Exemplo n.º 1
0
    def test_roots_share_suffix(self):
        graphs = Pair(AlpinoGraph(), AlpinoGraph())
        graphs.source.add_node(1, "x")
        graphs.target.add_node(2, "y")
        nodes = Pair(1, 2)

        # no roots
        self.assertEqual(ff_roots_share_suffix(nodes, graphs), "-")

        graphs.source.node[1]["root"] = "woon_wagen"
        graphs.target.node[2]["root"] = "eet_tafel"
        self.assertEqual(ff_roots_share_suffix(nodes, graphs), "F")

        graphs.source.node[1]["root"] = "woon_wagen"
        graphs.target.node[2]["root"] = "woon_wagen"
        self.assertEqual(ff_roots_share_suffix(nodes, graphs), "F")

        graphs.source.node[1]["root"] = "woon_wagen"
        graphs.target.node[2]["root"] = "wagen"
        self.assertEqual(ff_roots_share_suffix(nodes, graphs), "F")

        graphs.source.node[1]["root"] = "woon_wagen_bewoner"
        graphs.target.node[2]["root"] = "wagen_bewoner"
        self.assertEqual(ff_roots_share_suffix(nodes, graphs), "F")

        graphs.source.node[1]["root"] = "woon_wagen"
        graphs.target.node[2]["root"] = "mest_wagen"
        self.assertEqual(ff_roots_share_suffix(nodes, graphs), "T")

        graphs.source.node[1]["root"] = "woon_wagen_trekker"
        graphs.target.node[2]["root"] = "mest_wagen_trekker"
        self.assertEqual(ff_roots_share_suffix(nodes, graphs), "T")
Exemplo n.º 2
0
    def test_roots_subsumption(self):
        graphs = Pair(AlpinoGraph(), AlpinoGraph())
        graphs.source.add_node(1, "x")
        graphs.target.add_node(2, "y")
        nodes = Pair(1, 2)

        # no roots
        self.assertEqual(ff_roots_subsumption(nodes, graphs), "-")

        graphs.source.node[1]["root"] = "wagen"
        graphs.target.node[2]["root"] = "wagen"
        self.assertEqual(ff_roots_subsumption(nodes, graphs), "equals")

        graphs.source.node[1]["root"] = "brandweer_wagen"
        graphs.target.node[2]["root"] = "brandweer"
        self.assertEqual(ff_roots_subsumption(nodes, graphs), "has_prefix")

        graphs.source.node[1]["root"] = "brandweer"
        graphs.target.node[2]["root"] = "brandweer_wagen"
        self.assertEqual(ff_roots_subsumption(nodes, graphs), "is_prefix")

        graphs.source.node[1]["root"] = "brandweer_wagen"
        graphs.target.node[2]["root"] = "wagen"
        self.assertEqual(ff_roots_subsumption(nodes, graphs), "has_suffix")

        graphs.source.node[1]["root"] = "wagen"
        graphs.target.node[2]["root"] = "brandweer_wagen"
        self.assertEqual(ff_roots_subsumption(nodes, graphs), "is_suffix")

        graphs.source.node[1]["root"] = "woon_wagen_bewoners_kamp_ingang"
        graphs.target.node[2]["root"] = "wagen_bewoners"
        self.assertEqual(ff_roots_subsumption(nodes, graphs), "has_infix")

        graphs.source.node[1]["root"] = "wagen_bewoners"
        graphs.target.node[2]["root"] = "woon_wagen_bewoners_kamp_ingang"
        self.assertEqual(ff_roots_subsumption(nodes, graphs), "is_infix")

        # no subsumption
        graphs.source.node[1]["root"] = "brandweer_wagen"
        graphs.target.node[2]["root"] = "kamp_ingang"
        self.assertEqual(ff_roots_subsumption(nodes, graphs), "none")
Exemplo n.º 3
0
    def setUp(self):
        self.ag = AlpinoGraph(root="0")

        self.ag.add_node("0", "top", cat="top",
                         tokens="Ik wilde weten of hij echt begrip had .".split())
        self.ag.add_node("1", "smain", cat="smain",
                         tokens="Ik wilde weten of hij echt begrip had".split())
        self.ag.add_node("2", "pron", pos="pron", root="ik", index="1",
                         tokens="Ik".split())
        self.ag.add_node("3", "verb", pos="verb", root="willen",
                         tokens="wilde".split())	
        self.ag.add_node("4", "inf", cat="inf",
                         tokens="weten of hij echt begrip had".split())	
        self.ag.add_node("5", "index", index="1")	
        self.ag.add_node("6", "verb", pos="verb", root="weten",
                         tokens="weten".split())	
        self.ag.add_node("7", "cp", cat="cp",
                         tokens="of hij echt begrip had".split())	
        self.ag.add_node("8", "comp", pos="comp", root="of",
                         tokens="of".split())	
        self.ag.add_node("9", "ssub", cat="ssub",
                         tokens="hij echt begrip had".split())	
        self.ag.add_node("10", "pron", pos="pron", root="hij",
                         tokens="hij".split())	
        self.ag.add_node("11", "np", cat="np",
                         tokens="echt begrip".split())	
        self.ag.add_node("12", "adj", pos="adj", root="echt",
                         tokens="echt".split())	
        self.ag.add_node("13", "noun", pos="noun", root="begrip",
                         tokens="begrip".split())	
        self.ag.add_node("14", "verb", pos="verb", root="hebben",
                         tokens="had".split())	
        self.ag.add_node("15", "punt", pos="punct", root=".",
                         tokens=".".split())
        
        self.ag.add_edge("0", "1", "--")
        self.ag.add_edge("1", "2", "su")
        self.ag.add_edge("1", "3", "hd")
        self.ag.add_edge("1", "4", "vc")
        self.ag.add_edge("4", "5", "su")
        self.ag.add_edge("4", "6", "hd")
        self.ag.add_edge("4", "7", "vc")
        self.ag.add_edge("7", "8", "cmp")
        self.ag.add_edge("7", "9", "body")
        self.ag.add_edge("9", "10", "su")
        self.ag.add_edge("9", "11", "obj1")
        self.ag.add_edge("11", "12", "mod")
        self.ag.add_edge("11", "13", "hd")
        self.ag.add_edge("9", "14", "hd")
        self.ag.add_edge("0", "15", "punct")
Exemplo n.º 4
0
    def _start_graph(self, attrs):
        # to enable parsing graphs without id attribute,
        # id defaults to graph number
        id = attrs.get("id", self._n)
        self._n += 1

        if not self._sparse or id in self._id2graph:
            self._graph = self._id2graph[id] = AlpinoGraph(id=id)

            # stack that records ancestor nodes,
            # because we need a node's parent to add a new edge
            self._ancestors = []

            # list of tokens in the order that they are encountered in the tree
            # (which is often different from the order in the sentence)
            self._tokens = []

            # tracks the current position in self._tokens
            self._index = 0

            # stack which records self._index upon entering a non-terminal node,
            # which is required to calculate the tokens belonging to non-terminal
            # when exiting a non-terminal
            self._index_stack = []
Exemplo n.º 5
0
class Test_AlpinoGraph(unittest.TestCase):
    def setUp(self):
        self.ag = AlpinoGraph(root="0")

        self.ag.add_node(
            "0",
            "top",
            cat="top",
            tokens="Ik wilde weten of hij echt begrip had .".split())
        self.ag.add_node(
            "1",
            "smain",
            cat="smain",
            tokens="Ik wilde weten of hij echt begrip had".split())
        self.ag.add_node("2",
                         "pron",
                         pos="pron",
                         root="ik",
                         index="1",
                         tokens="Ik".split())
        self.ag.add_node("3",
                         "verb",
                         pos="verb",
                         root="willen",
                         tokens="wilde".split())
        self.ag.add_node("4",
                         "inf",
                         cat="inf",
                         tokens="weten of hij echt begrip had".split())
        self.ag.add_node("5", "index", index="1")
        self.ag.add_node("6",
                         "verb",
                         pos="verb",
                         root="weten",
                         tokens="weten".split())
        self.ag.add_node("7",
                         "cp",
                         cat="cp",
                         tokens="of hij echt begrip had".split())
        self.ag.add_node("8",
                         "comp",
                         pos="comp",
                         root="of",
                         tokens="of".split())
        self.ag.add_node("9",
                         "ssub",
                         cat="ssub",
                         tokens="hij echt begrip had".split())
        self.ag.add_node("10",
                         "pron",
                         pos="pron",
                         root="hij",
                         tokens="hij".split())
        self.ag.add_node("11", "np", cat="np", tokens="echt begrip".split())
        self.ag.add_node("12",
                         "adj",
                         pos="adj",
                         root="echt",
                         tokens="echt".split())
        self.ag.add_node("13",
                         "noun",
                         pos="noun",
                         root="begrip",
                         tokens="begrip".split())
        self.ag.add_node("14",
                         "verb",
                         pos="verb",
                         root="hebben",
                         tokens="had".split())
        self.ag.add_node("15",
                         "punt",
                         pos="punct",
                         root=".",
                         tokens=".".split())

        self.ag.add_edge("0", "1", "--")
        self.ag.add_edge("1", "2", "su")
        self.ag.add_edge("1", "3", "hd")
        self.ag.add_edge("1", "4", "vc")
        self.ag.add_edge("4", "5", "su")
        self.ag.add_edge("4", "6", "hd")
        self.ag.add_edge("4", "7", "vc")
        self.ag.add_edge("7", "8", "cmp")
        self.ag.add_edge("7", "9", "body")
        self.ag.add_edge("9", "10", "su")
        self.ag.add_edge("9", "11", "obj1")
        self.ag.add_edge("11", "12", "mod")
        self.ag.add_edge("11", "13", "hd")
        self.ag.add_edge("9", "14", "hd")
        self.ag.add_edge("0", "15", "punct")

    def test_print_subtree(self):
        print "\n", self.ag

    def test_node_is_nominal(self):
        self.assertTrue(self.ag.node_is_nominal("13"))
        self.assertFalse(self.ag.node_is_nominal("3"))

    def test_node_is_punct(self):
        self.assertTrue(self.ag.node_is_punct("15"))
        self.assertFalse(self.ag.node_is_punct("14"))

    def test_node_is_index(self):
        self.assertTrue(self.ag.node_is_index("5"))
        self.assertFalse(self.ag.node_is_index("1"))
        self.assertFalse(self.ag.node_is_index("2"))

    def test_get_root_node(self):
        self.assertEqual(self.ag.root, "0")

    def test_get_parent_node(self):
        self.assertEqual(self.ag.get_parent_node("0"), None)
        self.assertEqual(self.ag.get_parent_node("1"), "0")

    def test_get_node_deprel(self):
        self.assertEqual(self.ag.get_node_deprel("0"), None)
        self.assertEqual(self.ag.get_node_deprel("15"), "punct")

    def test_node_is_complement(self):
        self.assertTrue(self.ag.node_is_complement("11"))
        self.assertFalse(self.ag.node_is_complement("12"))
Exemplo n.º 6
0
    def setUp(self):
        self.ag = AlpinoGraph(root="0")

        self.ag.add_node(
            "0",
            "top",
            cat="top",
            tokens="Ik wilde weten of hij echt begrip had .".split())
        self.ag.add_node(
            "1",
            "smain",
            cat="smain",
            tokens="Ik wilde weten of hij echt begrip had".split())
        self.ag.add_node("2",
                         "pron",
                         pos="pron",
                         root="ik",
                         index="1",
                         tokens="Ik".split())
        self.ag.add_node("3",
                         "verb",
                         pos="verb",
                         root="willen",
                         tokens="wilde".split())
        self.ag.add_node("4",
                         "inf",
                         cat="inf",
                         tokens="weten of hij echt begrip had".split())
        self.ag.add_node("5", "index", index="1")
        self.ag.add_node("6",
                         "verb",
                         pos="verb",
                         root="weten",
                         tokens="weten".split())
        self.ag.add_node("7",
                         "cp",
                         cat="cp",
                         tokens="of hij echt begrip had".split())
        self.ag.add_node("8",
                         "comp",
                         pos="comp",
                         root="of",
                         tokens="of".split())
        self.ag.add_node("9",
                         "ssub",
                         cat="ssub",
                         tokens="hij echt begrip had".split())
        self.ag.add_node("10",
                         "pron",
                         pos="pron",
                         root="hij",
                         tokens="hij".split())
        self.ag.add_node("11", "np", cat="np", tokens="echt begrip".split())
        self.ag.add_node("12",
                         "adj",
                         pos="adj",
                         root="echt",
                         tokens="echt".split())
        self.ag.add_node("13",
                         "noun",
                         pos="noun",
                         root="begrip",
                         tokens="begrip".split())
        self.ag.add_node("14",
                         "verb",
                         pos="verb",
                         root="hebben",
                         tokens="had".split())
        self.ag.add_node("15",
                         "punt",
                         pos="punct",
                         root=".",
                         tokens=".".split())

        self.ag.add_edge("0", "1", "--")
        self.ag.add_edge("1", "2", "su")
        self.ag.add_edge("1", "3", "hd")
        self.ag.add_edge("1", "4", "vc")
        self.ag.add_edge("4", "5", "su")
        self.ag.add_edge("4", "6", "hd")
        self.ag.add_edge("4", "7", "vc")
        self.ag.add_edge("7", "8", "cmp")
        self.ag.add_edge("7", "9", "body")
        self.ag.add_edge("9", "10", "su")
        self.ag.add_edge("9", "11", "obj1")
        self.ag.add_edge("11", "12", "mod")
        self.ag.add_edge("11", "13", "hd")
        self.ag.add_edge("9", "14", "hd")
        self.ag.add_edge("0", "15", "punct")
Exemplo n.º 7
0
class Test_AlpinoGraph(unittest.TestCase):

    def setUp(self):
        self.ag = AlpinoGraph(root="0")

        self.ag.add_node("0", "top", cat="top",
                         tokens="Ik wilde weten of hij echt begrip had .".split())
        self.ag.add_node("1", "smain", cat="smain",
                         tokens="Ik wilde weten of hij echt begrip had".split())
        self.ag.add_node("2", "pron", pos="pron", root="ik", index="1",
                         tokens="Ik".split())
        self.ag.add_node("3", "verb", pos="verb", root="willen",
                         tokens="wilde".split())	
        self.ag.add_node("4", "inf", cat="inf",
                         tokens="weten of hij echt begrip had".split())	
        self.ag.add_node("5", "index", index="1")	
        self.ag.add_node("6", "verb", pos="verb", root="weten",
                         tokens="weten".split())	
        self.ag.add_node("7", "cp", cat="cp",
                         tokens="of hij echt begrip had".split())	
        self.ag.add_node("8", "comp", pos="comp", root="of",
                         tokens="of".split())	
        self.ag.add_node("9", "ssub", cat="ssub",
                         tokens="hij echt begrip had".split())	
        self.ag.add_node("10", "pron", pos="pron", root="hij",
                         tokens="hij".split())	
        self.ag.add_node("11", "np", cat="np",
                         tokens="echt begrip".split())	
        self.ag.add_node("12", "adj", pos="adj", root="echt",
                         tokens="echt".split())	
        self.ag.add_node("13", "noun", pos="noun", root="begrip",
                         tokens="begrip".split())	
        self.ag.add_node("14", "verb", pos="verb", root="hebben",
                         tokens="had".split())	
        self.ag.add_node("15", "punt", pos="punct", root=".",
                         tokens=".".split())
        
        self.ag.add_edge("0", "1", "--")
        self.ag.add_edge("1", "2", "su")
        self.ag.add_edge("1", "3", "hd")
        self.ag.add_edge("1", "4", "vc")
        self.ag.add_edge("4", "5", "su")
        self.ag.add_edge("4", "6", "hd")
        self.ag.add_edge("4", "7", "vc")
        self.ag.add_edge("7", "8", "cmp")
        self.ag.add_edge("7", "9", "body")
        self.ag.add_edge("9", "10", "su")
        self.ag.add_edge("9", "11", "obj1")
        self.ag.add_edge("11", "12", "mod")
        self.ag.add_edge("11", "13", "hd")
        self.ag.add_edge("9", "14", "hd")
        self.ag.add_edge("0", "15", "punct")

        
    def test_print_subtree(self):
        print "\n", self.ag
        
        
    def test_node_is_nominal(self):
        self.assertTrue(self.ag.node_is_nominal("13"))
        self.assertFalse(self.ag.node_is_nominal("3"))
        
    
    def test_node_is_punct(self):
        self.assertTrue(self.ag.node_is_punct("15"))
        self.assertFalse(self.ag.node_is_punct("14"))
        
        
    def test_node_is_index(self):
        self.assertTrue(self.ag.node_is_index("5"))
        self.assertFalse(self.ag.node_is_index("1"))
        self.assertFalse(self.ag.node_is_index("2"))
        
        
    def test_get_root_node(self):
        self.assertEqual(self.ag.root, "0")
        
        
    def test_get_parent_node(self):
        self.assertEqual(self.ag.get_parent_node("0"), None)
        self.assertEqual(self.ag.get_parent_node("1"), "0")
        
        
    def test_get_node_deprel(self):
        self.assertEqual(self.ag.get_node_deprel("0"), None)
        self.assertEqual(self.ag.get_node_deprel("15"), "punct")
        
        
    def test_node_is_complement(self):
        self.assertTrue(self.ag.node_is_complement("11"))
        self.assertFalse(self.ag.node_is_complement("12"))