From 278745610c9414aff46dc4559c748020b90445d1 Mon Sep 17 00:00:00 2001 From: Linghao Zhang Date: Sat, 24 Oct 2015 20:43:35 +0800 Subject: [PATCH] fix xml parsing issue when there is only one sentence in the result --- corenlp/corenlp.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/corenlp/corenlp.py b/corenlp/corenlp.py index f2c9a16..65284f7 100644 --- a/corenlp/corenlp.py +++ b/corenlp/corenlp.py @@ -222,8 +222,10 @@ def extract_words_from_xml(sent_node): # Making a raw sentence list of dictionaries: raw_sent_list = document[u'sentences'][u'sentence'] + if type(raw_sent_list) != list: + raw_sent_list = [raw_sent_list] + # Convert sentences to the format like python - # TODO: If there is only one sentence in input sentence, # raw_sent_list is dict and cannot decode following code... sentences = [{'dependencies': [[dep['dep'][i]['@type'], dep['dep'][i]['governor']['#text'],