mirror of
https://github.com/explosion/spaCy.git
synced 2024-11-10 19:57:17 +03:00
Fix ru/uk lemmatizer mp with spawn (#8657)
Use an instance variable instead a class variable for the morphological analzyer so that multiprocessing with spawn is possible.
This commit is contained in:
parent
b8e720fdb9
commit
d8805a1073
|
@ -12,7 +12,6 @@ PUNCT_RULES = {"«": '"', "»": '"'}
|
|||
|
||||
|
||||
class RussianLemmatizer(Lemmatizer):
|
||||
_morph = None
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
@ -31,8 +30,8 @@ class RussianLemmatizer(Lemmatizer):
|
|||
"The Russian lemmatizer mode 'pymorphy2' requires the "
|
||||
"pymorphy2 library. Install it with: pip install pymorphy2"
|
||||
) from None
|
||||
if RussianLemmatizer._morph is None:
|
||||
RussianLemmatizer._morph = MorphAnalyzer()
|
||||
if getattr(self, "_morph", None) is None:
|
||||
self._morph = MorphAnalyzer()
|
||||
super().__init__(vocab, model, name, mode=mode, overwrite=overwrite)
|
||||
|
||||
def pymorphy2_lemmatize(self, token: Token) -> List[str]:
|
||||
|
|
|
@ -7,8 +7,6 @@ from ...vocab import Vocab
|
|||
|
||||
|
||||
class UkrainianLemmatizer(RussianLemmatizer):
|
||||
_morph = None
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
vocab: Vocab,
|
||||
|
@ -27,6 +25,6 @@ class UkrainianLemmatizer(RussianLemmatizer):
|
|||
"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")
|
||||
if getattr(self, "_morph", None) is None:
|
||||
self._morph = MorphAnalyzer(lang="uk")
|
||||
super().__init__(vocab, model, name, mode=mode, overwrite=overwrite)
|
||||
|
|
Loading…
Reference in New Issue
Block a user