本文介绍了提取特定名词短语的空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在python中使用spacy来查找具有特定邻居的NP吗?我想要文本中带有动词的名词短语.

Can I use spacy in python to find NP with specific neighbors? I want Noun phrases from my text that has verb before and after it.

推荐答案

  1. 您可以合并名词短语(以使它们不会被单独地标记化).
  2. 分析依赖性分析树,并查看相邻令牌的POS.

  1. You can merge the noun phrases ( so that they do not get tokenized seperately).
  2. Analyse the dependency parse tree, and see the POS of neighbouring tokens.

>>> import spacy
>>> nlp = spacy.load('en')
>>> sent = u'run python program run, to make this work'
>>> parsed = nlp(sent)
>>> list(parsed.noun_chunks)
[python program]
>>> for noun_phrase in list(parsed.noun_chunks):
...     noun_phrase.merge(noun_phrase.root.tag_, noun_phrase.root.lemma_, noun_phrase.root.ent_type_)
... 
python program
>>> [(token.text,token.pos_) for token in parsed]
[(u'run', u'VERB'), (u'python program', u'NOUN'), (u'run', u'VERB'), (u',', u'PUNCT'), (u'to', u'PART'), (u'make', u'VERB'), (u'this', u'DET'), (u'work', u'NOUN')]

  • 通过分析相邻标记的POS,您可以获得所需的名词短语.

  • By analysing the POS of adjacent tokens, you can get your desired noun phrases.

    这篇关于提取特定名词短语的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

  • 10-18 15:19