Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tab annotations #1175

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
60 changes: 30 additions & 30 deletions server/src/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def json(self, json_dic):
# TODO: more specific error?
json_dic['exception'] = 'annotationCollectionNotFound'
return json_dic


class EventWithoutTriggerError(ProtocolError):
def __init__(self, event):
Expand All @@ -115,7 +115,7 @@ def __str__(self):
def json(self, json_dic):
json_dic['exception'] = 'eventWithoutTrigger'
return json_dic


class EventWithNonTriggerError(ProtocolError):
def __init__(self, event, non_trigger):
Expand Down Expand Up @@ -242,7 +242,7 @@ def is_valid_id(id):

try:
# currently accepting any ID that can be split.
# TODO: consider further constraints
# TODO: consider further constraints
__split_annotation_id(id)[1]
return True
except InvalidIdError:
Expand All @@ -258,7 +258,7 @@ class Annotations(object):

def get_document(self):
return self._document

def _select_input_files(self, document):
"""
Given a document name (path), returns a list of the names of
Expand Down Expand Up @@ -305,14 +305,14 @@ def _select_input_files(self, document):
self._read_only = True
else:
# Our last shot, we go for as many partial files as possible
input_files = [sugg_path for sugg_path in
input_files = [sugg_path for sugg_path in
(document + '.' + suff
for suff in PARTIAL_ANN_FILE_SUFF)
if isfile(sugg_path)]
self._read_only = True

return input_files

#TODO: DOC!
def __init__(self, document, read_only=False):
# this decides which parsing function is invoked by annotation
Expand Down Expand Up @@ -349,7 +349,7 @@ def __init__(self, document, read_only=False):
# Maximum id number used for each id prefix, to speed up id generation
#XXX: This is effectively broken by the introduction of id suffixes
self._max_id_num_by_prefix = defaultdict(lambda : 1)
# Annotation by id, not includid non-ided annotations
# Annotation by id, not includid non-ided annotations
self._ann_by_id = {}
###

Expand All @@ -372,7 +372,7 @@ def __init__(self, document, read_only=False):
# Finally, parse the given annotation file
try:
self._parse_ann_file()

# Sanity checking that can only be done post-parse
self._sanity()
except UnicodeDecodeError:
Expand Down Expand Up @@ -447,10 +447,10 @@ def _sanity(self):
if conflict_ann_ids:
referencer = self.get_ann_by_id(list(conflict_ann_ids)[0])
raise TriggerReferenceError(tr_ann, referencer)

def get_events(self):
return (a for a in self if isinstance(a, EventAnnotation))

def get_attributes(self):
return (a for a in self if isinstance(a, AttributeAnnotation))

Expand All @@ -471,7 +471,7 @@ def get_entities(self):
triggers = [t for t in self.get_triggers()]
return (a for a in self if (isinstance(a, TextBoundAnnotation) and
not a in triggers))

def get_oneline_comments(self):
#XXX: The status exception is for the document status protocol
# which is yet to be formalised
Expand Down Expand Up @@ -513,7 +513,7 @@ def add_annotation(self, ann, read=False):
for ent in merge_cand.entities:
if ent in eq_ann.entities:
for m_ent in merge_cand.entities:
if m_ent not in eq_ann.entities:
if m_ent not in eq_ann.entities:
eq_ann.entities.append(m_ent)
# Don't try to delete ann since it never was added
if merge_cand != ann:
Expand Down Expand Up @@ -583,7 +583,7 @@ def del_annotation(self, ann, tracker=None):
soft_deps, hard_deps = other_ann.get_deps()
if unicode(ann.id) in soft_deps | hard_deps:
ann_deps.append(other_ann)

# If all depending are AttributeAnnotations or EquivAnnotations,
# delete all modifiers recursively (without confirmation) and remove
# the annotation id from the equivs (and remove the equiv if there is
Expand Down Expand Up @@ -630,7 +630,7 @@ def del_annotation(self, ann, tracker=None):
# covered above.
assert False, "INTERNAL ERROR"
ann_deps = []

if ann_deps:
raise DependingAnnotationDeleteError(ann, ann_deps)

Expand Down Expand Up @@ -659,7 +659,7 @@ def _atomic_del_annotation(self, ann):
# Update the modification time
from time import time
self.ann_mtime = time()

def get_ann_by_id(self, id):
#TODO: DOC
try:
Expand Down Expand Up @@ -709,7 +709,7 @@ def _parse_attribute_annotation(self, id, data, data_tail, input_file_path):
if match is None:
raise IdedAnnotationLineSyntaxError(id, self.ann_line,
self.ann_line_num + 1, input_file_path)

_type, target = match.groups()
value = True
else:
Expand Down Expand Up @@ -755,7 +755,7 @@ def _parse_relation_annotation(self, id, data, data_tail, input_file_path):
except ValueError:
# cannot have a relation with just a type (contra event)
raise IdedAnnotationLineSyntaxError(id, self.ann_line, self.ann_line_num+1, input_file_path)

try:
args = [tuple(arg.split(':')) for arg in type_tail.split()]
except ValueError:
Expand Down Expand Up @@ -830,7 +830,7 @@ def _parse_normalization_annotation(self, _id, data, data_tail, input_file_path)
if d != data:
data = d
break

match = re_match(r'(\S+) (\S+) (\S+?):(\S+)', data)
if match is None:
raise IdedAnnotationLineSyntaxError(_id, self.ann_line, self.ann_line_num + 1, input_file_path)
Expand All @@ -844,7 +844,7 @@ def _parse_comment_annotation(self, _id, data, data_tail, input_file_path):
except ValueError:
raise IdedAnnotationLineSyntaxError(_id, self.ann_line, self.ann_line_num+1, input_file_path)
return OnelineCommentAnnotation(target, _id, _type, data_tail, source_id=input_file_path)

def _parse_ann_file(self):
self.ann_line_num = -1
for input_file_path in self._input_files:
Expand Down Expand Up @@ -935,7 +935,7 @@ def __len__(self):
def __enter__(self):
# No need to do any handling here, the constructor handles that
return self

def __exit__(self, type, value, traceback):
#self._file_input.close()
if not self._read_only:
Expand All @@ -944,7 +944,7 @@ def __exit__(self, type, value, traceback):
# We are hitting the disk a lot more than we should here, what we
# should have is a modification flag in the object but we can't
# due to how we change the annotations.

out_str = unicode(self)
with open_textfile(self._input_files[0], 'r') as old_ann_file:
old_str = old_ann_file.read()
Expand All @@ -955,7 +955,7 @@ def __exit__(self, type, value, traceback):
return

from config import WORK_DIR

# Protect the write so we don't corrupt the file
with file_lock(path_join(WORK_DIR,
str(hash(self._input_files[0].replace('/', '_')))
Expand Down Expand Up @@ -1025,7 +1025,7 @@ def __init__(self, document, read_only=False):
textfile_path = document[:len(document) - len(file_ext)]

self._document_text = self._read_document_text(textfile_path)

Annotations.__init__(self, document, read_only)

def _parse_textbound_annotation(self, id, data, data_tail, input_file_path):
Expand Down Expand Up @@ -1055,7 +1055,7 @@ def _parse_textbound_annotation(self, id, data, data_tail, input_file_path):
spanlen = sum([end-start for start, end in spans]) + (len(spans)-1)*len(DISCONT_SEP)

# Require tail to be either empty or to begin with the text
# corresponding to the catenation of the start:end spans.
# corresponding to the catenation of the start:end spans.
# If the tail is empty, force a fill with the corresponding text.
if data_tail.strip() == '' and spanlen > 0:
Messager.error(u"Text-bound annotation missing text (expected format 'ID\\tTYPE START END\\tTEXT'). Filling from reference text. NOTE: This changes annotations on disk unless read-only.")
Expand Down Expand Up @@ -1125,7 +1125,7 @@ def __str__(self):

def __repr__(self):
return u'%s("%s")' % (unicode(self.__class__), unicode(self))

def get_deps(self):
return (set(), set())

Expand Down Expand Up @@ -1280,7 +1280,7 @@ class EquivAnnotation(TypedAnnotation):
other annotations (normally TextBoundAnnotation) to be equivalent.

Represented in standoff as

*\tTYPE ID1 ID2 [...]

Where "*" is the literal asterisk character.
Expand Down Expand Up @@ -1323,7 +1323,7 @@ def __init__(self, target, id, type, tail, value, source_id=None):
IdedAnnotation.__init__(self, id, type, tail, source_id=source_id)
self.target = target
self.value = value

def __str__(self):
return u'%s\t%s %s%s%s' % (
self.id,
Expand Down Expand Up @@ -1377,7 +1377,7 @@ class OnelineCommentAnnotation(IdedAnnotation):
def __init__(self, target, id, type, tail, source_id=None):
IdedAnnotation.__init__(self, id, type, tail, source_id=source_id)
self.target = target

def __str__(self):
return u'%s\t%s %s%s' % (
self.id,
Expand Down Expand Up @@ -1405,7 +1405,7 @@ class does not assume ability to access text; use
TextBoundAnnotationWithText for that.

Represented in standoff as

ID\tTYPE START END

Where START and END are positive integer offsets identifying the
Expand Down Expand Up @@ -1567,7 +1567,7 @@ def __str__(self):
self.arg2,
self.tail
)

def get_deps(self):
soft_deps, hard_deps = IdedAnnotation.get_deps(self)
hard_deps.add(self.arg1)
Expand Down