diff --git a/spacy/tokens/span.pyx b/spacy/tokens/span.pyx index c41bb1cbe..1a22d6cc1 100644 --- a/spacy/tokens/span.pyx +++ b/spacy/tokens/span.pyx @@ -102,15 +102,15 @@ cdef class Span: self.doc = doc if isinstance(label, str): label = doc.vocab.strings.add(label) + elif label not in doc.vocab.strings: + raise ValueError(Errors.E084.format(name="label", value=label)) if isinstance(kb_id, str): kb_id = doc.vocab.strings.add(kb_id) + elif kb_id not in doc.vocab.strings: + raise ValueError(Errors.E084.format(name="kb_id", value=kb_id)) if isinstance(span_id, str): span_id = doc.vocab.strings.add(span_id) - if label not in doc.vocab.strings: - raise ValueError(Errors.E084.format(name="label", value=label)) - if kb_id not in doc.vocab.strings: - raise ValueError(Errors.E084.format(name="kb_id", value=kb_id)) - if span_id not in doc.vocab.strings: + elif span_id not in doc.vocab.strings: raise ValueError(Errors.E084.format(name="span_id", value=span_id)) start_char = doc[start].idx if start < doc.length else len(doc.text)