示例#1
0
    def test_str(self) -> None:
        k = Key([1])
        self.assertEqual(str(k), '1')

        k = Key([0, 1])
        with self.assertRaises(TypeError):
            str(k)
示例#2
0
    def test_from_words(self) -> None:
        with self.subTest():
            k1 = Key.from_words([self.hoge])
            k2 = Key([5, 1])
            self.assertEqual(k1, k2)

        with self.subTest():
            k1 = Key.from_words([self.hoge, self.fuga])
            k2 = Key([5, 1, 5, 1])
            self.assertEqual(k1, k2)
示例#3
0
 def setUp(self) -> None:
     self.lm = self.__class__.LM
     self.vocab = self.lm.create_vocabrary()
     self.key = Key([3, 1, 4, TagWord('<num>')])
     self.keys = [
         Key([TagWord('<num>')]),
         Key([4, TagWord('<num>')]),
         Key([1, 4, TagWord('<num>')]),
         Key([3, 1, 4, TagWord('<num>')]),
     ]
示例#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
class TestKey(unittest.TestCase):
    def setUp(self) -> None:
        self.hoge = Word(surface='歩下', yomi='ホゲ')
        self.fuga = Word(surface='不臥', yomi='フガ')

        self.key = Key([0, 1, 2, 3])

    def test_from_words(self) -> None:
        with self.subTest():
            k1 = Key.from_words([self.hoge])
            k2 = Key([5, 1])
            self.assertEqual(k1, k2)

        with self.subTest():
            k1 = Key.from_words([self.hoge, self.fuga])
            k2 = Key([5, 1, 5, 1])
            self.assertEqual(k1, k2)

    def test_str(self) -> None:
        k = Key([1])
        self.assertEqual(str(k), '1')

        k = Key([0, 1])
        with self.assertRaises(TypeError):
            str(k)

    def test_add(self) -> None:
        k1 = Key([0, 1, TagWord('<num>')])
        k2 = Key([2, 3])
        self.assertEqual(k1 + k2, Key([0, 1, TagWord('<num>'), 2, 3]))

    def test_subsequence(self) -> None:
        with self.subTest(msg="end=4でerror"):
            with self.assertRaises(ValueError):
                list(self.key.subsequence_with_end(4))

        with self.subTest(msg="end<0でerror"):
            with self.assertRaises(ValueError):
                list(self.key.subsequence_with_end(-1))

        with self.subTest(msg="end=2"):
            list_ = list(self.key.subsequence_with_end(2))
            self.assertIn(Key([2]), list_)
            self.assertIn(Key([1, 2]), list_)
            self.assertIn(Key([0, 1, 2]), list_)

        with self.subTest(msg="all_of_subsequence(end=3と同等なはず)、順序も検査"):
            target = list(self.key.all_of_subsequence())
            wrong = [
                Key([2, 3]),
                Key([3]),
                Key([1, 2, 3]),
                Key([0, 1, 2, 3]),
            ]
            self.assertNotEqual(target, wrong)

            correct = [
                Key([3]),
                Key([2, 3]),
                Key([1, 2, 3]),
                Key([0, 1, 2, 3]),
            ]
            self.assertEqual(target, correct)

        with self.subTest(msg="TagWordが絡む場合、順序もざっと検査"):
            k = Key([3, 1, 4, TagWord('<num>')])
            target = list(k.all_of_subsequence())

            correct = [
                Key([TagWord('<num>')]),
                Key([4, TagWord('<num>')]),
                Key([1, 4, TagWord('<num>')]),
                Key([3, 1, 4, TagWord('<num>')]),
            ]
            self.assertEqual(target, correct)
示例#7
0
    def test_subsequence(self) -> None:
        with self.subTest(msg="end=4でerror"):
            with self.assertRaises(ValueError):
                list(self.key.subsequence_with_end(4))

        with self.subTest(msg="end<0でerror"):
            with self.assertRaises(ValueError):
                list(self.key.subsequence_with_end(-1))

        with self.subTest(msg="end=2"):
            list_ = list(self.key.subsequence_with_end(2))
            self.assertIn(Key([2]), list_)
            self.assertIn(Key([1, 2]), list_)
            self.assertIn(Key([0, 1, 2]), list_)

        with self.subTest(msg="all_of_subsequence(end=3と同等なはず)、順序も検査"):
            target = list(self.key.all_of_subsequence())
            wrong = [
                Key([2, 3]),
                Key([3]),
                Key([1, 2, 3]),
                Key([0, 1, 2, 3]),
            ]
            self.assertNotEqual(target, wrong)

            correct = [
                Key([3]),
                Key([2, 3]),
                Key([1, 2, 3]),
                Key([0, 1, 2, 3]),
            ]
            self.assertEqual(target, correct)

        with self.subTest(msg="TagWordが絡む場合、順序もざっと検査"):
            k = Key([3, 1, 4, TagWord('<num>')])
            target = list(k.all_of_subsequence())

            correct = [
                Key([TagWord('<num>')]),
                Key([4, TagWord('<num>')]),
                Key([1, 4, TagWord('<num>')]),
                Key([3, 1, 4, TagWord('<num>')]),
            ]
            self.assertEqual(target, correct)
示例#8
0
 def test_add(self) -> None:
     k1 = Key([0, 1, TagWord('<num>')])
     k2 = Key([2, 3])
     self.assertEqual(k1 + k2, Key([0, 1, TagWord('<num>'), 2, 3]))
示例#9
0
    def test_have_num_tagword(self) -> None:
        with self.subTest():
            self.assertIn(TagWord('<num>'), self.lm._get_word_set())

        self.assertIn(Key([TagWord('<num>')]), self.vocab._datum.keys())