def genTestCost(cls): parser = Parser() parser.load_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 gen_TestUnifyBinary(): parser = Parser() parser.load_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 genTransUnify(): # used for data generation parser = Parser() parser.load_grammar(text=TestTransUnify.grammar) parser.compile() parser.parse(TestTransUnify.sent) tree = parser.make_tree() utree = parser.unify_tree(tree) print(utree.pformat_ext()) ttree = parser.trans_tree(utree) #print(ttree.format(3)) #print(ttree.pformat(3)) #print(ttree.str_format(3)) #lst = ttree.list_format(3) #print(Tree.convert_tree(lst).replace(" -","")) trans_list = [parser.post_processor(trans) for trans in ttree.enum()] print(trans_list)