使用 spaCY 处理语法

processing grammar using spaCY

我要检查输入的句子中的语法。如果 spaCy 在一个句子中识别出 PRP and MD and NN 那么它会给我一个文本输出

there is a prp, md and nn in the sentence

问题是:我如何告诉 spaCy 检查 PRPMDNN 然后给我想要的文本输出?

到目前为止,这是能够识别文本输入语法的代码:

import spacy

sent=input("insert sentence: \n\n")
nlp=spacy.load('en')
doc=nlp(sent)
for token in doc:
    print(token.text, token.tag_, token.dep_)

如果我理解正确的话:

In [34]: chk_set = set(['PRP','MD','NN'])

In [35]: chk_set.issubset(t.tag_ for t in nlp("I will go to the mall"))
Out[35]: True

In [36]: chk_set.issubset(t.tag_ for t in nlp("I will go"))
Out[36]: False

更新:

how can I read the word marked as NN and print it out?

In [53]: [t.text for t in nlp("I will go to the mall") if t.tag_ in ['NN']]
Out[53]: ['mall']