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
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
def test_at_location_not_found(tested): assert tested.at(Location(10, 10)) == []
def test_at_location_multiple(tested): assert tested.at(Location(9, 13)) == [ GenericLabel(9, 13, document=document, i=6), GenericLabel(9, 13, document=document, i=7), ]
def test_at_location(tested): assert tested.at(Location(2, 6))[0] == GenericLabel(2, 6, document=document, i=2)
def test_label_location(): l = GenericLabel(0, 10) assert l.location == Location(0, 10)
def test_location_equals(): assert Location(1, 3) == Location(1, 3)
def test_location_offset_by(): first = Location(0, 5) assert first.offset_by(10) == Location(10, 15) assert first.offset_by(Location(10, 25)) == Location(10, 15) assert first.offset_by(GenericLabel(10, 25)) == Location(10, 15)
def test_location_relative_to(): first = Location(10, 20) assert first.relative_to(5) == Location(5, 15) assert first.relative_to(GenericLabel(5, 25)) == Location(5, 15) assert first.relative_to(Location(5, 25)) == Location(5, 15)