Skip to content

Commit 3f628d7

Browse files
committed
fix: dictionary word lookup for party yoficated words, e.g. четырЕхзвЁздный, четырЁхзвЕздный
1 parent bd7c82f commit 3f628d7

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- [ ] feature: add lint option
1414
- [ ] feature: add replacement stats
1515

16+
### Fixed
17+
18+
- fix: dictionary word lookup for party yoficated words, e.g. `четырЕхзвЁздный`, `четырЁхзвЕздный`
19+
1620
## [0.1.0] — 2025-02-16
1721

1822
`md.language.yofication` package initial version

lib/md/language/yofication/_yofication.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ def __init__(self, dictionary: DictionaryType) -> None:
120120
self._dictionary[ye_word.lower()] = yo_word.lower()
121121

122122
def find(self, word: str) -> typing.Optional[str]:
123-
return self._dictionary.get(word, None)
123+
return self._dictionary.get(word.replace('ё', 'е'), None)
124124

125125
def has(self, word: str) -> bool:
126-
return word in self._dictionary
126+
return word.replace('ё', 'е') in self._dictionary
127127

128128

129129
class RegularExpressionYoficate(YoficateInterface):

tests/md/language/yofication/test_yofication.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,32 @@ def test_has(self) -> None:
2727
assert mapping_dictionary.has(word='трехмерный') is True
2828
assert mapping_dictionary.has(word='четырехзвездный') is False
2929

30+
def test_find_partly_yoficated(self) -> None:
31+
# arrange
32+
dictionary = {'четырехзвездный': 'четырёхзвёздный'}
33+
34+
# act
35+
mapping_dictionary = md.language.yofication.MappingDictionary(dictionary=dictionary)
36+
37+
# assert
38+
assert mapping_dictionary.find(word='четырёхзвёздный') == 'четырёхзвёздный'
39+
assert mapping_dictionary.find(word='четырехзвёздный') == 'четырёхзвёздный'
40+
assert mapping_dictionary.find(word='четырёхзвездный') == 'четырёхзвёздный'
41+
assert mapping_dictionary.find(word='четырехзвездный') == 'четырёхзвёздный'
42+
43+
def test_has_partly_yoficated(self) -> None:
44+
# arrange
45+
dictionary = {'четырехзвездный': 'четырёхзвёздный'}
46+
47+
# act
48+
mapping_dictionary = md.language.yofication.MappingDictionary(dictionary=dictionary)
49+
50+
# assert
51+
assert mapping_dictionary.has(word='четырёхзвёздный') is True
52+
assert mapping_dictionary.has(word='четырехзвёздный') is True
53+
assert mapping_dictionary.has(word='четырёхзвездный') is True
54+
assert mapping_dictionary.has(word='четырехзвездный') is True
55+
3056

3157
class TestRegularExpressionYoficate(unittest.TestCase):
3258
def test_word(self) -> None:

0 commit comments

Comments
 (0)