Skip to content

Commit

Permalink
Fix black, lint errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
jzohrab committed May 17, 2024
1 parent 96d5a96 commit 6d24af2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion plugins/lute-mandarin/lute_mandarin_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def get_reading(self, text: str):
# Flatten the list of lists to a single list
pinyin_list = (item for sublist in pinyin_list for item in sublist)
# Join the pinyin into a single string
ret = ' '.join(pinyin_list)
ret = " ".join(pinyin_list)
if ret in ("", text):
return None
return ret
2 changes: 1 addition & 1 deletion plugins/lute-mandarin/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def _get_test_language():
"""
thisdir = os.path.dirname(os.path.realpath(__file__))
definition_file = os.path.join(thisdir, "..", "definition.yaml")
with open(definition_file, "r", encoding="utf-8") as df:
with open(definition_file, "r", encoding="utf-8") as df:
d = yaml.safe_load(df)
lang = Language.from_dict(d)
return lang
Expand Down
17 changes: 9 additions & 8 deletions plugins/lute-mandarin/tests/test_MandarinParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@
MandarinParser tests.
"""

# pylint: disable=wrong-import-order
from lute.models.term import Term
from lute.parse.base import ParsedToken

from lute_mandarin_parser.parser import MandarinParser



def test_token_count(mandarin_chinese):
"""
token_count checks.
"""
cases = [("我", 1), ("运气", 1), ("你说", 2), ("我不相信", 3), ("我冒了严寒 ,回到相隔二千馀里,别了二十馀年的故乡去。", 21)]
cases = [
("我", 1),
("运气", 1),
("你说", 2),
("我不相信", 3),
("我冒了严寒 ,回到相隔二千馀里,别了二十馀年的故乡去。", 21),
]
for text, expected_count in cases:
t = Term(mandarin_chinese, text)
assert t.token_count == expected_count, text
Expand All @@ -39,7 +45,6 @@ def test_end_of_sentence_stored_in_parsed_tokens(mandarin_chinese):
"""
s = "你好。吃饭了吗?现在是2024年。"


expected = [
("你好", True),
("。", False, True),
Expand Down Expand Up @@ -67,11 +72,7 @@ def test_readings():
for c in no_reading:
assert p.get_reading(c) is None, c

cases = [
("你好", "nǐ hǎo"),
("欢迎", "huān yíng"),
("中国", "zhōng guó")
]
cases = [("你好", "nǐ hǎo"), ("欢迎", "huān yíng"), ("中国", "zhōng guó")]

for c in cases:
assert p.get_reading(c[0]) == c[1], c[0]

0 comments on commit 6d24af2

Please sign in to comment.