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)
| 410 | |
| 411 | |
| 412 | def 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 | |
| 439 | def set_lang_class(name: str, cls: Type["Language"]) -> None: |
searching dependent graphs…