diff --git a/Giveme5W1H/extractor/candidate.py b/Giveme5W1H/extractor/candidate.py index c0584966..539bbe15 100644 --- a/Giveme5W1H/extractor/candidate.py +++ b/Giveme5W1H/extractor/candidate.py @@ -23,6 +23,9 @@ def set_parts(self, parts): self._parts = parts def get_parts_as_text(self): + if not self._parts: + return "No result can be found in the document." + answer_text = [] for part in self._parts: answer_text.append(part[0]['nlpToken']['originalText']) diff --git a/Giveme5W1H/extractor/document.py b/Giveme5W1H/extractor/document.py index 4c65824b..2cbbfd4e 100644 --- a/Giveme5W1H/extractor/document.py +++ b/Giveme5W1H/extractor/document.py @@ -1,3 +1,4 @@ +from .candidate import Candidate class Document(object): """ Document is a pickable container for the raw document and all related data @@ -148,7 +149,11 @@ def get_answers(self, question=None): return self._answers def get_top_answer(self, question): - return self.get_answers(question=question)[0] + answers = self.get_answers(question=question) + if len(answers) == 0: + return Candidate() + else: + return answers[0] def get_annotations(self): return self._annotations