Skip to content

Commit

Permalink
Improved error reporting and span type checking
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusklang committed Jun 12, 2020
1 parent 6dfbbf8 commit 9cd2b35
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions py/docria/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ class Text:
def __init__(self, name, text):
self.name = name
self.text = text
self.spantype = DataType(DataTypeEnum.SPAN, context=self.name)
self.spantype = DataTypeTextspan(DataTypeEnum.SPAN, context=self.name)

def __str__(self):
"""Convert to string"""
Expand Down Expand Up @@ -1349,8 +1349,12 @@ def validate(self, node: "Node")->bool:
"field '%s' in layer '%s' for node %s" \
% (fieldtype.options["layer"], field, self.name, repr(node))
elif fieldtype.typename == DataTypeEnum.SPAN:
assert isinstance(fieldvalue, TextSpan), \
"The span field '%s' was not set to a TextSpan, but: '%s'" % \
(field, repr(fieldvalue))

assert fieldvalue.text.name == fieldtype.options["context"], \
"Textspan does not match expceted context %s found %s: " \
"Textspan does not match expected context %s found %s: " \
"field '%s' in layer '%s' for node %s" % \
(fieldtype.options["context"], fieldvalue.text.name, field, self.name, repr(node))
else:
Expand Down

0 comments on commit 9cd2b35

Please sign in to comment.