Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Commit

Permalink
failure from lex entity service shouldn't crash response
Browse files Browse the repository at this point in the history
  • Loading branch information
balmas committed Aug 23, 2017
1 parent eeca391 commit 9a4c896
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions morphsvc/lib/engines/MorpheusLocalEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,24 @@ def add_lexical_entity_uris(self,analysis,language):
"""
lemmas = analysis.xpath('//hdwd')
for l in lemmas:
resp = self._execute_lexical_query(language,l.text)
uri_xml = etree.fromstring(resp)
uri = ""
uris = uri_xml.xpath('//cs:reply//cite:citeObject',
try:
resp = self._execute_lexical_query(language,l.text)
uri_xml = etree.fromstring(resp)
uri = ""
uris = uri_xml.xpath('//cs:reply//cite:citeObject',
namespaces = {'cs':'http://shot.holycross.edu/xmlns/citequery',
'cite':'http://shot.holycross.edu/xmlns/cite'})
if len(uris) > 0:
uri = uris[0].get('urn')
else:
uris = uri_xml.xpath('//sparql:results/sparql:result/sparql:binding/sparql:uri',
namespaces = {'sparql':'http://www.w3.org/2005/sparql-results#'})
if len(uris) > 0:
uri = uris[0].text
if uri:
l.getparent().getparent().set('uri',self.lexical_entity_base_uri+uri)
uri = uris[0].get('urn')
else:
uris = uri_xml.xpath('//sparql:results/sparql:result/sparql:binding/sparql:uri',
namespaces = {'sparql':'http://www.w3.org/2005/sparql-results#'})
if len(uris) > 0:
uri = uris[0].text
if uri:
l.getparent().getparent().set('uri',self.lexical_entity_base_uri+uri)
except:
pass

def _execute_lexical_query(self,language,lemma):
""" Executes the configured lexical entity query service
Expand Down

0 comments on commit 9a4c896

Please sign in to comment.