def _create_equiv(ann_obj, projectconf, mods, origin, target, type, attributes, old_type, old_target): # due to legacy representation choices for Equivs (i.e. no # unique ID), support for attributes for Equivs would need # some extra work. Getting the easy non-Equiv case first. if attributes is not None: Messager.warning( '_create_equiv: attributes for Equiv annotation not supported yet, please tell the devs if you need this feature (mention "issue #799").' ) attributes = None ann = None if old_type is None: # new annotation # sanity assert old_target is None, '_create_equiv: incoherent args: old_type is None, old_target is not None (client/protocol error?)' ann = EquivAnnotation( type, [unicode(origin.id), unicode(target.id)], '') ann_obj.add_annotation(ann) mods.addition(ann) # TODO: attributes assert attributes is None, "INTERNAL ERROR" # see above else: # change to existing Equiv annotation. Other than the no-op # case, this remains TODO. assert projectconf.is_equiv_type( old_type ), 'attempting to change equiv relation to non-equiv relation, operation not supported' # sanity assert old_target is not None, '_create_equiv: incoherent args: old_type is not None, old_target is None (client/protocol error?)' if old_type != type: Messager.warning( '_create_equiv: equiv type change not supported yet, please tell the devs if you need this feature (mention "issue #798").' ) if old_target != target.id: Messager.warning( '_create_equiv: equiv reselect not supported yet, please tell the devs if you need this feature (mention "issue #797").' ) # TODO: attributes assert attributes is None, "INTERNAL ERROR" # see above return ann
def coref(xml, start_id=1): soup = _soup(xml) token_by_ids = _token_by_ids(soup) docs_e = soup.findall('document') assert len(docs_e) == 1 docs_e = docs_e[0] # Despite the name, this element contains conferences (note the "s") corefs_e = docs_e.findall('coreference') if not corefs_e: # No coreferences to process raise StopIteration assert len(corefs_e) == 1 corefs_e = corefs_e[0] curr_id = start_id for coref_e in corefs_e: if corefs_e.tag != 'coreference': # To be on the safe side continue # This tag is now a full corference chain chain = [] for mention_e in coref_e.getiterator('mention'): # Note: There is a "representative" attribute signalling the most # "suitable" mention, we are currently not using this # Note: We don't use the head information for each mention sentence_id = int(mention_e.find('sentence').text) start_tok_id = int(mention_e.find('start').text) end_tok_id = int(mention_e.find('end').text) - 1 mention_id = 'T%s' % (curr_id, ) chain.append(mention_id) curr_id += 1 yield TextBoundAnnotation( ((token_by_ids[sentence_id][start_tok_id].start, token_by_ids[sentence_id][end_tok_id].end), ), mention_id, 'Mention', '') yield EquivAnnotation('Coreference', chain, '')