示例#1
0
    def test_static_to_str(self, msg: str = 'Word.to_str(words)') -> None:
        words = [
            Word(surface='歩下', yomi='ホゲ'),
            Word(surface='普が', yomi='フガ'),
            Word(surface='日余', yomi='ピヨ'),
        ]

        self.assertEqual(Word.to_str(words), '歩下/ホゲ 普が/フガ 日余/ピヨ')
示例#2
0
    def test_from_str_of_singleword(self,
                                    msg: str = 'Word#from_str_of_singleword'
                                    ) -> None:

        with self.subTest(msg='<unk>'):
            a = Word.from_str_of_singleword('<unk>')
            b = Word(surface='<unk>', yomi='<unk>')
            self.assertNotEqual(a, b)

            b = TagWord('<unk>')
            self.assertEqual(a, b)

        with self.subTest(msg='general case'):
            a = Word.from_str_of_singleword('歩下/ホゲ')
            b = Word(surface='歩下', yomi='ホゲ')
            self.assertEqual(a, b)
示例#3
0
    def setUp(self) -> None:
        self.lm = self.__class__.LM

        self.hoge_word = Word(surface='特に', yomi='トクニ')
        self.root = RootNode()
        self.node = Node(self.hoge_word, [self.root], self.lm)
        self.eos = EOSNode([self.node], self.lm)
示例#4
0
    def test_http_estimate(self) -> None:
        resp = self.simulate_post('/').json
        self.assertIn('eid', resp.keys())
        eid = resp['eid']

        sentence = '特に1Fのバーは最高'
        test_words = list(Word.from_sentence(sentence, MeCab()))
        key = Key.from_words(test_words)

        for k in key:
            params = {'key': str(k)}
            result = self.simulate_post(f'/{eid}', params=params)
            self.assertLess(result.status_code, 400)

        get_result = self.simulate_get(f'/{eid}')
        self.assertLess(get_result.status_code, 400)

        correct = Word.to_str(test_words)
        self.assertEqual(correct, get_result.json['result'])
示例#5
0
    def setUp(self) -> None:
        self.hoge = Word(surface='歩下', yomi='ホゲ')
        self.fuga = Word(surface='不臥', yomi='フガ')

        self.key = Key([0, 1, 2, 3])
示例#6
0
 def test_score(self, msg: str = 'lm.scoreが何らかの値を返すか\'だけの\'テスト') -> None:
     words = [Word(surface='ホテル', yomi='ホテル')]
     self.lm.score(words)
示例#7
0
    def test_from_sentence(self) -> None:
        r1 = list(
            Word.from_sentence('ホテル内の飲食店が充実しており、特に1Fのバーは重厚なインテリアで、雰囲気が良く最高',
                               MeCab()))

        r2 = [
            Word('ホテル', 'ホテル'),
            Word('内', 'ナイ'),
            Word('の', 'ノ'),
            Word('飲食', 'インショク'),
            Word('店', 'テン'),
            Word('が', 'ガ'),
            Word('充実', 'ジュウジツ'),
            Word('し', 'シ'),
            Word('て', 'テ'),
            Word('おり', 'オリ'),
            Word('特に', 'トクニ'),
            TagWord('<num>'),
            TagWord('<eng>'),
            Word('の', 'ノ'),
            Word('バー', 'バー'),
            Word('は', 'ハ'),
            Word('重厚', 'ジュウコウ'),
            Word('な', 'ナ'),
            Word('インテリア', 'インテリア'),
            Word('で', 'デ'),
            Word('雰囲気', 'フンイキ'),
            Word('が', 'ガ'),
            Word('良く', 'ヨク'),
            Word('最高', 'サイコウ')
        ]
        self.assertEqual(r1, r2)
示例#8
0
 def test_eq(self) -> None:
     self.assertNotEqual(Word(surface='<unk>', yomi='<unk>'),
                         TagWord('<unk>'))
示例#9
0
 def test_str(self, msg: str = 'str(Word)') -> None:
     word = Word(surface='歩下', yomi='ホゲ')
     str_ = str(word)
     self.assertEqual(str_, '歩下/ホゲ')