2021-08-10 16:13:39 +03:00
|
|
|
from typing import Optional, Callable
|
2020-07-22 14:42:59 +03:00
|
|
|
|
2020-08-07 16:27:13 +03:00
|
|
|
from thinc.api import Model
|
2020-07-22 14:42:59 +03:00
|
|
|
|
2020-08-07 16:27:13 +03:00
|
|
|
from ..ru.lemmatizer import RussianLemmatizer
|
2021-08-10 16:13:39 +03:00
|
|
|
from ...pipeline.lemmatizer import lemmatizer_score
|
2020-08-07 16:27:13 +03:00
|
|
|
from ...vocab import Vocab
|
|
|
|
|
|
|
|
|
|
|
|
class UkrainianLemmatizer(RussianLemmatizer):
|
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
vocab: Vocab,
|
|
|
|
model: Optional[Model],
|
|
|
|
name: str = "lemmatizer",
|
|
|
|
*,
|
|
|
|
mode: str = "pymorphy2",
|
2020-10-05 10:26:43 +03:00
|
|
|
overwrite: bool = False,
|
2021-08-10 16:13:39 +03:00
|
|
|
scorer: Optional[Callable] = lemmatizer_score,
|
2020-08-07 16:27:13 +03:00
|
|
|
) -> None:
|
2021-06-11 11:19:22 +03:00
|
|
|
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
|
2021-07-09 16:36:56 +03:00
|
|
|
if getattr(self, "_morph", None) is None:
|
|
|
|
self._morph = MorphAnalyzer(lang="uk")
|
2021-08-10 16:13:39 +03:00
|
|
|
super().__init__(vocab, model, name, mode=mode, overwrite=overwrite, scorer=scorer)
|