Exemple #1
0
    def test_projection_2(self):
        ds3 = DepTree.fromstring(self.ds3str)

        # English sentence:
        #    1        2     3    4   5
        # "Tomorrow Mary  will meet Hans"
        #
        # Den   Hans  wird Maria morgen treffen
        #  1     2     3     4      5      6
        aln = Alignment([(1,5),(2,4),(3,3),(4,6),(5,2)])
        tgt_w = create_words_tier_from_string("Den Hans wird Maria morgen treffen")

        ds_proj = project_ds(ds3, tgt_w, aln)

        exp_proj = DepTree.fromstring("""
                                        (ROOT[0]
                                            (treffen[6]
                                                (Hans[2] (Den[1]))
                                                (wird[3])
                                                (Maria[4])
                                                (morgen[5])
                                        ))
                                                """,
                                      stype=DEPSTR_PTB)
        self.assertTrue(ds_proj.structurally_eq(exp_proj))
Exemple #2
0
    def test_read_proj_ds_tree(self):
        src_t = get_ds(self.inst2, trans(self.inst2))
        tgt_w = lang(self.inst2)
        aln   = get_trans_gloss_alignment(self.inst2)

        tgt_t = DepTree.fromstring("""
        (ROOT[0]
            (glaubst[2]
                (Was[1])
                (Du[3])
                (wer[4])
                (angerufen[5] (hat[6]))
            ))
        """, stype=DEPSTR_PTB)

        proj_t = project_ds(src_t, tgt_w, aln)

        self.assertTrue(proj_t.structurally_eq(tgt_t))
Exemple #3
0
    def test_projection_1(self):
        """
        Testcase for the DS projection in Fei/Will's paper.
        """
        ds1 = DepTree.fromstring(self.ds1str)
        ds2 = DepTree.fromstring(self.ds2str, stype=DEPSTR_PTB)

        # -----------------------------------------------------------------------------
        #    1       2      3        4    5        6      7
        # Rhoddod    yr   athro    lyfr  i'r     bachgen  ddoe
        # gave-3sg   the  teacher  book  to-the  boy      yesterday
        #
        # The     teacher  gave  a book   to the  boy      yesterday
        #  1         2     3     4  5     6  7    8           9


        tgt_w = create_words_tier_from_string("Rhoddodd yr athro lyfr i'r bachgen ddoe")

        aln = Alignment([(1,2),(2,3),(3,1),(5,4),(6,5),(7,5),(8,6),(9,7)])

        # And now, project...
        ds_proj = project_ds(ds1, tgt_w, aln)

        self.assertTrue(ds2.structurally_eq(ds_proj))