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