mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-27 10:26:35 +03:00
54e8e3c208
* Update pymorphy2 error messages for Russian and Ukrainian * Add pymorphy2 to pex * Update spacy-pkuseg version for pex
30 lines
917 B
Python
30 lines
917 B
Python
from typing import Optional
|
|
|
|
from thinc.api import Model
|
|
|
|
from ..ru.lemmatizer import RussianLemmatizer
|
|
from ...vocab import Vocab
|
|
|
|
|
|
class UkrainianLemmatizer(RussianLemmatizer):
|
|
def __init__(
|
|
self,
|
|
vocab: Vocab,
|
|
model: Optional[Model],
|
|
name: str = "lemmatizer",
|
|
*,
|
|
mode: str = "pymorphy2",
|
|
overwrite: bool = False,
|
|
) -> None:
|
|
super().__init__(vocab, model, name, mode=mode, overwrite=overwrite)
|
|
try:
|
|
from pymorphy2 import MorphAnalyzer
|
|
except ImportError:
|
|
raise ImportError(
|
|
"The Ukrainian lemmatizer requires the pymorphy2 library and "
|
|
"dictionaries: try to fix it with "
|
|
'"pip install pymorphy2 pymorphy2-dicts-uk"'
|
|
) from None
|
|
if UkrainianLemmatizer._morph is None:
|
|
UkrainianLemmatizer._morph = MorphAnalyzer(lang="uk")
|