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

疑問文の仕様変更反映 #272 #273

Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 2 additions & 6 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,7 @@ def accent_phrases(
"""
if is_kana:
try:
accent_phrases, interrogative_accent_phrase_marks = parse_kana(
text, enable_interrogative
)
accent_phrases = parse_kana(text, enable_interrogative)
except ParseKanaError as err:
raise HTTPException(
status_code=400,
Expand All @@ -196,9 +194,7 @@ def accent_phrases(
accent_phrases=accent_phrases, speaker_id=speaker
)

return adjust_interrogative_accent_phrases(
accent_phrases, interrogative_accent_phrase_marks, enable_interrogative
)
return adjust_interrogative_accent_phrases(accent_phrases)
else:
return engine.create_accent_phrases(
text,
Expand Down
146 changes: 105 additions & 41 deletions test/test_kana_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


def parse_kana(text: str) -> List[AccentPhrase]:
accent_phrases, _ = kana_parser.parse_kana(text, False)
accent_phrases = kana_parser.parse_kana(text, False)
return accent_phrases


Expand Down Expand Up @@ -61,17 +61,9 @@ def _interrogative_accent_phrase_marks_base(
text: str,
enable_interrogative: bool,
expected_accent_phrases: List[AccentPhrase],
expected_interrogative_accent_phrase_marks: List[bool],
):
accent_phrases, interrogative_accent_phrase_marks = kana_parser.parse_kana(
text, enable_interrogative
)
self.assertEqual(len(accent_phrases), len(interrogative_accent_phrase_marks))
accent_phrases = kana_parser.parse_kana(text, enable_interrogative)
self.assertEqual(expected_accent_phrases, accent_phrases)
self.assertEqual(
interrogative_accent_phrase_marks,
expected_interrogative_accent_phrase_marks,
)

def test_interrogative_accent_phrase_marks(self):
def a_slash_a_accent_phrases():
Expand Down Expand Up @@ -111,15 +103,13 @@ def a_slash_a_accent_phrases():
text="ア'/ア'",
enable_interrogative=False,
expected_accent_phrases=expected_accent_phrases,
expected_interrogative_accent_phrase_marks=[False, False],
)

expected_accent_phrases = a_slash_a_accent_phrases()
self._interrogative_accent_phrase_marks_base(
text="ア'/ア'",
enable_interrogative=True,
expected_accent_phrases=expected_accent_phrases,
expected_interrogative_accent_phrase_marks=[False, False],
)

def a_jp_comma_a_accent_phrases():
Expand Down Expand Up @@ -166,15 +156,13 @@ def a_jp_comma_a_accent_phrases():
text="ア'、ア'",
enable_interrogative=False,
expected_accent_phrases=expected_accent_phrases,
expected_interrogative_accent_phrase_marks=[False, False],
)

expected_accent_phrases = a_jp_comma_a_accent_phrases()
self._interrogative_accent_phrase_marks_base(
text="ア'、ア'",
enable_interrogative=True,
expected_accent_phrases=expected_accent_phrases,
expected_interrogative_accent_phrase_marks=[False, False],
)

def a_slash_a_slash_a_slash_a_slash_a_accent_phrases():
Expand Down Expand Up @@ -256,26 +244,12 @@ def a_slash_a_slash_a_slash_a_slash_a_accent_phrases():
text="ア'/ア'/ア'/ア'/ア'",
enable_interrogative=False,
expected_accent_phrases=expected_accent_phrases,
expected_interrogative_accent_phrase_marks=[
False,
False,
False,
False,
False,
],
)
expected_accent_phrases = a_slash_a_slash_a_slash_a_slash_a_accent_phrases()
self._interrogative_accent_phrase_marks_base(
text="ア'/ア'/ア'/ア'/ア'",
enable_interrogative=True,
expected_accent_phrases=expected_accent_phrases,
expected_interrogative_accent_phrase_marks=[
False,
False,
False,
False,
False,
],
)

def su_accent_phrases():
Expand All @@ -301,14 +275,12 @@ def su_accent_phrases():
text="ス'",
enable_interrogative=False,
expected_accent_phrases=expected_accent_phrases,
expected_interrogative_accent_phrase_marks=[False],
)
expected_accent_phrases = su_accent_phrases()
self._interrogative_accent_phrase_marks_base(
text="ス'",
enable_interrogative=True,
expected_accent_phrases=expected_accent_phrases,
expected_interrogative_accent_phrase_marks=[False],
)

def under_score_su_accent_phrases():
Expand All @@ -334,15 +306,13 @@ def under_score_su_accent_phrases():
text="_ス'",
enable_interrogative=False,
expected_accent_phrases=expected_accent_phrases,
expected_interrogative_accent_phrase_marks=[False],
)

expected_accent_phrases = under_score_su_accent_phrases()
self._interrogative_accent_phrase_marks_base(
text="_ス'",
enable_interrogative=True,
expected_accent_phrases=expected_accent_phrases,
expected_interrogative_accent_phrase_marks=[False],
)

def gye_accent_phrases():
Expand All @@ -368,15 +338,13 @@ def gye_accent_phrases():
text="ギェ'",
enable_interrogative=False,
expected_accent_phrases=expected_accent_phrases,
expected_interrogative_accent_phrase_marks=[False],
)

expected_accent_phrases = gye_accent_phrases()
self._interrogative_accent_phrase_marks_base(
text="ギェ'",
enable_interrogative=True,
expected_accent_phrases=expected_accent_phrases,
expected_interrogative_accent_phrase_marks=[False],
)

def gye_gye_gye_accent_phrases():
Expand Down Expand Up @@ -437,15 +405,13 @@ def gye_gye_gye_accent_phrases():
text="ギェ'、ギェ'/ギェ'",
enable_interrogative=False,
expected_accent_phrases=expected_accent_phrases,
expected_interrogative_accent_phrase_marks=[False, False, False],
)

expected_accent_phrases = gye_gye_gye_accent_phrases()
self._interrogative_accent_phrase_marks_base(
text="ギェ'、ギェ'/ギェ'",
enable_interrogative=True,
expected_accent_phrases=expected_accent_phrases,
expected_interrogative_accent_phrase_marks=[False, False, False],
)

def a_question_mark_accent_phrases():
Expand All @@ -471,11 +437,11 @@ def a_question_mark_accent_phrases():
text="ア'?",
enable_interrogative=False,
expected_accent_phrases=expected_accent_phrases,
expected_interrogative_accent_phrase_marks=[False],
)

expected_accent_phrases = a_question_mark_accent_phrases()
expected_accent_phrases[0].moras.append(
expected_accent_phrases[-1].is_interrogative = True
expected_accent_phrases[-1].moras.append(
Mora(
text="ア",
consonant=None,
Expand All @@ -489,7 +455,6 @@ def a_question_mark_accent_phrases():
text="ア'?",
enable_interrogative=True,
expected_accent_phrases=expected_accent_phrases,
expected_interrogative_accent_phrase_marks=[True],
)

def gye_gye_gye_question_mark_accent_phrases():
Expand Down Expand Up @@ -550,10 +515,10 @@ def gye_gye_gye_question_mark_accent_phrases():
text="ギェ'、ギェ'/ギェ'?",
enable_interrogative=False,
expected_accent_phrases=expected_accent_phrases,
expected_interrogative_accent_phrase_marks=[False, False, False],
)

expected_accent_phrases = gye_gye_gye_question_mark_accent_phrases()
expected_accent_phrases[-1].is_interrogative = True
expected_accent_phrases[-1].moras.append(
Mora(
text="エ",
Expand All @@ -568,7 +533,6 @@ def gye_gye_gye_question_mark_accent_phrases():
text="ギェ'、ギェ'/ギェ'?",
enable_interrogative=True,
expected_accent_phrases=expected_accent_phrases,
expected_interrogative_accent_phrase_marks=[False, False, True],
)


Expand Down Expand Up @@ -601,3 +565,103 @@ def test_exceptions(self):
with self.assertRaises(ParseKanaError) as err:
kana_parser.parse_kana("ア?ア'", True)
self.assertEqual(err.exception.errcode, ParseKanaErrorCode.UNKNOWN_TEXT)


class TestCreateKana(TestCase):
def test_create_kana_interrogative(self):
def koreha_arimasuka_accent_phrases():
return [
AccentPhrase(
moras=[
Mora(
text="コ",
consonant="k",
consonant_length=0,
vowel="o",
vowel_length=0,
pitch=0,
),
Mora(
text="レ",
consonant="r",
consonant_length=0,
vowel="e",
vowel_length=0,
pitch=0,
),
Mora(
text="ワ",
consonant="w",
consonant_length=0,
vowel="a",
vowel_length=0,
pitch=0,
),
],
accent=3,
pause_mora=None,
is_interrogative=False,
),
AccentPhrase(
moras=[
Mora(
text="ア",
consonant=None,
consonant_length=None,
vowel="a",
vowel_length=0,
pitch=0,
),
Mora(
text="リ",
consonant="r",
consonant_length=0,
vowel="i",
vowel_length=0,
pitch=0,
),
Mora(
text="マ",
consonant="m",
consonant_length=0,
vowel="a",
vowel_length=0,
pitch=0,
),
Mora(
text="ス",
consonant="s",
consonant_length=0,
vowel="U",
vowel_length=0,
pitch=0,
),
Mora(
text="カ",
consonant="k",
consonant_length=0,
vowel="a",
vowel_length=0,
pitch=0,
),
Mora(
text="ア",
consonant=None,
consonant_length=None,
vowel="a",
vowel_length=0,
pitch=0,
),
],
accent=3,
pause_mora=None,
is_interrogative=False,
),
]

accent_phrases = koreha_arimasuka_accent_phrases()
self.assertEqual(create_kana(accent_phrases), "コレワ'/アリマ'_スカア")

accent_phrases = koreha_arimasuka_accent_phrases()
accent_phrases[-1].is_interrogative = True
self.assertEqual(create_kana(accent_phrases), "コレワ'/アリマ'_スカ?")
Loading