MCPcopy
hub / github.com/explosion/spaCy / get_lang_class

Function get_lang_class

spacy/util.py:412–436  ·  view source on GitHub ↗

Import and load a Language class. lang (str): Two-letter ISO 639-1 or three-letter ISO 639-3 language code, such as 'en' and 'eng'. RETURNS (Language): Language class.

(lang: str)

Source from the content-addressed store, hash-verified

410
411
412def get_lang_class(lang: str) -> Type["Language"]:
413 """Import and load a Language class.
414
415 lang (str): Two-letter ISO 639-1 or three-letter ISO 639-3 language code, such as 'en' and 'eng'.
416 RETURNS (Language): Language class.
417 """
418 # Check if language is registered / entry point is available
419 if lang in registry.languages:
420 return registry.languages.get(lang)
421 else:
422 # Find the language in the spacy.lang subpackage
423 try:
424 module = importlib.import_module(f".lang.{lang}", "spacy")
425 except ImportError as err:
426 # Find a matching language. For example, if the language 'eng' is
427 # requested, we can use language-matching to load `spacy.lang.en`.
428 match = find_matching_language(lang)
429
430 if match:
431 lang = match
432 module = importlib.import_module(f".lang.{lang}", "spacy")
433 else:
434 raise ImportError(Errors.E048.format(lang=lang, err=err)) from err
435 set_lang_class(lang, getattr(module, module.__all__[0])) # type: ignore[attr-defined]
436 return registry.languages.get(lang)
437
438
439def set_lang_class(name: str, cls: Type["Language"]) -> None:

Callers 15

tokenizerFunction · 0.90
af_tokenizerFunction · 0.90
am_tokenizerFunction · 0.90
ar_tokenizerFunction · 0.90
bg_tokenizerFunction · 0.90
bn_tokenizerFunction · 0.90
bo_tokenizerFunction · 0.90
ca_tokenizerFunction · 0.90
cs_tokenizerFunction · 0.90
da_tokenizerFunction · 0.90
de_tokenizerFunction · 0.90
de_vocabFunction · 0.90

Calls 3

find_matching_languageFunction · 0.85
set_lang_classFunction · 0.85
getMethod · 0.45

Tested by 15

tokenizerFunction · 0.72
af_tokenizerFunction · 0.72
am_tokenizerFunction · 0.72
ar_tokenizerFunction · 0.72
bg_tokenizerFunction · 0.72
bn_tokenizerFunction · 0.72
bo_tokenizerFunction · 0.72
ca_tokenizerFunction · 0.72
cs_tokenizerFunction · 0.72
da_tokenizerFunction · 0.72
de_tokenizerFunction · 0.72
de_vocabFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…