Esempio n. 1
0
    def test_rename_action(self):
        text = '一条中第三項を第四項とする'
        action = parse_action_text(text)

        self.assertTrue(isinstance(action, RenameAction))
        self.assertEqual(Query.from_text('一条中第三項'), action.old)
        self.assertEqual(Query.from_text('第四項'), action.new)
        self.assertTrue(is_serializable(action))
Esempio n. 2
0
 def from_text(cls, text, meta=None):
     masked_text, placeholder_map = mask_escape(text)
     match = cls._match_pattern(masked_text)
     return cls(text=text,
                meta=meta,
                at=Query.from_text(match.group(1).format(**placeholder_map)),
                what=match.group(2).format(**placeholder_map))
Esempio n. 3
0
 def from_text(cls, text, meta=None):
     match = cls._match_pattern(text)
     return cls(text=text,
                meta=meta,
                at=Query.from_text(match.group(1)),
                word=match.group(2),
                what=match.group(3))
Esempio n. 4
0
    def test_add_law_action(self):
        text = '第二条に次の二項を加え'
        action = parse_action_text(text)

        self.assertTrue(isinstance(action, AddLawAction))
        self.assertEqual(Query.from_text('第二条'), action.at)
        self.assertEqual('二項', action.what)
        self.assertTrue(is_serializable(action))
Esempio n. 5
0
    def test_law_node_finder(self):
        finder = LawNodeFinder(self.build_sample_law_tree())
        nodes = finder.find(Query.from_text('第一条第二項'))

        self.assertEqual(1, len(nodes))
        node = nodes[0]
        self.assertTrue(isinstance(node, Paragraph))
        self.assertEqual('第一条第二項', node.sentence)
Esempio n. 6
0
    def test_replace_action_short(self):
        text = '「第百二十五条」を「第百二十五条の二」に'
        action = parse_action_text(text)

        self.assertTrue(isinstance(action, ReplaceAction))
        self.assertEqual(Query.from_text(''), action.at)
        self.assertEqual('第百二十五条', action.old)
        self.assertEqual('第百二十五条の二', action.new)
        self.assertTrue(is_serializable(action))
Esempio n. 7
0
    def test_replace_action(self):
        text = '第一条中「中「小」」を「大「中」」に改める'
        action = parse_action_text(text)

        self.assertTrue(isinstance(action, ReplaceAction))
        self.assertEqual(Query.from_text('第一条'), action.at)
        self.assertEqual('中「小」', action.old)
        self.assertEqual('大「中」', action.new)
        self.assertTrue(is_serializable(action))
Esempio n. 8
0
    def test_add_word_action_short(self):
        text = '「前項」の下に「について」を'
        action = parse_action_text(text)

        self.assertTrue(isinstance(action, AddWordAction))
        self.assertEqual(Query.from_text(''), action.at)
        self.assertEqual('前項', action.word)
        self.assertEqual('について', action.what)
        self.assertTrue(is_serializable(action))
Esempio n. 9
0
    def test_delete_action_short(self):
        text = '「その他」及び「前項」を削り'
        action = parse_action_text(text)

        self.assertTrue(isinstance(action, DeleteAction))
        self.assertEqual(Query.from_text(''), action.at)
        self.assertEqual(2, len(action.whats))
        self.assertEqual('その他', action.whats[0])
        self.assertEqual('前項', action.whats[1])
        self.assertTrue(is_serializable(action))
Esempio n. 10
0
    def test_compensate_success(self):
        qc = QueryCompensator()
        texts = ['附則第一条第二項第三号', 'ランダムな文', '同項第四号の次', '第二条', '', '第三項', '第一節', '同節']
        results = list(map(lambda text: qc.compensate(Query.from_text(text)), texts))

        self.assertEqual(len(texts), len(results))
        for i, result in enumerate(results):
            if i == 0:
                self.assertEqual('附則第一条第二項第三号', result.text)
                self.assertEqual('附則', result.get(LawHierarchy.SUPPLEMENT))
                self.assertEqual('第一条', result.get(LawHierarchy.ARTICLE))
                self.assertEqual('第二項', result.get(LawHierarchy.PARAGRAPH))
                self.assertEqual('第三号', result.get(LawHierarchy.ITEM))
            elif i == 1:
                self.assertEqual('ランダムな文', result.text)
                self.assertTrue(result.is_empty())
            elif i == 2:
                self.assertEqual('同項第四号の次', result.text)
                self.assertEqual(QueryType.AFTER, result.query_type)
                self.assertEqual('附則', result.get(LawHierarchy.SUPPLEMENT))
                self.assertEqual('第一条', result.get(LawHierarchy.ARTICLE))
                self.assertEqual('第二項', result.get(LawHierarchy.PARAGRAPH))
                self.assertEqual('第四号', result.get(LawHierarchy.ITEM))
            elif i == 3:
                self.assertEqual('第二条', result.text)
                self.assertEqual(QueryType.AT, result.query_type)
                self.assertEqual('附則', result.get(LawHierarchy.SUPPLEMENT))
                self.assertEqual('第二条', result.get(LawHierarchy.ARTICLE))
                self.assertFalse(result.has(LawHierarchy.PARAGRAPH))
                self.assertFalse(result.has(LawHierarchy.ITEM))
            elif i == 4:
                self.assertEqual('', result.text)
                self.assertEqual(QueryType.AT, result.query_type)
                self.assertEqual('附則', result.get(LawHierarchy.SUPPLEMENT))
                self.assertEqual('第二条', result.get(LawHierarchy.ARTICLE))
                self.assertFalse(result.has(LawHierarchy.PARAGRAPH))
                self.assertFalse(result.has(LawHierarchy.ITEM))
            elif i == 5:
                self.assertEqual('第三項', result.text)
                self.assertEqual(QueryType.AT, result.query_type)
                self.assertEqual('附則', result.get(LawHierarchy.SUPPLEMENT))
                self.assertEqual('第二条', result.get(LawHierarchy.ARTICLE))
                self.assertEqual('第三項', result.get(LawHierarchy.PARAGRAPH))
                self.assertFalse(result.has(LawHierarchy.ITEM))
            elif i == 6:
                self.assertEqual('第一節', result.text)
                self.assertEqual(QueryType.AT, result.query_type)
                self.assertEqual('附則', result.get(LawHierarchy.SUPPLEMENT))
                self.assertEqual('第一節', result.get(LawHierarchy.SECTION))
            elif i == 7:
                self.assertEqual('同節', result.text)
                self.assertEqual(QueryType.AT, result.query_type)
                self.assertEqual('附則', result.get(LawHierarchy.SUPPLEMENT))
                self.assertEqual('第一節', result.get(LawHierarchy.SECTION))
Esempio n. 11
0
    def test_from_text(self):
        text = '第一条第二項第三号の次'
        query = Query.from_text(text)

        self.assertEqual(text, query.text)
        self.assertEqual(QueryType.AFTER, query.query_type)
        self.assertEqual('第一条', query.get(LawHierarchy.ARTICLE))
        self.assertEqual('第二項', query.get(LawHierarchy.PARAGRAPH))
        self.assertEqual('第三号', query.get(LawHierarchy.ITEM))
        self.assertEqual('', query.get(LawHierarchy.SUBITEM1))
        self.assertTrue(is_serializable(query))
        print(query.serialize())
Esempio n. 12
0
 def test_law_node_finder_fail(self):
     finder = LawNodeFinder(self.build_sample_law_tree())
     self.assertEqual(0, len(finder.find(Query.from_text('第一条第一号イ'))))
     self.assertEqual(0, len(finder.find(Query.from_text('第三条'))))
Esempio n. 13
0
 def from_text(cls, text, meta=None):
     match = cls._match_pattern(text)
     return cls(text=text,
                meta=meta,
                old=Query.from_text(match.group(1)),
                new=Query.from_text(match.group(2)))
Esempio n. 14
0
 def from_text(cls, text, meta=None):
     match = cls._match_pattern(text)
     return cls(text=text,
                meta=meta,
                at=Query.from_text(match.group(1)),
                whats=match.group(2).split('」及び「'))
Esempio n. 15
0
 def test_compensate_fail(self):
     qc = QueryCompensator()
     query = Query.from_text('同条中第三項')
     with self.assertRaises(ValueError):
         qc.compensate(query)