情感词在否定的语义范围内表现出很大的不同。我想使用Das and Chen (2001)的稍作修改的版本 它们检测诸如no、not和never之类的单词,然后在否定和从句级标点符号之间的每个单词附加一个“neg”后缀。 我想用spaCy的依赖解析创建类似的东西。在
import spacy
from spacy import displacy
nlp = spacy.load('en')
doc = nlp(u'$AAPL is óóóóópen to ‘Talk’ about patents with GOOG definitely not the treatment #samsung got:-) heh')
options = {'compact': True, 'color': 'black', 'font': 'Arial'}
displacy.serve(doc, style='dep', options=options)
可视化依赖项路径:
很好,依赖标记方案中存在一个否定修饰符;NEG
为了识别否定,我使用以下方法:
^{pr2}$现在我要检索否定的范围。在
import spacy
from spacy import displacy
import pandas as pd
nlp = spacy.load("en_core_web_sm")
doc = nlp(u'AAPL is óóóóópen to Talk about patents with GOOG definitely not the treatment got')
print('DEPENDENCY RELATIONS')
print('Key: ')
print('TEXT, DEP, HEAD_TEXT, HEAD_POS, CHILDREN')
for token in doc:
print(token.text, token.dep_, token.head.text, token.head.pos_,
[child for child in token.children])
这将产生以下输出:
DEPENDENCY RELATIONS
Key:
TEXT, DEP, HEAD_TEXT, HEAD_POS, CHILDREN
AAPL nsubj is VERB []
is ROOT is VERB [AAPL, óóóóópen, got]
óóóóópen acomp is VERB [to]
to prep óóóóópen ADJ [Talk]
Talk pobj to ADP [about, definitely]
about prep Talk NOUN [patents]
patents pobj about ADP [with]
with prep patents NOUN [GOOG]
GOOG pobj with ADP []
definitely advmod Talk NOUN []
not neg got VERB []
the det treatment NOUN []
treatment nsubj got VERB [the]
got conj is VERB [not, treatment]
如何只过滤掉令牌.head.text不是,所以got
它在定位吗?
有人能帮我吗?在
您可以简单地定义并循环使用找到的否定标记的头标记:
它为您打印
got
的信息。在相关问题 更多 >
编程相关推荐