我有这个代码在一个句子中找到名词和动词.
# -*- coding: utf-8 -*-
from nltk.corpus import wordnet as wn
from nltk import pos_tag
import nltk
syno =[]
sentence = '''His father suggested he study to become a parson instead, but Darwin was far more inclined to study natural history.DarwinDar·win (där'w?n),Charles Robert.1809-1882.British naturalist who revolutionized the study of biology with his theory ofevolutionbased on natural selection
Like several scientists before him, Darwin believed all the life on earth evolved (developed gradually) over millions of years from a few …Run Code Online (Sandbox Code Playgroud) 我有一个使用 NLTK 查找名词和动词的代码。
from nltk.corpus import wordnet as wn
from nltk import pos_tag
import nltk
sentence = "Hello my name is Abhishek Mitra"
sentence = nltk.word_tokenize(sentence)
sent = pos_tag(sentence)
print sent
Run Code Online (Sandbox Code Playgroud)
它返回:
[('Hello', 'NNP'), ('my', 'PRP$'), ('name', 'NN'), ('is', 'VBZ'), ('Abhishek', 'NNP'), ('Mitra', 'NNP')]
Run Code Online (Sandbox Code Playgroud)
我怎样才能从列表中只删除“NN”单词。
这是我的计划的一部分.它给出了错误NameError: name 'urlss' is not defined
def testfunc():
urlss = "hey"
return urlss
print urlss
Run Code Online (Sandbox Code Playgroud)
为什么会这样?
我有一个变量
sentence = "In 1794, shortly after his arrival in Manchester, Dalton was elected a member of the Manchester Literary and Philosophical Society, the "Lit & Phil", and a few weeks later he communicated his first paper on "Extraordinary facts relating to the vision of colours", in which he postulated that shortage in colour perception was caused by discoloration of the liquid medium of the eyeball. In fact, a shortage of colour perception in some people had not even been …Run Code Online (Sandbox Code Playgroud)