def test_rules(self): self.maxDiff = None for define, exp_rules in zip(self.defines, self.rule_sets): parser = Parser() parser.parse_grammar(text=define + self.grammar) with self.subTest(rules=parser.rules, exp_rules=exp_rules): self.assertEqual(parser.rules, exp_rules)
def genTestMacro(): for define, exp_rules in zip(TestIfdef.defines, TestIfdef.rule_sets): parser = Parser() parser.parse_grammar(text=define + TestIfdef.grammar) print(define) print(parser.rules) print("==============================")
def setUp(self): parser = Parser() parser.parse_grammar(text=self.grammar) parser.compile() self.parser = parser self.maxDiff = None
def genTestCost(cls): parser = Parser() parser.parse_grammar(text=cls.grammar, reverse=cls.reverse) parser.compile() for sent in cls.sents: parser.parse(sent) tree = parser.make_tree() utree = parser.unify_tree(tree) ttree = parser.trans_tree(utree) print(list(sorted(ttree.enumx())))
def setUp(self): parser = Parser("EN","TR") grammar = textwrap.dedent(self.grammar) parser.parse_grammar(text=grammar) parser.compile() parser.parse(self.sent) self.parser = parser self.tree = parser.make_tree() self.ttree = parser.trans_tree(self.tree) self.maxDiff = None
def setUp(self): parser = Parser() grammar = textwrap.dedent(self.grammar) parser.parse_grammar(text=grammar) sent = "c" parser.compile() parser.parse(sent) self.parser = parser self.tree = parser.make_tree() self.maxDiff = None
def setUp(self): parser = Parser() grammar = textwrap.dedent(self.grammar) parser.parse_grammar(text=grammar) sent = "i saw the man in the house with the telescope" parser.compile() parser.parse(sent) self.parser = parser self.tree = parser.make_tree() self.maxDiff = None
def gen_TestParseMiddleEmpty(): parser = Parser() grammar = textwrap.dedent(TestParseMiddleEmpty.grammar) parser.parse_grammar(text=grammar) sent = "c" parser.compile() parser.parse(sent) tree = parser.make_tree() print(tree.format()) print(tree.str_format()) print(tree.pformat()) print(tree.pformat_ext())
def gen_TestParseSimpleEmpty(): parser = Parser() grammar = textwrap.dedent(TestParseSimpleEmpty.grammar) parser.parse_grammar(text=grammar) sent = "i saw man in apt with tel" parser.compile() parser.parse(sent) tree = parser.make_tree() print(tree.format()) print(tree.str_format()) print(tree.pformat()) print(tree.pformat_ext())
def gen_TestParseSimple(): parser = Parser() grammar = textwrap.dedent(TestParseSimple.grammar) parser.parse_grammar(text=grammar) sent = "i saw the man in the house with the telescope" parser.compile() parser.parse(sent) tree = parser.make_tree() print(tree.format()) print(tree.str_format()) print(tree.pformat()) print(tree.pformat_ext())
def gen_TestUnifyBinary(): parser = Parser() parser.parse_grammar(text=TestUnifyBinary.grammar) parser.compile() sents = [ "a0 b0", "a0 b1", "a1 b0", "a1 b1" ] for sent in sents: print(sent) try: parser.parse(sent) tree = parser.make_tree() tree2 = parser.unify_tree(tree) print(tree2.pformat_ext()) except UnifyError as ue: print(ue) except ParseError as pe: print(pe)
def gen_TestUnify(): parser = Parser() parser.parse_grammar(text=TestUnify.grammar) parser.compile() sents = ["i am watching her", "she is watching me", "these men are watching us", "me am watching you", "she is watching i", "two man is watching it", "a man watch us", "they watch us", "he watches the men", "he watches a men", "i watch him"] for sent in sents: print(sent) try: parser.parse(sent) tree = parser.make_tree() tree2 = parser.unify_tree(tree) print(tree2.pformat_ext()) except UnifyError as ue: print(ue) except ParseError as pe: print(pe)
def genTrans(): # used for data generation parser = Parser() parser.parse_grammar(text=TestTrans.grammar) parser.compile() parser.parse(TestTrans.sent) tree = parser.make_tree() ttree = parser.trans_tree(tree) print(ttree.formatr()) print(ttree.pformatr()) print(ttree.str_formatr()) lst = ttree.list_formatr() #print(Tree.convert_tree(lst).replace(" -","")) trans_list = [parser.post_processor(trans) for trans in ttree.enum()] print(trans_list)
def genTestMacro(): parser = Parser() parser.parse_grammar(text=TestMacro.grammar) for rule in parser.rules: print(rule)
def setUp(self): parser = Parser() parser.parse_grammar(text=self.grammar, reverse=self.reverse) parser.compile() self.parser = parser