我想从这个sentence
中提取名词 - 形容词对。所以,基本上我想要的东西:
(Mark,sincere) (John,sincere)
。
from nltk import word_tokenize, pos_tag, ne_chunk
sentence = "Mark and John are sincere employees at Google."
print ne_chunk(pos_tag(word_tokenize(sentence)))
答案 0 :(得分:7)
Spacy的POS tagging会比NLTK
更好。它越来越快。以下是您要做的事情的示例
import spacy
nlp = spacy.load('en')
doc = nlp(u'Mark and John are sincere employees at Google.')
noun_adj_pairs = []
for i,token in enumerate(doc):
if token.pos_ not in ('NOUN','PROPN'):
continue
for j in range(i+1,len(doc)):
if doc[j].pos_ == 'ADJ':
noun_adj_pairs.append((token,doc[j]))
break
noun_adj_pairs
<强>输出强>
[(Mark, sincere), (John, sincere)
]