From 5dbf70677fcef18e7eba60be14bb9f5942320f66 Mon Sep 17 00:00:00 2001 From: Adriane Boyd Date: Mon, 3 Apr 2023 13:14:44 +0200 Subject: [PATCH] Refactor to if/else --- spacy/tokens/span.pyx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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)