Nlp 用spacy查找名词组的词根位置

Nlp 用spacy查找名词组的词根位置,nlp,root,spacy,chunks,lemmatization,Nlp,Root,Spacy,Chunks,Lemmatization,使用spacy时,您可以轻松地在文本的名词短语之间循环,如下所示: S='This is an example sentence that should include several parts and also make clear that studying Natural language Processing is not difficult' nlp = spacy.load('en_core_web_sm') doc = nlp(S) [chunk.text for chunk

使用spacy时,您可以轻松地在文本的名词短语之间循环,如下所示:

S='This is an example sentence that should include several parts and also make clear that studying Natural language Processing is not difficult'
nlp = spacy.load('en_core_web_sm')
doc = nlp(S)

[chunk.text for chunk in doc.noun_chunks]
# = ['an example sentence', 'several parts', 'Natural language Processing']
您还可以获取名词块的“根”:

[chunk.root.text for chunk in doc.noun_chunks]
# = ['sentence', 'parts', 'Processing']
我如何获得这些单词的词性(即使看起来一个名词短语的词根总是一个名词),以及如何获得该特定单词的引理、形状和单数单词

这可能吗


thx.

每个
块。root
是一个可以获得不同属性的函数,包括
引理和
位置(或者
标记
,如果您更喜欢Penntrekbak位置标记)


顺便说一句。。。在这个句子中,“processing”是一个名词,所以它的引理是“processing”,而不是动词“processing”的引理“process”。

omg,每个chunk.root都是一个标记,它就在我眼前。谢谢
import spacy
S='This is an example sentence that should include several parts and also make ' \
  'clear that studying Natural language Processing is not difficult'
nlp = spacy.load('en_core_web_sm')
doc = nlp(S)
for chunk in doc.noun_chunks:
    print('%-12s %-6s  %s' % (chunk.root.text, chunk.root.pos_, chunk.root.lemma_))

sentence     NOUN    sentence
parts        NOUN    part
Processing   NOUN    processing