def test_basic_noun_verb(): ball = DependencyTreeToken("chyou2", NOUN) go = DependencyTreeToken("dzou3", VERB) tree = DiGraph() tree.add_edge(ball, go, role=NOMINAL_SUBJECT) predicted_token_order = tuple( node.token for node in SIMPLE_CHINESE_DEPENDENCY_TREE_LINEARIZER.linearize( DependencyTree(tree)).surface_token_order) assert predicted_token_order == ("chyou2", "dzou3")
def test_adj_noun(): truck = DependencyTreeToken("ka3 che1", NOUN) red = DependencyTreeToken("hung2 se4", ADJECTIVE) tree = DiGraph() tree.add_edge(red, truck, role=ADJECTIVAL_MODIFIER) predicted_token_order = tuple( node.token for node in SIMPLE_CHINESE_DEPENDENCY_TREE_LINEARIZER.linearize( DependencyTree(tree)).surface_token_order) assert predicted_token_order == ("hung2 se4", "ka3 che1")
def test_counting(): three = DependencyTreeToken("san1", NUMERAL) clf = DependencyTreeToken("jr1", PARTICLE) dog = DependencyTreeToken("gou3", NOUN) tree = DiGraph() tree.add_edge(clf, dog, role=CLASSIFIER) tree.add_edge(three, dog, role=NUMERIC_MODIFIER) predicted_token_order = tuple( node.token for node in SIMPLE_CHINESE_DEPENDENCY_TREE_LINEARIZER.linearize( DependencyTree(tree)).surface_token_order) assert predicted_token_order == ("san1", "jr1", "gou3")
def test_direct_object(): me = DependencyTreeToken("wo3", NOUN) drink = DependencyTreeToken("he1", VERB) juice = DependencyTreeToken("gwo3 jr1", NOUN) tree = DiGraph() tree.add_edge(me, drink, role=NOMINAL_SUBJECT) tree.add_edge(juice, drink, role=OBJECT) predicted_token_order = tuple( node.token for node in SIMPLE_CHINESE_DEPENDENCY_TREE_LINEARIZER.linearize( DependencyTree(tree)).surface_token_order) assert predicted_token_order == ("wo3", "he1", "gwo3 jr1")
def test_proper_noun_modified(): near = DependencyTreeToken("fu4, jin4", NOUN) at = DependencyTreeToken("dzai4", ADPOSITION) ma = DependencyTreeToken("ma1", PROPER_NOUN) tree = DiGraph() tree.add_edge(at, ma, role=CASE_SPATIAL) tree.add_edge(near, ma, role=NOMINAL_MODIFIER) predicted_token_order = tuple( node.token for node in SIMPLE_CHINESE_DEPENDENCY_TREE_LINEARIZER.linearize( DependencyTree(tree)).surface_token_order) assert predicted_token_order == ("dzai4", "ma1", "fu4, jin4")
def test_possessives(): me = DependencyTreeToken("wo3", NOUN) de = DependencyTreeToken("de", PARTICLE) truck = DependencyTreeToken("ka3 che1", NOUN) red = DependencyTreeToken("hung2 se4", ADJECTIVE) tree = DiGraph() tree.add_edge(de, me, role=CASE_POSSESSIVE) tree.add_edge(red, truck, role=ADJECTIVAL_MODIFIER) tree.add_edge(me, truck, role=NOMINAL_MODIFIER_POSSESSIVE) predicted_token_order = tuple( node.token for node in SIMPLE_CHINESE_DEPENDENCY_TREE_LINEARIZER.linearize( DependencyTree(tree)).surface_token_order) assert predicted_token_order == ("wo3", "de", "hung2 se4", "ka3 che1")
def test_indirect_object(): me = DependencyTreeToken("wo3", NOUN) give = DependencyTreeToken("gei3", VERB) you = DependencyTreeToken("ni3", NOUN) book = DependencyTreeToken("shu1", NOUN) tree = DiGraph() tree.add_edge(me, give, role=NOMINAL_SUBJECT) tree.add_edge(book, give, role=OBJECT) tree.add_edge(you, give, role=INDIRECT_OBJECT) predicted_token_order = tuple( node.token for node in SIMPLE_CHINESE_DEPENDENCY_TREE_LINEARIZER.linearize( DependencyTree(tree)).surface_token_order) assert predicted_token_order == ("wo3", "gei3", "ni3", "shu1")
def test_proper_noun_possessive(): ma = DependencyTreeToken("ma1", PROPER_NOUN) de = DependencyTreeToken("de", PARTICLE) dog = DependencyTreeToken("gou3", NOUN) black = DependencyTreeToken("hei1 se4", ADJECTIVE) tree = DiGraph() tree.add_edge(de, ma, role=CASE_POSSESSIVE) tree.add_edge(ma, dog, role=NOMINAL_MODIFIER_POSSESSIVE) tree.add_edge(black, dog, role=ADJECTIVAL_MODIFIER) predicted_token_order = tuple( node.token for node in SIMPLE_CHINESE_DEPENDENCY_TREE_LINEARIZER.linearize( DependencyTree(tree)).surface_token_order) assert predicted_token_order == ("ma1", "de", "hei1 se4", "gou3")
def test_long_localizer_phrase(): de = DependencyTreeToken("de", PARTICLE) truck = DependencyTreeToken("ka3 che1", NOUN) red = DependencyTreeToken("hung2 se4", ADJECTIVE) three = DependencyTreeToken("san1", NUMERAL) clf = DependencyTreeToken("lyang4", PARTICLE) near = DependencyTreeToken("fu4, jin4", NOUN) at = DependencyTreeToken("dzai4", ADPOSITION) ma = DependencyTreeToken("ma1ma1", PROPER_NOUN) tree = DiGraph() tree.add_edge(at, truck, role=CASE_SPATIAL) tree.add_edge(near, truck, role=NOMINAL_MODIFIER) tree.add_edge(clf, truck, role=CLASSIFIER) tree.add_edge(three, truck, role=NUMERIC_MODIFIER) tree.add_edge(de, ma, role=CASE_POSSESSIVE) tree.add_edge(red, truck, role=ADJECTIVAL_MODIFIER) tree.add_edge(ma, truck, role=NOMINAL_MODIFIER_POSSESSIVE) predicted_token_order = tuple( node.token for node in SIMPLE_CHINESE_DEPENDENCY_TREE_LINEARIZER.linearize( DependencyTree(tree)).surface_token_order) assert predicted_token_order == ( "dzai4", "ma1ma1", "de", "san1", "lyang4", "hung2 se4", "ka3 che1", "fu4, jin4", )
def test_adverb_mods(): me = DependencyTreeToken("wo3", NOUN) give = DependencyTreeToken("gei3", VERB) you = DependencyTreeToken("ni3", NOUN) book = DependencyTreeToken("shu1", NOUN) slowly = DependencyTreeToken("man4 man", ADVERB) tree = DiGraph() tree.add_edge(me, give, role=NOMINAL_SUBJECT) tree.add_edge(book, give, role=OBJECT) tree.add_edge(you, give, role=INDIRECT_OBJECT) tree.add_edge(slowly, give, role=ADVERBIAL_MODIFIER) predicted_token_order = tuple( node.token for node in SIMPLE_CHINESE_DEPENDENCY_TREE_LINEARIZER.linearize( DependencyTree(tree)).surface_token_order) assert predicted_token_order == ("wo3", "man4 man", "gei3", "ni3", "shu1")
def test_preverbial_prep(): me = DependencyTreeToken("wo3", NOUN) at = DependencyTreeToken("dzai4", ADPOSITION) table = DependencyTreeToken("jwo1 dz", NOUN) on = DependencyTreeToken("shang4", NOUN) eat = DependencyTreeToken("chr1", VERB) tree = DiGraph() tree.add_edge(at, table, role=CASE_SPATIAL) tree.add_edge(on, table, role=NOMINAL_MODIFIER) tree.add_edge(me, eat, role=NOMINAL_SUBJECT) tree.add_edge(table, eat, role=OBLIQUE_NOMINAL) predicted_token_order = tuple( node.token for node in SIMPLE_CHINESE_DEPENDENCY_TREE_LINEARIZER.linearize( DependencyTree(tree)).surface_token_order) assert predicted_token_order == ("wo3", "dzai4", "jwo1 dz", "shang4", "chr1")
def test_I_push_the_book_along_the_table(): me = DependencyTreeToken("wo3", NOUN) book = DependencyTreeToken("shu1", NOUN) ba = DependencyTreeToken("ba3", PARTICLE) push = DependencyTreeToken("twei1", VERB) at = DependencyTreeToken("dau4", ADPOSITION) table = DependencyTreeToken("jwo1 dz", NOUN) on = DependencyTreeToken("shang4", NOUN) tree = DiGraph() tree.add_edge(ba, book, role=CASE_SPATIAL) tree.add_edge(book, push, role=OBLIQUE_NOMINAL) tree.add_edge(me, push, role=NOMINAL_SUBJECT) tree.add_edge(at, table, role=CASE_SPATIAL) tree.add_edge(on, table, role=NOMINAL_MODIFIER) # TODO: this is a bit of a hack since I'm not sure this really counts as an IO, but I'm not sure what to classify it as tree.add_edge(table, push, role=ADVERBIAL_CLAUSE_MODIFIER) predicted_token_order = tuple( node.token for node in SIMPLE_CHINESE_DEPENDENCY_TREE_LINEARIZER.linearize( DependencyTree(tree)).surface_token_order) assert predicted_token_order == ( "wo3", "ba3", "shu1", "twei1", "dau4", "jwo1 dz", "shang4", )
def test_basic_noun(): truck = DependencyTreeToken("ka3 che1", NOUN) tree = DiGraph() tree.add_node(truck) predicted_token_order = tuple( node.token for node in SIMPLE_CHINESE_DEPENDENCY_TREE_LINEARIZER.linearize( DependencyTree(tree)).surface_token_order) assert predicted_token_order == ("ka3 che1", )
def test_mom_put_the_ball_on_the_table(): mom = DependencyTreeToken("Mom", NOUN) put = DependencyTreeToken("put", VERB) the_0 = DependencyTreeToken("the", DETERMINER) ball = DependencyTreeToken("ball", NOUN) on = DependencyTreeToken("on", ADPOSITION) the_1 = DependencyTreeToken("the", DETERMINER) table = DependencyTreeToken("table", NOUN) tree = DiGraph() tree.add_edge(mom, put, role=NOMINAL_SUBJECT) tree.add_edge(the_0, ball, role=DETERMINER_ROLE) tree.add_edge(ball, put, role=OBJECT) tree.add_edge(on, table, role=CASE_SPATIAL) tree.add_edge(the_1, table, role=DETERMINER_ROLE) tree.add_edge(table, put, role=OBLIQUE_NOMINAL) predicted_token_order = tuple( node.token for node in SIMPLE_ENGLISH_DEPENDENCY_TREE_LINEARIZER.linearize( DependencyTree(tree)).surface_token_order) assert predicted_token_order == ("Mom", "put", "the", "ball", "on", "the", "table")