Skip to content

Commit

Permalink
Fix case support
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Aug 3, 2024
1 parent 2c9478c commit c3e1904
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
6 changes: 5 additions & 1 deletion custom_components/morph_numbers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ def words_after_number(self, number: int, text: str) -> list[str]:
words = []

for word in text.split(" "):
if w := self.parse(word).make_agree_with_number(number):
w: Parse = self.parse(word)
grammemes = w.tag.numeral_agreement_grammemes(number)
if grammemes == {"sing", "accs"}:
grammemes = {"sing", w.tag.case}
if w := w.inflect(grammemes):
words.append(w.word)

return words
Expand Down
22 changes: 20 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ def test_integrations():
)

assert (
morph.number_with_custom_text(2, ["грамм", "грамма", "граммов"])
== "два грамма"
morph.number_with_custom_text(2, ["грамм", "грамма", "граммов"]) == "два грамма"
)


Expand Down Expand Up @@ -151,3 +150,22 @@ def test_float():
morph.number_with_text(22.2, "яркость")
== "двадцать две целых и две десятых яркости"
)


def test_case():
# Кто? Что?
assert morph.number_with_text(1, "муниципальный") == "один муниципальный"
# Кого? Чего?
assert morph.number_with_text(1, "муниципального") == "одного муниципального"
# Кому? Чему?
assert morph.number_with_text(1, "муниципальному") == "одному муниципальному"
# Кого? Что?
assert morph.number_with_text(1, "муниципального") == "одного муниципального"
# Кем? Чем?
assert morph.number_with_text(1, "муниципальным") == "одним муниципальным"
# О ком? О чём?
assert morph.number_with_text(1, "муниципальном") == "одном муниципальном"

assert morph.number_with_text(2, "муниципальном") == "два муниципальных"
assert morph.number_with_text(5, "муниципальном") == "пять муниципальных"
assert morph.number_with_text(21, "муниципальном") == "двадцать одном муниципальном"

0 comments on commit c3e1904

Please sign in to comment.