mirror of
https://github.com/explosion/spaCy.git
synced 2025-08-07 13:44:55 +03:00
Don't throw an error if using displacy on an unset span key
This commit is contained in:
parent
f0d8309a28
commit
08e81c80e6
|
@ -228,7 +228,7 @@ def parse_spans(doc: Doc, options: Dict[str, Any] = {}) -> Dict[str, Any]:
|
||||||
"kb_id": span.kb_id_ if span.kb_id_ else "",
|
"kb_id": span.kb_id_ if span.kb_id_ else "",
|
||||||
"kb_url": kb_url_template.format(span.kb_id_) if kb_url_template else "#",
|
"kb_url": kb_url_template.format(span.kb_id_) if kb_url_template else "#",
|
||||||
}
|
}
|
||||||
for span in doc.spans[spans_key]
|
for span in doc.spans.get(spans_key, [])
|
||||||
]
|
]
|
||||||
tokens = [token.text for token in doc]
|
tokens = [token.text for token in doc]
|
||||||
|
|
||||||
|
|
|
@ -203,6 +203,16 @@ def test_displacy_parse_spans_different_spans_key(en_vocab):
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_displacy_parse_empty_spans_key(en_vocab):
|
||||||
|
"""Test that having an unset spans key doesn't raise an error"""
|
||||||
|
doc = Doc(en_vocab, words=["Welcome", "to", "the", "Bank", "of", "China"])
|
||||||
|
doc.spans["custom"] = [Span(doc, 3, 6, "BANK")]
|
||||||
|
with pytest.warns(UserWarning, match="W117"):
|
||||||
|
spans = displacy.parse_spans(doc)
|
||||||
|
|
||||||
|
assert isinstance(spans, dict)
|
||||||
|
|
||||||
|
|
||||||
def test_displacy_parse_ents(en_vocab):
|
def test_displacy_parse_ents(en_vocab):
|
||||||
"""Test that named entities on a Doc are converted into displaCy's format."""
|
"""Test that named entities on a Doc are converted into displaCy's format."""
|
||||||
doc = Doc(en_vocab, words=["But", "Google", "is", "starting", "from", "behind"])
|
doc = Doc(en_vocab, words=["But", "Google", "is", "starting", "from", "behind"])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user