예제 #1
0
    def _post_proc(self, phrase_tree):
        """
        句生成完了後の処理.
        - 最後の3語を保持
        - 生成した句の読みを保持
        - 生成した句をリストとして保持

        - 生成した句を保持

        Args:
          最後の PhraseTree インスタンス
        Returns:
          Phrase インスタンス
        """
        assert phrase_tree is not None
        assert not PhraseTree.is_root(phrase_tree), "phrase_tree is not root"
        Phrase.text_list = PhraseTree.get_text_list(phrase_tree)
        Phrase.last_words = PhraseTree.get_last_words(phrase_tree)
        Phrase.last_vowel = PhraseTree.get_text_vowel(phrase_tree)
예제 #2
0
    def test_get_last_words(self):
        WordsData(self.WORDS)
        word_tuple = (
            Words(
                {
                    "word": "古池",
                    "vowel": "ウウイエ",
                    "length": 4,
                    "part": "名詞"
                }
            ),
            Words(
                {
                    "word": "蛙",
                    "vowel": "アエウ",
                    "length": 3,
                    "part": "名詞"
                }
            ),
            Words(
                {
                    "word": "あ",
                    "vowel": "ア",
                    "length": 1,
                    "part": "名詞"
                }
            )
        )
        pt = PhraseTree(word_tuple)

        next_word_tuple = (
            Words(
                {
                    "word": "蛙",
                    "vowel": "アエウ",
                    "length": 3,
                    "part": "名詞"
                }
            ),
            Words(
                {
                    "word": "あ",
                    "vowel": "ア",
                    "length": 1,
                    "part": "名詞"
                }
            ),
            Words(
                {
                    "word": "い",
                    "vowel": "イ",
                    "length": 1,
                    "part": "名詞"
                }
            )
        )
        next_pt = PhraseTree(next_word_tuple, parent=pt)
        pt.next_tree = next_pt

        self.assertEqual(
            PhraseTree.get_last_words(pt),
            next_word_tuple
        )