def test_parse(self): path = bllip_wrapper.init_model() rrp = RerankingParser.from_unified_model_dir(path) tree = bllip_wrapper.parse(rrp, 'hello world!') self.assertIsNotNone(tree) print tree.ptb_parse self.assertEqual(str(tree.ptb_parse), '(S1 (S (NP (NN hello) (NN world) (NN !))))')
def bllip_parse(): global rrp if request.method == 'GET': text = str(request.args.get('text')) elif request.method == 'POST': text = str(request.get_data()) lines = text.splitlines() trees = [] for line in lines: tree = parse(rrp, line) trees.append(tree) return "\n".join(str(tree.ptb_parse) if tree is not None else '' for tree in trees)