diff --git a/corenlp.py b/corenlp.py index 753e51c..49444d9 100644 --- a/corenlp.py +++ b/corenlp.py @@ -72,6 +72,10 @@ def parse_parser_results(text): """ results = {"sentences": []} state = STATE_START + + + + for line in text.encode('utf-8').split("\n"): line = line.strip() @@ -86,10 +90,14 @@ def parse_parser_results(text): elif state == STATE_WORDS: if not line.startswith("[Text="): - raise Exception('Parse error. Could not find "[Text=" in: %s' % line) + if line.startswith("NLP>"): + state = STATE_TREE + pass + else: + raise Exception('Parse error. Could not find "[Text=" in: %s' % line) for s in WORD_PATTERN.findall(line): sentence['words'].append(parse_bracketed(s)) - state = STATE_TREE + #state = STATE_TREE elif state == STATE_TREE: if len(line) == 0: @@ -121,7 +129,6 @@ def parse_parser_results(text): return results - class StanfordCoreNLP(object): """ Command-line interaction with Stanford's CoreNLP java utilities.