Tidy up and auto-format

This commit is contained in:
Ines Montani 2019-10-28 12:36:23 +01:00
parent f0ec7bcb79
commit 92018b9cd4
2 changed files with 9 additions and 8 deletions

View File

@ -527,6 +527,7 @@ class Errors(object):
"attributes are connected anyways): {attr} -> {solution}") "attributes are connected anyways): {attr} -> {solution}")
E185 = ("Received invalid attribute in component attribute declaration: " E185 = ("Received invalid attribute in component attribute declaration: "
"{obj}.{attr}\nAttribute '{attr}' does not exist on {obj}.") "{obj}.{attr}\nAttribute '{attr}' does not exist on {obj}.")
E186 = ("'{tok_a}' and '{tok_b}' are different texts.")
@add_codes @add_codes
@ -559,6 +560,10 @@ class MatchPatternError(ValueError):
ValueError.__init__(self, msg) ValueError.__init__(self, msg)
class AlignmentError(ValueError):
pass
class ModelsWarning(UserWarning): class ModelsWarning(UserWarning):
pass pass

View File

@ -13,7 +13,7 @@ import srsly
from .syntax import nonproj from .syntax import nonproj
from .tokens import Doc, Span from .tokens import Doc, Span
from .errors import Errors from .errors import Errors, AlignmentError
from .compat import path2str from .compat import path2str
from . import util from . import util
from .util import minibatch, itershuffle from .util import minibatch, itershuffle
@ -86,10 +86,6 @@ def _normalize_for_alignment(tokens):
return output return output
class AlignmentError(ValueError):
pass
def align(tokens_a, tokens_b): def align(tokens_a, tokens_b):
"""Calculate alignment tables between two tokenizations. """Calculate alignment tables between two tokenizations.
@ -152,7 +148,7 @@ def align(tokens_a, tokens_b):
offset_a += len(b) offset_a += len(b)
else: else:
assert "".join(tokens_a) != "".join(tokens_b) assert "".join(tokens_a) != "".join(tokens_b)
raise AlignmentError(f"{tokens_a} and {tokens_b} are different texts.") raise AlignmentError(Errors.E186.format(tok_a=tokens_a, tok_b=tokens_b))
return cost, a2b, b2a, a2b_multi, b2a_multi return cost, a2b, b2a, a2b_multi, b2a_multi