Python 空间否定与依赖解析
在否定的语义范围内,情感词的表现非常不同。我想使用稍微修改过的版本 它们检测到诸如no、not和never之类的单词,然后在否定和子句级标点符号之间出现的每个单词后面加上一个“neg”后缀。 我想从spaCy创建类似的依赖项解析Python 空间否定与依赖解析,python,spacy,Python,Spacy,在否定的语义范围内,情感词的表现非常不同。我想使用稍微修改过的版本 它们检测到诸如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 definit
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)
可视化的依赖路径:
很好,依赖项标记方案中存在一个否定修饰符<代码>负
为了识别否定,我使用以下方法:
negation = [tok for tok in doc if tok.dep_ == 'neg']
现在我想检索否定的范围
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]
如何仅过滤not的token.head.text,以便get
及其定位?
有人能帮我吗 您可以简单地定义和循环找到的否定标记的头部标记:
negation_tokens = [tok for tok in doc if tok.dep_ == 'neg']
negation_head_tokens = [token.head for token in negation_tokens]
for token in negation_head_tokens:
print(token.text, token.dep_, token.head.text, token.head.pos_, [child for child in token.children])
它为您打印
got
的信息 什么是nlp
constructor`??python-mspacy下载en