From defc0713642a4e917fa9bcc3fd76a139ac7f7339 Mon Sep 17 00:00:00 2001 From: HES SONG Date: Fri, 6 Oct 2017 15:54:57 -0700 Subject: [PATCH] Update corenlp.py Now there is latest version of Stanford Core NLP(3.8.0). There is simple change in this module, so this change can be work for new version. --- corenlp.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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.