Skip to content

Commit

Permalink
Added inline text parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
luisulloa committed Dec 14, 2017
1 parent 70edb24 commit 7c24542
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cape/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ def set_default_threshold(self, threshold):
return r.json()['result']['threshold']

def answer(self, question, token=None, threshold=None, document_ids=None,
source_type='all', speed_or_accuracy='balanced', number_of_items=1, offset=0):
source_type='all', speed_or_accuracy='balanced', number_of_items=1, offset=0,
text=None):
"""
Provide a list of answers to a given question.
Expand All @@ -161,6 +162,7 @@ def answer(self, question, token=None, threshold=None, document_ids=None,
:param speed_or_accuracy: Prioritise speed or accuracy in answers ('speed'/'accuracy'/'balanced')
:param number_of_items: The number of answers to return
:param offset: The starting point in the list of answers, used in conjunction with number_of_items to retrieve multiple batches of answers.
:param text: An inline text to be treated as a document with id "Inline Text"
:return: A list of answers
"""
if document_ids is not None:
Expand All @@ -181,7 +183,8 @@ def answer(self, question, token=None, threshold=None, document_ids=None,
'sourceType': str(source_type),
'speedOrAccuracy': speed_or_accuracy,
'numberOfItems': str(number_of_items),
'offset': str(offset)}
'offset': str(offset),
'text': text}
if token is None:
params.pop('token')
if not self.logged_in():
Expand All @@ -190,6 +193,8 @@ def answer(self, question, token=None, threshold=None, document_ids=None,
params.pop('documentIds')
if threshold is None:
params.pop('threshold')
if text is None:
params.pop('text')
r = self._raw_api_call('answer', params)
return r.json()['result']['items']

Expand Down
3 changes: 3 additions & 0 deletions tests/test_answers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ def test_document_ids(cc):
answers = cc.answer("Is this API easy to use?", document_ids=["358e1b77c9bcc353946dfe107d6b32ff"])
assert len(answers) == 1

def test_inline_answer(cc):
answers = cc.answer("Is this API easy to use?", text="This API is easy to use.")
assert len(answers) == 1

def test_answer_exceptions(cc):
with pytest.raises(CapeException):
Expand Down

0 comments on commit 7c24542

Please sign in to comment.