Nlp 测试令牌是否是spaCy中的连接头 问题:

Nlp 测试令牌是否是spaCy中的连接头 问题:,nlp,spacy,dependency-parsing,Nlp,Spacy,Dependency Parsing,有没有办法检测一个标记是否是spaCy中的连接头 问题描述 我想要下面这句话: “美国人、穆斯林朋友和公民、纳税公民以及其他国家的穆斯林都感到震惊,无法相信我们在电视屏幕上看到的一切。” …返回以下自定义块: custom_chunks = [ Americans, Muslim friends, citizens, # `poss` modifier Muslim to be added as a hidden element tax-pay

有没有办法检测一个标记是否是spaCy中的连接头

问题描述 我想要下面这句话:

“美国人、穆斯林朋友和公民、纳税公民以及其他国家的穆斯林都感到震惊,无法相信我们在电视屏幕上看到的一切。”

…返回以下
自定义块

custom_chunks = [
    Americans,
    Muslim friends, 
    citizens,          # `poss` modifier Muslim to be added as a hidden element
    tax-paying citizens, 
    Muslims in nations, 
    what, 
    what, 
    we, 
    TV screens]
这句话的主连词中包含一个子连词,这使得任务更加复杂:

# main conjunction
"Americans" : Conjuncts(friends, citizens, Muslims, citizens)
"Americans" : Children(Both, and, friends, ,, citizens, ,, and, Muslims)

# sub-conjunction
"Friends : Conjuncts(Americans, citizens, Muslims, citizens)
"Friends" : Children(Muslim, and, citizens) # `children` attribute correctly identifies the sub-conjunction tokens
目前,我正在使用以下代码生成所需的答案:

# if the word has conjuncts but does not have a `conj` dependency it is the head of the main conjunction.
if word.conjuncts and word.dep != conj:
        # prev_end is the current word index
    prev_end = word.i         
    yield word.left_edge.i, word.i + 1, cc_label    
            
# if the word has a `conj` dependency and its subtree contains `conj` dependencies, it is the head of a sub-conjunction to a main conjunction
elif word.dep == conj and list(word.rights) and conj in [t.dep for t in word.rights]:
    # prev_end is the current word index
    prev_end = word.i            
    yield word.left_edge.i, word.i + 1, cc_label
    
# for when the word is not part of a conjunction    
elif word.dep in np_deps: # `conj` added to np_deps for other tokens of a conjunction
    # prev_end marks the right edge of the token subtree
    prev_end = word.right_edge.i                     
    yield word.left_edge.i, word.right_edge.i + 1, cc_label
识别连词和子连词头的
if
elif
语句感觉有点粗糙,是否有更肯定的方法来识别标记是否为连词头,或者是否可以请求这样的属性