代码之家  ›  专栏  ›  技术社区  ›  HJA24

空间否定与依赖分析

  •  0
  • HJA24  · 技术社区  · 7 年前

    情感词在否定的语义范围内表现出很大的不同。我想用一个稍微修改过的版本 Das and Chen (2001) 它们能检测出诸如 , ,和 然后在否定和从句级标点符号之间出现的每个单词后面加一个“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)
    

    可视化的依赖关系路径:

    enter image description here

    很好,在依赖标记方案中存在一个否定修饰符; NEG

    为了识别否定,我使用以下方法:

     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]
    

    ,所以 got 它正在定位?

    0 回复  |  直到 7 年前
        1
  •  7
  •   Sofie VL    7 年前

    您可以简单地定义和循环找到的否定标记的头标记:

    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 .