Skip to content

Commit

Permalink
Merge pull request stanfordnlp#262 from stanfordnlp/barf_if_propertie…
Browse files Browse the repository at this point in the history
…s_unknown

Barf if an unknown properties file was asked for
  • Loading branch information
AngledLuffa authored Apr 21, 2020
2 parents 310cfe2 + 21a0227 commit 63f44d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion stanza/server/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,10 @@ def annotate(self, text, annotators=None, output_format=None, properties_key=Non
request_properties = dict(ENGLISH_DEFAULT_REQUEST_PROPERTIES)
elif properties_key.lower() in CoreNLPClient.PIPELINE_LANGUAGES:
request_properties = {'pipelineLanguage': properties_key.lower()}
elif properties_key not in self.properties_cache:
raise ValueError("Properties cache does not have '%s'" % properties_key)
else:
request_properties = dict(self.properties_cache.get(properties_key, {}))
request_properties = dict(self.properties_cache[properties_key])
else:
request_properties = {}
# add on custom properties for this request
Expand Down
6 changes: 6 additions & 0 deletions tests/test_server_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,9 @@ def test_english_request():
assert ann.strip() == EN_DOC_GOLD.strip()



def test_unknown_request():
""" Test case of starting server with Spanish defaults, and then requesting UNBAN_MOX_OPAL properties """
with corenlp.CoreNLPClient(properties='spanish', server_id='test_english_request') as client:
with pytest.raises(ValueError):
ann = client.annotate(EN_DOC, properties_key='UNBAN_MOX_OPAL', output_format='text')

0 comments on commit 63f44d0

Please sign in to comment.