Skip to content

Commit

Permalink
remove try/except clauses from subfunctions
Browse files Browse the repository at this point in the history
  • Loading branch information
alistairewj committed Feb 19, 2019
1 parent 419768e commit 0f7f293
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
29 changes: 12 additions & 17 deletions negbio/pipeline/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,11 @@ def parse(self, s):
if not s:
raise ValueError('Cannot parse empty sentence: {}'.format(s))

try:
nbest = self.rrp.parse(str(s))
if nbest:
return nbest[0].ptb_parse
else:
return None
except:
raise ValueError('Cannot parse sentence: %s' % s)
nbest = self.rrp.parse(str(s))
if nbest:
return nbest[0].ptb_parse

return None


class NegBioParser(Bllip):
Expand All @@ -54,14 +51,12 @@ def parse_doc(self, document):
"""
for passage in document.passages:
for sentence in passage.sentences:
try:
text = sentence.text
tree = self.parse(text)
if tree:
sentence.infons['parse tree'] = str(tree)
else:
sentence.infons['parse tree'] = None
except:
text = sentence.text
tree = self.parse(text)
if tree:
sentence.infons['parse tree'] = str(tree)
else:
sentence.infons['parse tree'] = None
logging.exception(
'Cannot parse sentence: {}'.format(sentence.offset))
'No parse tree for sentence: %s', sentence.offset)
return document
4 changes: 0 additions & 4 deletions negbio/pipeline/ptb2ud.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,8 @@ def convert_doc(self, document):
# check for empty infons, don't process if empty
# this sometimes happens with poorly tokenized sentences
if not sentence.infons:
logging.warning(
"No parse information for sentence %d in %s", sentence.offset, document.id)
continue
elif not sentence.infons['parse tree']:
logging.warning(
"No parse tree for sentence %d in %s", sentence.offset, document.id)
continue

try:
Expand Down

0 comments on commit 0f7f293

Please sign in to comment.