mirror of
https://github.com/explosion/spaCy.git
synced 2025-03-22 02:44:15 +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):
|
class RussianLemmatizer(Lemmatizer):
|
||||||
_morph = None
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -31,8 +30,8 @@ class RussianLemmatizer(Lemmatizer):
|
||||||
"The Russian lemmatizer mode 'pymorphy2' requires the "
|
"The Russian lemmatizer mode 'pymorphy2' requires the "
|
||||||
"pymorphy2 library. Install it with: pip install pymorphy2"
|
"pymorphy2 library. Install it with: pip install pymorphy2"
|
||||||
) from None
|
) from None
|
||||||
if RussianLemmatizer._morph is None:
|
if getattr(self, "_morph", None) is None:
|
||||||
RussianLemmatizer._morph = MorphAnalyzer()
|
self._morph = MorphAnalyzer()
|
||||||
super().__init__(vocab, model, name, mode=mode, overwrite=overwrite)
|
super().__init__(vocab, model, name, mode=mode, overwrite=overwrite)
|
||||||
|
|
||||||
def pymorphy2_lemmatize(self, token: Token) -> List[str]:
|
def pymorphy2_lemmatize(self, token: Token) -> List[str]:
|
||||||
|
|
|
@ -7,8 +7,6 @@ from ...vocab import Vocab
|
||||||
|
|
||||||
|
|
||||||
class UkrainianLemmatizer(RussianLemmatizer):
|
class UkrainianLemmatizer(RussianLemmatizer):
|
||||||
_morph = None
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
vocab: Vocab,
|
vocab: Vocab,
|
||||||
|
@ -27,6 +25,6 @@ class UkrainianLemmatizer(RussianLemmatizer):
|
||||||
"pymorphy2 library and dictionaries. Install them with: "
|
"pymorphy2 library and dictionaries. Install them with: "
|
||||||
"pip install pymorphy2 pymorphy2-dicts-uk"
|
"pip install pymorphy2 pymorphy2-dicts-uk"
|
||||||
) from None
|
) from None
|
||||||
if UkrainianLemmatizer._morph is None:
|
if getattr(self, "_morph", None) is None:
|
||||||
UkrainianLemmatizer._morph = MorphAnalyzer(lang="uk")
|
self._morph = MorphAnalyzer(lang="uk")
|
||||||
super().__init__(vocab, model, name, mode=mode, overwrite=overwrite)
|
super().__init__(vocab, model, name, mode=mode, overwrite=overwrite)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user