From 264862c67a669ab908c2c628c5de8fb4c07e7d18 Mon Sep 17 00:00:00 2001 From: Adriane Boyd Date: Mon, 22 Feb 2021 01:05:08 +0100 Subject: [PATCH] Fix Ukrainian lemmatizer init (#7127) Fix class variable and init for `UkrainianLemmatizer` so that it loads the `uk` dictionaries rather than having the parent `RussianLemmatizer` override with the `ru` settings. --- spacy/lang/ru/lemmatizer.py | 3 +-- spacy/lang/uk/lemmatizer.py | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/spacy/lang/ru/lemmatizer.py b/spacy/lang/ru/lemmatizer.py index b7a2fc8e4..e4689815e 100644 --- a/spacy/lang/ru/lemmatizer.py +++ b/spacy/lang/ru/lemmatizer.py @@ -23,8 +23,6 @@ class RussianLemmatizer(Lemmatizer): mode: str = "pymorphy2", overwrite: bool = False, ) -> None: - super().__init__(vocab, model, name, mode=mode, overwrite=overwrite) - try: from pymorphy2 import MorphAnalyzer except ImportError: @@ -34,6 +32,7 @@ class RussianLemmatizer(Lemmatizer): ) from None if RussianLemmatizer._morph is None: RussianLemmatizer._morph = MorphAnalyzer() + super().__init__(vocab, model, name, mode=mode, overwrite=overwrite) def pymorphy2_lemmatize(self, token: Token) -> List[str]: string = token.text diff --git a/spacy/lang/uk/lemmatizer.py b/spacy/lang/uk/lemmatizer.py index 56d9c75c0..0b4435a21 100644 --- a/spacy/lang/uk/lemmatizer.py +++ b/spacy/lang/uk/lemmatizer.py @@ -7,6 +7,8 @@ from ...vocab import Vocab class UkrainianLemmatizer(RussianLemmatizer): + _morph = None + def __init__( self, vocab: Vocab, @@ -16,7 +18,6 @@ class UkrainianLemmatizer(RussianLemmatizer): mode: str = "pymorphy2", overwrite: bool = False, ) -> None: - super().__init__(vocab, model, name, mode=mode, overwrite=overwrite) try: from pymorphy2 import MorphAnalyzer except ImportError: @@ -27,3 +28,4 @@ class UkrainianLemmatizer(RussianLemmatizer): ) from None if UkrainianLemmatizer._morph is None: UkrainianLemmatizer._morph = MorphAnalyzer(lang="uk") + super().__init__(vocab, model, name, mode=mode, overwrite=overwrite)