Skip to content

Commit

Permalink
Changes to exceptions (issue #79).
Browse files Browse the repository at this point in the history
  • Loading branch information
marcverhagen committed Dec 16, 2020
1 parent c378f68 commit 854baed
Show file tree
Hide file tree
Showing 14 changed files with 276 additions and 113 deletions.
5 changes: 2 additions & 3 deletions components/common_modules/chunks.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,8 @@ def _passes_semantics_test(self):
is_event = self._run_classifier(lemma)
logger.debug(" baysian classifier result ==> %s" % is_event)
return is_event
except bayes.DisambiguationError, (strerror):
pass
logger.debug(" DisambiguationError: %s" % unicode(strerror))
except bayes.DisambiguationError as e:
logger.debug(" DisambiguationError: %s" % e)
# check whether primary sense or some of the senses are events
if EVITA_NOM_WNPRIMSENSE_ONLY:
is_event = wordnet.primarySenseIsEvent(lemma)
Expand Down
2 changes: 1 addition & 1 deletion components/common_modules/constituent.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def matchConstituent(self, description):
if self.feature_value(feat) == value[1]:
return False
else:
raise "ERROR specifying description of pattern"
raise Exception("ERROR specifying description of pattern")
elif type(value) is ListType:
if self.feature_value(feat) not in value:
if self.isChunk() and feat == 'text':
Expand Down
4 changes: 2 additions & 2 deletions components/common_modules/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def feature_value(self, name):
logger.warn("Returning 'epos' instead of 'pos' value")
return self.tree.events[self.eid][EPOS]
else:
raise AttributeError, name
raise AttributeError(name)

def _get_attribute(self, name, default):
try:
Expand Down Expand Up @@ -127,7 +127,7 @@ def feature_value(self, name):
EVENTID, EIID, CLASS]:
return None
else:
raise AttributeError, name
raise AttributeError(name)

def isTimex(self):
return True
Expand Down
4 changes: 2 additions & 2 deletions components/common_modules/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def feature_value(self, name):
EPOS, MOD, POL, EVENTID, EIID, CLASS]:
return None
else:
raise AttributeError, name
raise AttributeError(name)

def getText(self):
"""Return the text of the token."""
Expand Down Expand Up @@ -156,7 +156,7 @@ def feature_value(self, name):
return self.tree.events[self.eid].get(POS,'NONE')
return self.tree.events[self.eid][name]
else:
raise AttributeError, name
raise AttributeError(name)

def isAdjToken(self):
return True
Expand Down
4 changes: 2 additions & 2 deletions components/evita/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,13 @@ def is_do_auxiliar(self):
def normalizeMod(self, form):
if form == 'ca': return 'can'
elif form == "'d": return 'would'
else: raise "ERROR: unknown modal form: "+str(form)
else: raise Exception("ERROR: unknown modal form: "+str(form))

def normalizeHave(self, form):
if form == "'d": return 'had'
elif form == "'s": return 'has'
elif form == "'ve": return 'have'
else: raise "ERROR: unknown raise form: "+str(form)
else: raise Exception("ERROR: unknown raise form: "+str(form))

def getPolarity(self):
if self.negative:
Expand Down
48 changes: 24 additions & 24 deletions components/merging/sputlink/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,28 +341,28 @@ def pp_html(self, filename=None, filehandle=None, standalone=False):
fh = open(filename, 'w') if filename else filehandle
if standalone:
html_graph_prefix(fh)
fh.write("<table cellpadding=0 cellspacing=0 border=0>\n")
fh.write("<tr><td>\n")
fh.write(u"<table cellpadding=0 cellspacing=0 border=0>\n")
fh.write(u"<tr><td>\n")
nodes = self.nodes.keys()
nodes.sort(compare_id)
self._html_nodes_table(fh, nodes)
fh.write("</td>\n\n")
fh.write("<td valign=top>\n")
fh.write(u"</td>\n\n")
fh.write(u"<td valign=top>\n")
self._html_added_table(fh)
fh.write("</td></tr>\n\n")
fh.write("</table>\n\n")
fh.write(u"</td></tr>\n\n")
fh.write(u"</table>\n\n")
if standalone:
fh.write("</body>\n</html>\n\n")
fh.write(u"</body>\n</html>\n\n")

def _html_nodes_table(self, fh, nodes):
fh.write("<table cellpadding=5 cellspacing=0 border=1>\n")
fh.write("\n<tr>\n\n")
fh.write(" <td>&nbsp;\n\n")
fh.write(u"<table cellpadding=5 cellspacing=0 border=1>\n")
fh.write(u"\n<tr>\n\n")
fh.write(u" <td>&nbsp;\n\n")
for identifier in nodes:
fh.write(" <td>%s\n" % identifier)
fh.write(u" <td>%s\n" % identifier)
for id1 in nodes:
fh.write("\n\n<tr align=center>\n\n")
fh.write(" <td align=left>%s\n" % id1)
fh.write(u"\n\n<tr align=center>\n\n")
fh.write(u" <td align=left>%s\n" % id1)
for id2 in nodes:
edge = self.edges[id1][id2]
rel = edge.relset
Expand All @@ -379,26 +379,26 @@ def _html_nodes_table(self, fh, nodes):
classes.append("nocell")
# rel = '&nbsp;'
classes = " class=\"%s\"" % ' '.join(classes)
fh.write(" <td width=25pt%s>%s\n" % (classes, rel))
fh.write("</table>\n\n")
fh.write(u" <td width=25pt%s>%s\n" % (classes, rel))
fh.write(u"</table>\n\n")

def _html_added_table(self, fh):
fh.write("<table cellpadding=5 cellspacing=0 border=1>\n")
fh.write(u"<table cellpadding=5 cellspacing=0 border=1>\n")
if self.added:
fh.write("<tr><td>added<td colspan=2>derived from\n")
fh.write(u"<tr><td>added<td colspan=2>derived from\n")
for c in self.added:
fh.write("<tr>\n <td>%s</td>\n" % c)
fh.write(u"<tr>\n <td>%s</td>\n" % c)
if isinstance(c.history, tuple):
fh.write(" <td>%s\n" % str(c.history[0]))
fh.write(" <td>%s\n" % str(c.history[1]))
fh.write(u" <td>%s\n" % str(c.history[0]))
fh.write(u" <td>%s\n" % str(c.history[1]))
elif c.history.__class__.__name__ == 'Tag':
tlink = "TLINK(relType=%s)" % c.history.attrs.get('relType')
fh.write(" <td colspan=2>%s\n" % tlink)
fh.write(u" <td colspan=2>%s\n" % tlink)
elif c.history.__class__.__name__ == 'Constraint':
fh.write(" <td colspan=2>%s\n" % c.history)
fh.write(u" <td colspan=2>%s\n" % c.history)
else:
fh.write(" <td colspan=2>&nbsp;\n")
fh.write("</table>\n\n")
fh.write(u" <td colspan=2>&nbsp;\n")
fh.write(u"</table>\n\n")


def debug(indent=0, str=''):
Expand Down
2 changes: 1 addition & 1 deletion components/merging/sputlink/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def _debug_init_cycles_file(self):
def _debug_print_cycle(self, constraint=None):
if DEBUG:
fname = "cycle-%02d.html" % self.graph.cycle
self.cycles_fh.write("<p>Cycle %s - <b>%s</b></p>\n"
self.cycles_fh.write(u"<p>Cycle %s - <b>%s</b></p>\n"
% (self.graph.cycle, constraint))
graph_file = os.path.join(TTK_ROOT, 'data', 'tmp', fname)
self.graph.pp_html(filehandle=self.cycles_fh)
Expand Down
52 changes: 26 additions & 26 deletions components/merging/sputlink/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,31 +70,31 @@ def compose_rels(self, rel1, rel2):
def pp(self, filename):
"""Print an html table to filename."""
file = open(filename, 'w')
file.write("<html>\n")
file.write("<head>\n<style type=\"text/css\">\n<!--\n")
file.write("body { font-size: 14pt }\n")
file.write("table { font-size: 14pt }\n")
file.write("-->\n</style>\n</head>\n")
file.write("<body>\n\n")
file.write("<table cellpadding=3 cellspacing=0 border=1>\n")
file.write("\n<tr>\n\n")
file.write(" <td>&nbsp;\n\n")
file.write(u"<html>\n")
file.write(u"<head>\n<style type=\"text/css\">\n<!--\n")
file.write(u"body { font-size: 14pt }\n")
file.write(u"table { font-size: 14pt }\n")
file.write(u"-->\n</style>\n</head>\n")
file.write(u"<body>\n\n")
file.write(u"<table cellpadding=3 cellspacing=0 border=1>\n")
file.write(u"\n<tr>\n\n")
file.write(u" <td>&nbsp;\n\n")
rels = self.data.keys()
rels.sort()
for rel in rels:
rel = massage(rel)
file.write(" <td>%s\n" % rel)
file.write(u" <td>%s\n" % rel)
for r1 in rels:
file.write("\n\n<tr>\n\n")
file.write(u"\n\n<tr>\n\n")
header = massage(r1)
file.write(" <td>%s\n" % header)
file.write(u" <td>%s\n" % header)
for r2 in rels:
r = self.data[r1][r2]
if r is None:
r = ' '
r = massage(r)
file.write(" <td>%s\n" % r)
file.write("</table>\n</body>\n</html>\n\n")
file.write(u" <td>%s\n" % r)
file.write(u"</table>\n</body>\n</html>\n\n")


def massage(str):
Expand All @@ -107,15 +107,15 @@ def massage(str):


def html_graph_prefix(fh):
fh.write("<html>\n")
fh.write("<head>\n<style type=\"text/css\">\n<!--\n")
fh.write("body { font-size: 18pt }\n")
fh.write("table { font-size: 18pt; margin-left:20pt; }\n")
fh.write(".user { background-color: lightblue; }\n")
fh.write(".closure { background-color: pink; }\n")
fh.write(".user-inverted { background-color: lightyellow; }\n")
fh.write(".closure-inverted { background-color: lightyellow; }\n")
fh.write(".nocell { background-color: lightgrey; }\n")
fh.write(".cycle { font-weight: bold; font-size: 18pt }\n")
fh.write("-->\n</style>\n</head>\n")
fh.write("<body>\n\n")
fh.write(u"<html>\n")
fh.write(u"<head>\n<style type=\"text/css\">\n<!--\n")
fh.write(u"body { font-size: 18pt }\n")
fh.write(u"table { font-size: 18pt; margin-left:20pt; }\n")
fh.write(u".user { background-color: lightblue; }\n")
fh.write(u".closure { background-color: pink; }\n")
fh.write(u".user-inverted { background-color: lightyellow; }\n")
fh.write(u".closure-inverted { background-color: lightyellow; }\n")
fh.write(u".nocell { background-color: lightgrey; }\n")
fh.write(u".cycle { font-weight: bold; font-size: 18pt }\n")
fh.write(u"-->\n</style>\n</head>\n")
fh.write(u"<body>\n\n")
Loading

0 comments on commit 854baed

Please sign in to comment.