-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_rule_manager.py
44 lines (30 loc) · 1.79 KB
/
test_rule_manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import unittest
from choppa.rule_manager import RuleManager
from choppa.structures import Rule, LanguageRule
from choppa.srx_parser import SrxDocument
from typing import List
class RuleManagerTest(unittest.TestCase):
def test_simple_rule(self) -> None:
language_rule_pl: LanguageRule = LanguageRule("Polish")
rule1: Rule = Rule(False, r"[Pp]rof\.", r"\s")
language_rule_pl.add_rule(rule1)
language_rule_en: LanguageRule = LanguageRule("English")
rule2: Rule = Rule(False, r"Mr\.", r"\s")
language_rule_en.add_rule(rule2)
language_rule_def: LanguageRule = LanguageRule("Default")
break_rule1 = Rule(True, r"\.", r"\s")
language_rule_def.add_rule(break_rule1)
break_rule2 = Rule(True, r"", r"\n")
language_rule_def.add_rule(break_rule2)
document: SrxDocument = SrxDocument()
document.add_language_map("pl.*", language_rule_pl)
document.add_language_map("en.*", language_rule_en)
document.add_language_map(".*", language_rule_def)
language_rule_list: List[LanguageRule] = document.get_language_rule_list("pl")
rule_manager: RuleManager = document.get_rule_manager(language_rule_list, 100)
self.assertEqual(rule_manager.exception_pattern_map[break_rule1].pattern, r"(?:(?<=[Pp]rof\.)(?=\s))")
self.assertEqual(rule_manager.exception_pattern_map[break_rule2].pattern, r"(?:(?<=[Pp]rof\.)(?=\s))")
language_rule_list = document.get_language_rule_list("en")
rule_manager: RuleManager = document.get_rule_manager(language_rule_list, 100)
self.assertEqual(rule_manager.exception_pattern_map[break_rule1].pattern, r"(?:(?<=Mr\.)(?=\s))")
self.assertEqual(rule_manager.exception_pattern_map[break_rule2].pattern, r"(?:(?<=Mr\.)(?=\s))")