diff --git a/tests/test_parse_navigate.py b/tests/test_parse_navigate.py index 1bbfdafc2..30e257204 100644 --- a/tests/test_parse_navigate.py +++ b/tests/test_parse_navigate.py @@ -26,3 +26,36 @@ def test_consistency(nlp, sun_text): assert child.head is head for child in head.rights: assert child.head is head + + +def test_child_consistency(nlp, sun_text): + tokens = nlp(sun_text) + + lefts = {} + rights = {} + for head in tokens: + assert head.i not in lefts + lefts[head.i] = set() + for left in head.lefts: + lefts[head.i].add(left.i) + assert head.i not in rights + rights[head.i] = set() + for right in head.rights: + rights[head.i].add(right.i) + for head in tokens: + assert head.n_rights == len(rights[head.i]) + assert head.n_lefts == len(lefts[head.i]) + for child in tokens: + if child.i < child.head.i: + assert child.i in lefts[child.head.i] + assert child.i not in rights[child.head.i] + lefts[child.head.i].remove(child.i) + elif child.i > child.head.i: + assert child.i in rights[child.head.i] + assert child.i not in lefts[child.head.i] + rights[child.head.i].remove(child.i) + for head_index, children in lefts.items(): + assert not children + for head_index, children in rights.items(): + assert not children +