Display warning when spacy.explain() finds no term (#10645)

* Display warning when spacy.explain() finds no term

* Updated warning message text
This commit is contained in:
Richard Hudson 2022-04-12 10:48:28 +02:00 committed by GitHub
parent d4196a62f1
commit 75fbbcdc18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -196,6 +196,9 @@ class Warnings(metaclass=ErrorsWithCodes):
"surprising to you, make sure the Doc was processed using a model "
"that supports span categorization, and check the `doc.spans[spans_key]` "
"property manually if necessary.")
W118 = ("Term '{term}' not found in glossary. It may however be explained in documentation "
"for the corpora used to train the language. Please check "
"`nlp.meta[\"sources\"]` for any relevant links.")
class Errors(metaclass=ErrorsWithCodes):

View File

@ -1,3 +1,7 @@
import warnings
from .errors import Warnings
def explain(term):
"""Get a description for a given POS tag, dependency label or entity type.
@ -11,6 +15,8 @@ def explain(term):
"""
if term in GLOSSARY:
return GLOSSARY[term]
else:
warnings.warn(Warnings.W118.format(term=term))
GLOSSARY = {