Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Giveme5W1H/extractor/candidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
7 changes: 6 additions & 1 deletion Giveme5W1H/extractor/document.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .candidate import Candidate
class Document(object):
"""
Document is a pickable container for the raw document and all related data
Expand Down Expand Up @@ -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
Expand Down