From f503817623627b0e7a8e7bdacdcda412fc9318c0 Mon Sep 17 00:00:00 2001 From: svlandeg Date: Thu, 2 Jul 2020 13:48:11 +0200 Subject: [PATCH] fix parsing entity links in new gold format --- spacy/errors.py | 2 -- spacy/gold/example.pyx | 16 +++------------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/spacy/errors.py b/spacy/errors.py index 66a3c61da..6e7ec49ae 100644 --- a/spacy/errors.py +++ b/spacy/errors.py @@ -556,8 +556,6 @@ class Errors(object): E979 = ("Cannot convert {type} to an Example object.") E980 = ("Each link annotation should refer to a dictionary with at most one " "identifier mapping to 1.0, and all others to 0.0.") - E981 = ("The offsets of the annotations for 'links' need to refer exactly " - "to the offsets of the 'entities' annotations.") E982 = ("The 'ent_iob' attribute of a Token should be an integer indexing " "into {values}, but found {value}.") E983 = ("Invalid key for '{dict}': {key}. Available keys: " diff --git a/spacy/gold/example.pyx b/spacy/gold/example.pyx index 5e36156a9..841b233c4 100644 --- a/spacy/gold/example.pyx +++ b/spacy/gold/example.pyx @@ -235,10 +235,7 @@ def _annot2array(vocab, tok_annot, doc_annot): if key == "entities": pass elif key == "links": - entities = doc_annot.get("entities", {}) - if not entities: - raise ValueError(Errors.E981) - ent_kb_ids = _parse_links(vocab, tok_annot["ORTH"], value, entities) + ent_kb_ids = _parse_links(vocab, tok_annot["ORTH"], tok_annot["SPACY"], value) tok_annot["ENT_KB_ID"] = ent_kb_ids elif key == "cats": pass @@ -381,18 +378,11 @@ def _parse_ner_tags(biluo_or_offsets, vocab, words, spaces): ent_types.append("") return ent_iobs, ent_types -def _parse_links(vocab, words, links, entities): - reference = Doc(vocab, words=words) +def _parse_links(vocab, words, spaces, links): + reference = Doc(vocab, words=words, spaces=spaces) starts = {token.idx: token.i for token in reference} ends = {token.idx + len(token): token.i for token in reference} ent_kb_ids = ["" for _ in reference] - entity_map = [(ent[0], ent[1]) for ent in entities] - - # links annotations need to refer 1-1 to entity annotations - throw error otherwise - for index, annot_dict in links.items(): - start_char, end_char = index - if (start_char, end_char) not in entity_map: - raise ValueError(Errors.E981) for index, annot_dict in links.items(): true_kb_ids = []