mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-27 02:16:32 +03:00
f4008bdb13
For the Russian and Ukrainian lemmatizers, restrict the `pymorphy2` requirement to the mode `pymorphy2` so that lookup or other lemmatizer modes can be loaded without installing `pymorphy2`.
33 lines
1023 B
Python
33 lines
1023 B
Python
from typing import Optional
|
|
|
|
from thinc.api import Model
|
|
|
|
from ..ru.lemmatizer import RussianLemmatizer
|
|
from ...vocab import Vocab
|
|
|
|
|
|
class UkrainianLemmatizer(RussianLemmatizer):
|
|
_morph = None
|
|
|
|
def __init__(
|
|
self,
|
|
vocab: Vocab,
|
|
model: Optional[Model],
|
|
name: str = "lemmatizer",
|
|
*,
|
|
mode: str = "pymorphy2",
|
|
overwrite: bool = False,
|
|
) -> None:
|
|
if mode == "pymorphy2":
|
|
try:
|
|
from pymorphy2 import MorphAnalyzer
|
|
except ImportError:
|
|
raise ImportError(
|
|
"The Ukrainian lemmatizer mode 'pymorphy2' requires the "
|
|
"pymorphy2 library and dictionaries. Install them with: "
|
|
"pip install pymorphy2 pymorphy2-dicts-uk"
|
|
) from None
|
|
if UkrainianLemmatizer._morph is None:
|
|
UkrainianLemmatizer._morph = MorphAnalyzer(lang="uk")
|
|
super().__init__(vocab, model, name, mode=mode, overwrite=overwrite)
|