Пример #1
0
def first_level(gov: GenericLabel, negation_location: Location,
                upos_tags: 'LabelIndex[GenericLabel]'):
    if negation_location.covers(gov):
        return True
    if check_conj_or(gov, negation_location, upos_tags):
        return True
    for child in gov.dependents:
        if negation_location.covers(child):
            return True
        if check_suggest(child, negation_location, upos_tags):
            return True
        if check_nmod(child, negation_location, upos_tags):
            return True
        if check_cc_and(child, upos_tags):
            continue
        for second_child in child.dependents:
            if check_cc_and(second_child, upos_tags):
                continue
            if negation_location.covers(second_child):
                return True
            if check_nmod(child, negation_location, upos_tags):
                return True
            if check_suggest(second_child, negation_location, upos_tags):
                return True
    return False
Пример #2
0
def check_conj_or(dep: GenericLabel, negation_location: Location, upos_tags):
    if dep.deprel == 'conj':
        gov = dep.head
        conjs = [child for child in gov.dependents if child.deprel == 'conj']
        conjs.sort(key=lambda x: x.location)
        loc = conjs.index(dep)
        has_or = False
        for child in conjs[-1].dependents:
            if child.deprel == 'cc' and child.text.lower() == 'or':
                has_or = True
        if has_or and loc >= len(conjs) - 4:
            for child in conjs[loc:]:
                if negation_location.covers(child):
                    return True
        return False