Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip diacritics for pymorphy lemmatizer #12554

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion spacy/lang/ru/lemmatizer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from typing import Callable, Dict, List, Optional, Tuple

from thinc.api import Model
Expand All @@ -7,6 +8,7 @@
from ...symbols import POS
from ...tokens import Token
from ...vocab import Vocab
from ..char_classes import COMBINING_DIACRITICS

PUNCT_RULES = {"«": '"', "»": '"'}

Expand Down Expand Up @@ -51,9 +53,10 @@ def __init__(
super().__init__(
vocab, model, name, mode=mode, overwrite=overwrite, scorer=scorer
)
self._diacritics_re = re.compile(f"[{COMBINING_DIACRITICS}]")

def _pymorphy_lemmatize(self, token: Token) -> List[str]:
string = token.text
string = self._diacritics_re.sub("", token.text)
univ_pos = token.pos_
morphology = token.morph.to_dict()
if univ_pos == "PUNCT":
Expand Down
2 changes: 2 additions & 0 deletions spacy/tests/lang/ru/test_lemmatizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def test_ru_lemmatizer_works_with_different_pos_homonyms(
("гвоздики", "Gender=Masc", "гвоздик"),
("вина", "Gender=Fem", "вина"),
("вина", "Gender=Neut", "вино"),
("жену", "Gender=Fem", "жена"),
("жену́", "Gender=Fem", "жена"),
],
)
def test_ru_lemmatizer_works_with_noun_homonyms(ru_lemmatizer, text, morph, lemma):
Expand Down