Skip to content

Commit

Permalink
chore(pre-commit.ci): auto fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Jun 17, 2024
1 parent b69a90d commit 83560f8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/mecab_text_cleaner/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ def to_reading(
reading_type: Literal["orth", "pron", "kana"] = "pron",
add_atype: bool = True,
add_blank_between_words: bool = True,
when_unknown: Literal["passthrough", "*", "unidecode"]
| Callable[[str], str] = "passthrough",
when_unknown: (
Literal["passthrough", "*", "unidecode"] | Callable[[str], str]
) = "passthrough",
tagger: fugashi.Tagger = _get_tagger(),
) -> str:
"""Convert text to reading.
Expand Down Expand Up @@ -212,7 +213,9 @@ def to_reading(

if reading in ("", "*", None):
# unknown reading
if not (word.feature.pos1 == "補助記号" and word.feature.pos2 == "一般"):
if not (
word.feature.pos1 == "補助記号" and word.feature.pos2 == "一般"
):
# known symbol
if add_blank_between_words:
res = res[:-1]
Expand Down
15 changes: 12 additions & 3 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ def test_simple():


def test_complex():
assert to_reading(" 1한. 人、武蔵 小杉に向かう。") == "1 한. ヒト=、 ム]サシ コスギ= ニ ムカウ=。"
assert (
to_reading(" 1한. 人、武蔵 小杉に向かう。")
== "1 한. ヒト=、 ム]サシ コスギ= ニ ムカウ=。"
)


def test_multiline():
assert to_reading(" 한空、雲。\n雨!(") == "한 ソ]ラ、 ク]モ。\nア]メ!("


def test_multiline_noatype():
assert to_reading(" 한空、雲。\n雨!(", add_atype=False) == "한 ソラ、 クモ。\nアメ!("
assert (
to_reading(" 한空、雲。\n雨!(", add_atype=False)
== "한 ソラ、 クモ。\nアメ!("
)


def test_multiline_noblank():
Expand All @@ -34,7 +40,10 @@ def test_multiline_unidecode():


def test_multiline_star():
assert to_reading(" 한空、雲。\n雨!(", when_unknown="*") == "* ソ]ラ、 ク]モ。\nア]メ!("
assert (
to_reading(" 한空、雲。\n雨!(", when_unknown="*")
== "* ソ]ラ、 ク]モ。\nア]メ!("
)


def test_multiline_custom():
Expand Down

0 comments on commit 83560f8

Please sign in to comment.