From 2081a3718e4cddd14842146e842faae5b217b76e Mon Sep 17 00:00:00 2001 From: Eu-Bin KIM Date: Tue, 21 Jun 2022 16:35:31 +0100 Subject: [PATCH] [#82] functional stylers with proper tests --- explore/explore_fetch_environs.py | 5 + explore/explore_khaiii.py | 3 +- explore/explore_politely_multiple_stylers.py | 2 +- main_demo.py | 38 +- main_test.py | 576 +++++++++---------- politely/__init__.py | 15 +- politely/fetchers.py | 11 + politely/stylers.py | 71 +-- 8 files changed, 364 insertions(+), 357 deletions(-) create mode 100644 explore/explore_fetch_environs.py diff --git a/explore/explore_fetch_environs.py b/explore/explore_fetch_environs.py new file mode 100644 index 0000000..4db3c21 --- /dev/null +++ b/explore/explore_fetch_environs.py @@ -0,0 +1,5 @@ +from politely import ENVIRONS +from politely import LISTENERS + +print(ENVIRONS) +print(LISTENERS) diff --git a/explore/explore_khaiii.py b/explore/explore_khaiii.py index e026c80..60b2897 100644 --- a/explore/explore_khaiii.py +++ b/explore/explore_khaiii.py @@ -48,10 +48,11 @@ def main(): print(token) for sent in sents: - for token in analyser.analyze(sent): + for token in analyser._analyze(sent): print("=====") print(token) + """ # 굉장히 빠르고 정확하다! 띄어쓰기를 훼손하지도 않고... 심플하고... 정확히 내가 바라던 것인 것 같다. konlpy, kiwi에 걸쳐... 여기에 종착하게 되는 것인가? diff --git a/explore/explore_politely_multiple_stylers.py b/explore/explore_politely_multiple_stylers.py index 068473a..05fc502 100644 --- a/explore/explore_politely_multiple_stylers.py +++ b/explore/explore_politely_multiple_stylers.py @@ -6,5 +6,5 @@ def main(): styler("hi", 1) -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/main_demo.py b/main_demo.py index 2776cc8..97babdb 100644 --- a/main_demo.py +++ b/main_demo.py @@ -1,4 +1,4 @@ -from politely import Styler +from politely import style SENTS = [ # ㅂ 불규칙 @@ -27,27 +27,17 @@ "그는 전설이에요", ] -styler = Styler() - -def main(): - # first way of using it - politeness is not determined - for sent in SENTS: - listener = "friends and junior" - environ = "formal" - styled = styler(sent, listener, environ) - print(sent, "->", styled) - print(styler.logs.honorifics) - print(styler.logs.conjugations) - - # the other way of using it - politeness is determined - print("--------") - for sent in SENTS: - ban = styler(sent, 1) - jon = styler(sent, 2) - formal = styler(sent, 3) - print(sent, "->", ban, "|", jon, "|", formal) - - -if __name__ == "__main__": - main() +# first way of using it - politeness is not determined +for sent in SENTS: + listener = "friends and junior" + environ = "formal" + styled = style(sent, listener, environ) + print(sent, "->", styled) +# the other way of using it - politeness is determined +print("----------------------------------------------") +for sent in SENTS: + ban = style(sent, 1) + jon = style(sent, 2) + formal = style(sent, 3) + print(sent, "->", ban, "|", jon, "|", formal) diff --git a/main_test.py b/main_test.py index 887bede..f9cf427 100644 --- a/main_test.py +++ b/main_test.py @@ -1,558 +1,554 @@ -from politely import Styler +from politely import style +from politely.stylers import _preprocess # noqa import pytest -@pytest.fixture(scope="session") -def styler(): - return Styler() - - -def test_preprocess(styler): +def test_preprocess(): sent = "이것은 예시 문장이다" - styler.preprocess(sent) - assert "이것은 예시 문장이다.", styler.out + out = _preprocess(sent) + assert "이것은 예시 문장이다.", out sent = "이것은 예시 문장이다." - styler.preprocess(sent) - assert "이것은 예시 문장이다.", styler.out + out = _preprocess(sent) + assert "이것은 예시 문장이다.", out -def test_preprocess_trailing_spaces(styler): +def test_preprocess_trailing_spaces(): sent = "이것은 예시 문장이다 " - styler.preprocess(sent) - assert "이것은 예시 문장이다.", styler.out + out = _preprocess(sent) + assert "이것은 예시 문장이다.", out sent = "이것은 예시 문장이다. " - styler.preprocess(sent) - assert "이것은 예시 문장이다.", styler.out + out = _preprocess(sent) + assert "이것은 예시 문장이다.", out -def test_honorify_ra(styler): +def test_honorify_ra(): """ 종결어미 -라 """ sent = "최선을 다하라." - assert "최선을 다하라.", styler(sent, 1) - assert "최선을 다하세요.", styler(sent, 2) - assert "최선을 다합시다.", styler(sent, 3) + assert "최선을 다하라.", style(sent, 1) + assert "최선을 다하세요.", style(sent, 2) + assert "최선을 다합시다.", style(sent, 3) -def test_honorify_ja(styler): +def test_honorify_ja(): """ 종결어미 -자 """ sent = "자 이제 먹자." - assert "자 이제 먹자.", styler(sent, 1) - assert "자 이제 먹어요.", styler(sent, 2) - assert "자 이제 먹읍시다.", styler(sent, 3) + assert "자 이제 먹자.", style(sent, 1) + assert "자 이제 먹어요.", style(sent, 2) + assert "자 이제 먹읍시다.", style(sent, 3) -def test_honorify_nieun_dae(styler): +def test_honorify_nieun_dae(): """ 종결어미 ㄴ대 """ sent = "밥먹고 누우면 안 된대." - assert "밥먹고 누우면 안 된대.", styler(sent, 1) - assert "밥먹고 누우면 안 된대요.", styler(sent, 2) - assert "밥먹고 누우면 안 된답니다.", styler(sent, 3) + assert "밥먹고 누우면 안 된대.", style(sent, 1) + assert "밥먹고 누우면 안 된대요.", style(sent, 2) + assert "밥먹고 누우면 안 된답니다.", style(sent, 3) -def test_honorify_nieun_dae_yo(styler): +def test_honorify_nieun_dae_yo(): """ 종결어미 ㄴ대요 """ sent = "밥먹고 누우면 안 된대요." - assert "밥먹고 누우면 안 된대.", styler(sent, 1) - assert "밥먹고 누우면 안 된대요.", styler(sent, 2) - assert "밥먹고 누우면 안 된답니다.", styler(sent, 3) + assert "밥먹고 누우면 안 된대.", style(sent, 1) + assert "밥먹고 누우면 안 된대요.", style(sent, 2) + assert "밥먹고 누우면 안 된답니다.", style(sent, 3) -def test_honorify_gae(styler): +def test_honorify_gae(): sent = "회의를 시작할게." - assert "회의를 시작할게.", styler(sent, 1) - assert "회의를 시작할게요.", styler(sent, 2) - assert "회의를 시작하겠습니다.", styler(sent, 3) + assert "회의를 시작할게.", style(sent, 1) + assert "회의를 시작할게요.", style(sent, 2) + assert "회의를 시작하겠습니다.", style(sent, 3) -def test_honorify_eo(styler): +def test_honorify_eo(): """ 종결어미 -어 """ sent = "그 일은 내가 처리했어." - assert "그 일은 내가 처리했어.", styler(sent, 1) - assert "그 일은 제가 처리했어요.", styler(sent, 2) - assert "그 일은 제가 처리했습니다.", styler(sent, 3) + assert "그 일은 내가 처리했어.", style(sent, 1) + assert "그 일은 제가 처리했어요.", style(sent, 2) + assert "그 일은 제가 처리했습니다.", style(sent, 3) -def test_honorify_yo(styler): +def test_honorify_yo(): """ 종결어미 -요 """ sent = "제 패션을 함부로 비꼬지마요" - assert "내 패션을 함부로 비꼬지마.", styler(sent, 1) - assert "제 패션을 함부로 비꼬지마요.", styler(sent, 2) - assert "제 패션을 함부로 비꼬지마십시오.", styler(sent, 3) + assert "내 패션을 함부로 비꼬지마.", style(sent, 1) + assert "제 패션을 함부로 비꼬지마요.", style(sent, 2) + assert "제 패션을 함부로 비꼬지마십시오.", style(sent, 3) -def test_honorify_ge_yo(styler): +def test_honorify_ge_yo(): """ 게 + 종결어미 -요 """ sent = "회의를 시작할게요." - assert "회의를 시작할게.", styler(sent, 1) - assert "회의를 시작할게요.", styler(sent, 2) - assert "회의를 시작하겠습니다.", styler(sent, 3) + assert "회의를 시작할게.", style(sent, 1) + assert "회의를 시작할게요.", style(sent, 2) + assert "회의를 시작하겠습니다.", style(sent, 3) -def test_honorify_yi_ya(styler): +def test_honorify_yi_ya(): """ 이+야 """ sent = "그 일은 내 담당이야." - assert "그 일은 내 담당이야.", styler(sent, 1) - assert "그 일은 제 담당이에요.", styler(sent, 2) - assert "그 일은 제 담당입니다.", styler(sent, 3) + assert "그 일은 내 담당이야.", style(sent, 1) + assert "그 일은 제 담당이에요.", style(sent, 2) + assert "그 일은 제 담당입니다.", style(sent, 3) -def test_honorify_se_yo(styler): +def test_honorify_se_yo(): """ 세+요 """ # 이미 규칙으로 존재하는 -세요 때문에 얘는 달라져야함 sent = "최선을 다하세요." - assert "최선을 다해.", styler(sent, 1) - assert "최선을 다하세요.", styler(sent, 2) - assert "최선을 다하십시오.", styler(sent, 3) + assert "최선을 다해.", style(sent, 1) + assert "최선을 다하세요.", style(sent, 2) + assert "최선을 다하십시오.", style(sent, 3) -def test_honorify_yi_eyo(styler): +def test_honorify_yi_eyo(): """ 이 + 에요 """ sent = "그 일은 제 담당이에요." - assert "그 일은 내 담당이야.", styler(sent, 1) - assert "그 일은 제 담당이에요.", styler(sent, 2) - assert "그 일은 제 담당입니다.", styler(sent, 3) + assert "그 일은 내 담당이야.", style(sent, 1) + assert "그 일은 제 담당이에요.", style(sent, 2) + assert "그 일은 제 담당입니다.", style(sent, 3) -def test_honorify_eu_yo_1(styler): +def test_honorify_eu_yo_1(): """ 종결어미 -어요 (1) """ sent = "자 이제 먹어요." - assert "자 이제 먹어.", styler(sent, 1) - assert "자 이제 먹어요.", styler(sent, 2) - assert "자 이제 먹습니다.", styler(sent, 3) + assert "자 이제 먹어.", style(sent, 1) + assert "자 이제 먹어요.", style(sent, 2) + assert "자 이제 먹습니다.", style(sent, 3) -def test_honorify_eu_yo_2(styler): +def test_honorify_eu_yo_2(): """ 종결어미 -어요 (2) """ sent = "그 일은 제가 처리했어요." - assert "그 일은 내가 처리했어.", styler(sent, 1) - assert "그 일은 제가 처리했어요.", styler(sent, 2) - assert "그 일은 제가 처리했습니다.", styler(sent, 3) + assert "그 일은 내가 처리했어.", style(sent, 1) + assert "그 일은 제가 처리했어요.", style(sent, 2) + assert "그 일은 제가 처리했습니다.", style(sent, 3) -def test_honorify_bo_ayo(styler): +def test_honorify_bo_ayo(): """ 보 + 종결어미 -아요 """ sent = "좀만 더 버텨봐요" - assert "좀만 더 버텨봐.", styler(sent, 1) - assert "좀만 더 버텨봐요.", styler(sent, 2) - assert "좀만 더 버텨봅시다.", styler(sent, 3) + assert "좀만 더 버텨봐.", style(sent, 1) + assert "좀만 더 버텨봐요.", style(sent, 2) + assert "좀만 더 버텨봅시다.", style(sent, 3) -def test_honorify_ma(styler): +def test_honorify_ma(): sent = "내 패션을 함부로 비꼬지마" - assert "내 패션을 함부로 비꼬지마.", styler(sent, 1) - assert "제 패션을 함부로 비꼬지마요.", styler(sent, 2) - assert "제 패션을 함부로 비꼬지마십시오.", styler(sent, 3) + assert "내 패션을 함부로 비꼬지마.", style(sent, 1) + assert "제 패션을 함부로 비꼬지마요.", style(sent, 2) + assert "제 패션을 함부로 비꼬지마십시오.", style(sent, 3) -def test_honorify_bo_a(styler): +def test_honorify_bo_a(): sent = "좀만 더 버텨봐" - assert "좀만 더 버텨봐.", styler(sent, 1) - assert "좀만 더 버텨봐요.", styler(sent, 2) - assert "좀만 더 버텨봅시다.", styler(sent, 3) + assert "좀만 더 버텨봐.", style(sent, 1) + assert "좀만 더 버텨봐요.", style(sent, 2) + assert "좀만 더 버텨봅시다.", style(sent, 3) -def test_honorify_dae_q(styler): +def test_honorify_dae_q(): sent = "걔 오늘 기분이 왜 이렇게 좋대?" - assert "걔 오늘 기분이 왜 이렇게 좋대?", styler(sent, 1) - assert "걔 오늘 기분이 왜 이렇게 좋대요?", styler(sent, 2) - assert "걔 오늘 기분이 왜 이렇게 좋습니까?", styler(sent, 3) + assert "걔 오늘 기분이 왜 이렇게 좋대?", style(sent, 1) + assert "걔 오늘 기분이 왜 이렇게 좋대요?", style(sent, 2) + assert "걔 오늘 기분이 왜 이렇게 좋습니까?", style(sent, 3) -def test_honorify_dae_yo_q(styler): +def test_honorify_dae_yo_q(): sent = "걔 오늘 기분이 왜 이렇게 좋대요?" - assert "걔 오늘 기분이 왜 이렇게 좋대?", styler(sent, 1) - assert "걔 오늘 기분이 왜 이렇게 좋대요?", styler(sent, 2) - assert "걔 오늘 기분이 왜 이렇게 좋습니까?", styler(sent, 3) + assert "걔 오늘 기분이 왜 이렇게 좋대?", style(sent, 1) + assert "걔 오늘 기분이 왜 이렇게 좋대요?", style(sent, 2) + assert "걔 오늘 기분이 왜 이렇게 좋습니까?", style(sent, 3) -def test_honorify_eo_q(styler): +def test_honorify_eo_q(): """ 어? """ # 했어? sent = "어제 공부는 마무리 했어?" - assert "어제 공부는 마무리 했어?", styler(sent, 1) - assert "어제 공부는 마무리 했어요?", styler(sent, 2) - assert "어제 공부는 마무리 했습니까?", styler(sent, 3) + assert "어제 공부는 마무리 했어?", style(sent, 1) + assert "어제 공부는 마무리 했어요?", style(sent, 2) + assert "어제 공부는 마무리 했습니까?", style(sent, 3) -def test_honorify_eo_yo_q_1(styler): +def test_honorify_eo_yo_q_1(): """ 의문형 종결어미 -어요? (1) """ sent = "어제 공부는 마무리 했어요?" - assert "어제 공부는 마무리 했어?", styler(sent, 1) - assert "어제 공부는 마무리 했어요?", styler(sent, 2) - assert "어제 공부는 마무리 했습니까?", styler(sent, 3) + assert "어제 공부는 마무리 했어?", style(sent, 1) + assert "어제 공부는 마무리 했어요?", style(sent, 2) + assert "어제 공부는 마무리 했습니까?", style(sent, 3) -def test_honorify_eo_yo_q_2(styler): +def test_honorify_eo_yo_q_2(): """ 의문형 종결어미 -어요 (2) """ sent = "어디 가세요?" - assert "어디 가셔?", styler(sent, 1) - assert "어디 가세요?", styler(sent, 2) - assert "어디 가십니까?", styler(sent, 3) + assert "어디 가셔?", style(sent, 1) + assert "어디 가세요?", style(sent, 2) + assert "어디 가십니까?", style(sent, 3) -def test_honorify_si_eo_q(styler): +def test_honorify_si_eo_q(): """ 시 + 의문형 종결어미 -어? """ # 가셔? (가시어?) sent = "어디 가셔?" - assert "어디 가셔?", styler(sent, 1) - assert "어디 가셔요?", styler(sent, 2) - assert "어디 가십니까?", styler(sent, 3) + assert "어디 가셔?", style(sent, 1) + assert "어디 가셔요?", style(sent, 2) + assert "어디 가십니까?", style(sent, 3) -def test_honorify_ddae_q(styler): +def test_honorify_ddae_q(): sent = "순서를 바꾸는건 어때?" - assert "순서를 바꾸는건 어때?", styler(sent, 1) - assert "순서를 바꾸는건 어때요?", styler(sent, 2) - assert "순서를 바꾸는건 어떻습니까?", styler(sent, 3) + assert "순서를 바꾸는건 어때?", style(sent, 1) + assert "순서를 바꾸는건 어때요?", style(sent, 2) + assert "순서를 바꾸는건 어떻습니까?", style(sent, 3) sent = "순서를 바꾸는건 어때요?" - assert "순서를 바꾸는건 어때?", styler(sent, 1) - assert "순서를 바꾸는건 어때요?", styler(sent, 2) - assert "순서를 바꾸는건 어떻습니까?", styler(sent, 3) + assert "순서를 바꾸는건 어때?", style(sent, 1) + assert "순서를 바꾸는건 어때요?", style(sent, 2) + assert "순서를 바꾸는건 어떻습니까?", style(sent, 3) # --- tests by irregular conjugations --- # -def test_conjugate_ah_1(styler): +def test_conjugate_ah_1(): """ 동모음 탈락 걸어가어요 (x) 걸어가요 (o) """ sent = "가까우니까 걸어가자." - assert "가까우니까 걸어가자.", styler(sent, 1) - assert "가까우니까 걸어가요.", styler(sent, 2) - assert "가까우니까 걸어갑시다.", styler(sent, 3) + assert "가까우니까 걸어가자.", style(sent, 1) + assert "가까우니까 걸어가요.", style(sent, 2) + assert "가까우니까 걸어갑시다.", style(sent, 3) -def test_conjugate_ah_2(styler): +def test_conjugate_ah_2(): """ 동모음 탈락 떠나어요 (x) 떠나요 (o) """ sent = "자, 떠나자. 동해바다로." - assert "자, 떠나자. 동해바다로.", styler(sent, 1) - assert "자, 떠나요. 동해바다로.", styler(sent, 2) - assert "자, 떠납시다. 동해바다로.", styler(sent, 3) + assert "자, 떠나자. 동해바다로.", style(sent, 1) + assert "자, 떠나요. 동해바다로.", style(sent, 2) + assert "자, 떠납시다. 동해바다로.", style(sent, 3) -def test_conjugate_ah_3(styler): +def test_conjugate_ah_3(): """ 동모음 탈락 (3) """ sent = "자, 떠나요. 동해바다로." - assert "자, 떠나. 동해바다로.", styler(sent, 1) - assert "자, 떠나요. 동해바다로.", styler(sent, 2) - assert "자, 떠납니다. 동해바다로.", styler(sent, 3) + assert "자, 떠나. 동해바다로.", style(sent, 1) + assert "자, 떠나요. 동해바다로.", style(sent, 2) + assert "자, 떠납니다. 동해바다로.", style(sent, 3) -def test_conjugate_digud(styler): +def test_conjugate_digud(): """ ㄷ 불규칙 """ sent = "나는 오늘 그 사실을 깨달았다." - assert "나는 오늘 그 사실을 깨달았다.", styler(sent, 1) - assert "저는 오늘 그 사실을 깨달았어요.", styler(sent, 2) - assert "저는 오늘 그 사실을 깨달았습니다.", styler(sent, 3) + assert "나는 오늘 그 사실을 깨달았다.", style(sent, 1) + assert "저는 오늘 그 사실을 깨달았어요.", style(sent, 2) + assert "저는 오늘 그 사실을 깨달았습니다.", style(sent, 3) sent = "저는 오늘 그 사실을 깨달았어요." - assert "나는 오늘 그 사실을 깨달았어.", styler(sent, 1) - assert "저는 오늘 그 사실을 깨달았어요.", styler(sent, 2) - assert "저는 오늘 그 사실을 깨달았습니다.", styler(sent, 3) + assert "나는 오늘 그 사실을 깨달았어.", style(sent, 1) + assert "저는 오늘 그 사실을 깨달았어요.", style(sent, 2) + assert "저는 오늘 그 사실을 깨달았습니다.", style(sent, 3) -def test_conjugate_ru(styler): +def test_conjugate_ru(): """ 르 불규칙 e.g. 들르 + 어 -> 들러 e.g. 이르 + 어 -> 일러 """ sent = "나는 그 상점을 들렀다." - assert "나는 그 상점을 들렀다.", styler(sent, 1) - assert "저는 그 상점을 들렀어요.", styler(sent, 2) - assert "저는 그 상점을 들렀습니다.", styler(sent, 3) + assert "나는 그 상점을 들렀다.", style(sent, 1) + assert "저는 그 상점을 들렀어요.", style(sent, 2) + assert "저는 그 상점을 들렀습니다.", style(sent, 3) sent = "저는 그 상점을 들렀어요." - assert "나는 그 상점을 들렀어.", styler(sent, 1) - assert "저는 그 상점을 들렀어요.", styler(sent, 2) - assert "저는 그 상점을 들렀습니다.", styler(sent, 3) + assert "나는 그 상점을 들렀어.", style(sent, 1) + assert "저는 그 상점을 들렀어요.", style(sent, 2) + assert "저는 그 상점을 들렀습니다.", style(sent, 3) sent = "지금은 좀 일러." - assert "지금은 좀 일러.", styler(sent, 1) - assert "지금은 좀 일러요.", styler(sent, 2) - assert "지금은 좀 이릅니다.", styler(sent, 3) + assert "지금은 좀 일러.", style(sent, 1) + assert "지금은 좀 일러요.", style(sent, 2) + assert "지금은 좀 이릅니다.", style(sent, 3) -def test_conjugate_bieup_1(styler): +def test_conjugate_bieup_1(): """ ㅂ 불규칙 (모음 조화 o) """ sent = "모래가 참 고와." - assert "모래가 참 고와.", styler(sent, 1) - assert "모래가 참 고와요.", styler(sent, 2) - assert "모래가 참 곱습니다.", styler(sent, 3) + assert "모래가 참 고와.", style(sent, 1) + assert "모래가 참 고와요.", style(sent, 2) + assert "모래가 참 곱습니다.", style(sent, 3) sent = "모래가 참 고와요." - assert "모래가 참 고와.", styler(sent, 1) - assert "모래가 참 고와요.", styler(sent, 2) - assert "모래가 참 곱습니다.", styler(sent, 3) + assert "모래가 참 고와.", style(sent, 1) + assert "모래가 참 고와요.", style(sent, 2) + assert "모래가 참 곱습니다.", style(sent, 3) -def test_conjugate_bieup_2(styler): +def test_conjugate_bieup_2(): """ ㅂ 불규칙 (모음 조화 x) """ sent = "참 아름답다." - assert "참 아름답다.", styler(sent, 1) - assert "참 아름다워요.", styler(sent, 2) - assert "참 아름답습니다.", styler(sent, 3) + assert "참 아름답다.", style(sent, 1) + assert "참 아름다워요.", style(sent, 2) + assert "참 아름답습니다.", style(sent, 3) sent = "참 아름다워요." - assert "참 아름다워.", styler(sent, 1) - assert "참 아름다워요.", styler(sent, 2) - assert "참 아름답습니다.", styler(sent, 3) + assert "참 아름다워.", style(sent, 1) + assert "참 아름다워요.", style(sent, 2) + assert "참 아름답습니다.", style(sent, 3) -def test_conjugate_bieup_3(styler): +def test_conjugate_bieup_3(): """ 더워의 경우. """ sent = "오늘이 어제보다 더워." - assert "오늘이 어제보다 더워.", styler(sent, 1) - assert "오늘이 어제보다 더워요.", styler(sent, 2) - assert "오늘이 어제보다 덥습니다.", styler(sent, 3) + assert "오늘이 어제보다 더워.", style(sent, 1) + assert "오늘이 어제보다 더워요.", style(sent, 2) + assert "오늘이 어제보다 덥습니다.", style(sent, 3) sent = "오늘이 어제보다 더워요." - assert "오늘이 어제보다 더워.", styler(sent, 1) - assert "오늘이 어제보다 더워요.", styler(sent, 2) - assert "오늘이 어제보다 덥습니다.", styler(sent, 3) + assert "오늘이 어제보다 더워.", style(sent, 1) + assert "오늘이 어제보다 더워요.", style(sent, 2) + assert "오늘이 어제보다 덥습니다.", style(sent, 3) -def test_conjugate_bieup_4(styler): +def test_conjugate_bieup_4(): """ 가려워의 경우. """ sent = "너무 가려워." - assert "너무 가려워.", styler(sent, 1) - assert "너무 가려워요.", styler(sent, 2) - assert "너무 가렵습니다.", styler(sent, 3) + assert "너무 가려워.", style(sent, 1) + assert "너무 가려워요.", style(sent, 2) + assert "너무 가렵습니다.", style(sent, 3) sent = "너무 가려워요." - assert "너무 가려워.", styler(sent, 1) - assert "너무 가려워요.", styler(sent, 2) - assert "너무 가렵습니다.", styler(sent, 3) + assert "너무 가려워.", style(sent, 1) + assert "너무 가려워요.", style(sent, 2) + assert "너무 가렵습니다.", style(sent, 3) -def test_conjugate_r_cho_is_bieup(styler): +def test_conjugate_r_cho_is_bieup(): """ ㅂ니다 """ sent = "이름은 김유빈이야." - assert "이름은 김유빈입니다.", styler(sent, 3) + assert "이름은 김유빈입니다.", style(sent, 3) sent = "이름은 김유빈이에요." - assert "이름은 김유빈입니다.", styler(sent, 3) + assert "이름은 김유빈입니다.", style(sent, 3) -def test_conjugate_siot(styler): +def test_conjugate_siot(): """ ㅅ 불규칙 """ sent = "거기에 선을 그어." - assert "거기에 선을 그어.", styler(sent, 1) - assert "거기에 선을 그어요.", styler(sent, 2) - assert "거기에 선을 긋습니다.", styler(sent, 3) + assert "거기에 선을 그어.", style(sent, 1) + assert "거기에 선을 그어요.", style(sent, 2) + assert "거기에 선을 긋습니다.", style(sent, 3) sent = "거기에 선을 그어요." - assert "거기에 선을 그어.", styler(sent, 1) - assert "거기에 선을 그어요.", styler(sent, 2) - assert "거기에 선을 긋습니다.", styler(sent, 3) + assert "거기에 선을 그어.", style(sent, 1) + assert "거기에 선을 그어요.", style(sent, 2) + assert "거기에 선을 긋습니다.", style(sent, 3) -def test_conjugate_siot_exception(styler): +def test_conjugate_siot_exception(): """ ㅅ 불규칙 (벗어는 예외) """ sent = "한국의 목욕탕에서는 옷을 벗어." - assert "한국의 목욕탕에서는 옷을 벗어.", styler(sent, 1) - assert "한국의 목욕탕에서는 옷을 벗어요.", styler(sent, 2) - assert "한국의 목욕탕에서는 옷을 벗습니다.", styler(sent, 3) + assert "한국의 목욕탕에서는 옷을 벗어.", style(sent, 1) + assert "한국의 목욕탕에서는 옷을 벗어요.", style(sent, 2) + assert "한국의 목욕탕에서는 옷을 벗습니다.", style(sent, 3) sent = "한국의 목욕탕에서는 옷을 벗어요." - assert "한국의 목욕탕에서는 옷을 벗어.", styler(sent, 1) - assert "한국의 목욕탕에서는 옷을 벗어요.", styler(sent, 2) - assert "한국의 목욕탕에서는 옷을 벗습니다.", styler(sent, 3) + assert "한국의 목욕탕에서는 옷을 벗어.", style(sent, 1) + assert "한국의 목욕탕에서는 옷을 벗어요.", style(sent, 2) + assert "한국의 목욕탕에서는 옷을 벗습니다.", style(sent, 3) -def test_conjugate_u(styler): +def test_conjugate_u(): """ 우 불규칙 """ sent = "이 포스팅 퍼갈게." - assert "이 포스팅 퍼갈게.", styler(sent, 1) - assert "이 포스팅 퍼갈게요.", styler(sent, 2) - assert "이 포스팅 퍼가겠습니다.", styler(sent, 3) + assert "이 포스팅 퍼갈게.", style(sent, 1) + assert "이 포스팅 퍼갈게요.", style(sent, 2) + assert "이 포스팅 퍼가겠습니다.", style(sent, 3) sent = "이 포스팅 퍼갈게요." - assert "이 포스팅 퍼갈게.", styler(sent, 1) - assert "이 포스팅 퍼갈게요.", styler(sent, 2) - assert "이 포스팅 퍼가겠습니다.", styler(sent, 3) + assert "이 포스팅 퍼갈게.", style(sent, 1) + assert "이 포스팅 퍼갈게요.", style(sent, 2) + assert "이 포스팅 퍼가겠습니다.", style(sent, 3) -def test_conjugate_u_jup(styler): +def test_conjugate_u_jup(): """ 우 불규칙 - 줍은 예외 """ sent = "쓰레기를 줍자." - assert "쓰레기를 줍자.", styler(sent, 1) - assert "쓰레기를 주워요.", styler(sent, 2) - assert "쓰레기를 주웁시다.", styler(sent, 3) + assert "쓰레기를 줍자.", style(sent, 1) + assert "쓰레기를 주워요.", style(sent, 2) + assert "쓰레기를 주웁시다.", style(sent, 3) sent = "쓰레기를 주워요." - assert "쓰레기를 주워.", styler(sent, 1) - assert "쓰레기를 주워요.", styler(sent, 2) - assert "쓰레기를 줍습니다.", styler(sent, 3) + assert "쓰레기를 주워.", style(sent, 1) + assert "쓰레기를 주워요.", style(sent, 2) + assert "쓰레기를 줍습니다.", style(sent, 3) -def test_conjugate_o(styler): +def test_conjugate_o(): """ 오 불규칙 """ sent = "오늘 제주도로 여행왔어." - assert "오늘 제주도로 여행왔어.", styler(sent, 1) - assert "오늘 제주도로 여행왔어요.", styler(sent, 2) - assert "오늘 제주도로 여행왔습니다.", styler(sent, 3) + assert "오늘 제주도로 여행왔어.", style(sent, 1) + assert "오늘 제주도로 여행왔어요.", style(sent, 2) + assert "오늘 제주도로 여행왔습니다.", style(sent, 3) sent = "오늘 제주도로 여행왔어요." - assert "오늘 제주도로 여행왔어.", styler(sent, 1) - assert "오늘 제주도로 여행왔어요.", styler(sent, 2) - assert "오늘 제주도로 여행왔습니다.", styler(sent, 3) + assert "오늘 제주도로 여행왔어.", style(sent, 1) + assert "오늘 제주도로 여행왔어요.", style(sent, 2) + assert "오늘 제주도로 여행왔습니다.", style(sent, 3) -def test_conjugate_drop_ue(styler): +def test_conjugate_drop_ue(): """ 으 탈락 불규칙 """ sent = "전등을 껐다." - assert "전등을 껐다.", styler(sent, 1) - assert "전등을 껐어요.", styler(sent, 2) - assert "전등을 껐습니다.", styler(sent, 3) + assert "전등을 껐다.", style(sent, 1) + assert "전등을 껐어요.", style(sent, 2) + assert "전등을 껐습니다.", style(sent, 3) sent = "전등을 껐어요." - assert "전등을 껐어.", styler(sent, 1) - assert "전등을 껐어요.", styler(sent, 2) - assert "전등을 껐습니다.", styler(sent, 3) + assert "전등을 껐어.", style(sent, 1) + assert "전등을 껐어요.", style(sent, 2) + assert "전등을 껐습니다.", style(sent, 3) -def test_conjugate_gara(styler): +def test_conjugate_gara(): """ -가라 불규칙 """ sent = "저기로 가거라." - assert "저기로 가거라.", styler(sent, 1) - assert "저기로 가세요.", styler(sent, 2) - assert "저기로 가십시오.", styler(sent, 3) + assert "저기로 가거라.", style(sent, 1) + assert "저기로 가세요.", style(sent, 2) + assert "저기로 가십시오.", style(sent, 3) sent = "저기로 가세요." - assert "저기로 가셔.", styler(sent, 1) - assert "저기로 가세요.", styler(sent, 2) - assert "저기로 가십시오.", styler(sent, 3) + assert "저기로 가셔.", style(sent, 1) + assert "저기로 가세요.", style(sent, 2) + assert "저기로 가십시오.", style(sent, 3) -def test_conjugate_neura(styler): +def test_conjugate_neura(): """ -너라 불규칙 """ sent = "이리 오너라." - assert "이리 오너라.", styler(sent, 1) - assert "이리 오세요.", styler(sent, 2) - assert "이리 오십시오.", styler(sent, 3) + assert "이리 오너라.", style(sent, 1) + assert "이리 오세요.", style(sent, 2) + assert "이리 오십시오.", style(sent, 3) sent = "이리 오세요." - assert "이리 오셔.", styler(sent, 1) - assert "이리 오세요.", styler(sent, 2) - assert "이리 오십시오.", styler(sent, 3) + assert "이리 오셔.", style(sent, 1) + assert "이리 오세요.", style(sent, 2) + assert "이리 오십시오.", style(sent, 3) -def test_conjugate_yue(styler): +def test_conjugate_yue(): """ -여 불규칙 """ sent = "나는 그리하지 아니하였다." - assert "나는 그리하지 아니하였다.", styler(sent, 1) - assert "저는 그리하지 아니했어요.", styler(sent, 2) - assert "저는 그리하지 아니했습니다.", styler(sent, 3) + assert "나는 그리하지 아니하였다.", style(sent, 1) + assert "저는 그리하지 아니했어요.", style(sent, 2) + assert "저는 그리하지 아니했습니다.", style(sent, 3) sent = "저는 그리하지 아니하였어요." - assert "나는 그리하지 아니했어.", styler(sent, 1) - assert "저는 그리하지 아니하였어요.", styler(sent, 2) - assert "저는 그리하지 아니했습니다.", styler(sent, 3) + assert "나는 그리하지 아니했어.", style(sent, 1) + assert "저는 그리하지 아니하였어요.", style(sent, 2) + assert "저는 그리하지 아니했습니다.", style(sent, 3) -def test_conjugate_drop_hiut(styler): +def test_conjugate_drop_hiut(): """ ㅎ 탈락 """ sent = "하늘이 파랗다." - assert "하늘이 파랗다.", styler(sent, 1) - assert "하늘이 파래요.", styler(sent, 2) - assert "하늘이 파랗습니다.", styler(sent, 3) + assert "하늘이 파랗다.", style(sent, 1) + assert "하늘이 파래요.", style(sent, 2) + assert "하늘이 파랗습니다.", style(sent, 3) sent = "하늘이 파래요." - assert "하늘이 파래.", styler(sent, 1) - assert "하늘이 파래요.", styler(sent, 2) - assert "하늘이 파랗습니다.", styler(sent, 3) + assert "하늘이 파래.", style(sent, 1) + assert "하늘이 파래요.", style(sent, 2) + assert "하늘이 파랗습니다.", style(sent, 3) -def test_conjugate_drop_yi(styler): +def test_conjugate_drop_yi(): """ ㅓ + 이. """ sent = "이렇게 하는 거야?" - assert "이렇게 하는 거야?", styler(sent, 1) - assert "이렇게 하는 거죠?", styler(sent, 2) - assert "이렇게 하는 겁니까?", styler(sent, 3) + assert "이렇게 하는 거야?", style(sent, 1) + assert "이렇게 하는 거죠?", style(sent, 2) + assert "이렇게 하는 겁니까?", style(sent, 3) sent = "이렇게 하는 거죠?" - assert "이렇게 하는 거야?", styler(sent, 1) - assert "이렇게 하는 거죠?", styler(sent, 2) - assert "이렇게 하는 겁니까?", styler(sent, 3) + assert "이렇게 하는 거야?", style(sent, 1) + assert "이렇게 하는 거죠?", style(sent, 2) + assert "이렇게 하는 겁니까?", style(sent, 3) # --- known issues --- # @pytest.mark.skip("추가할만한 기능 (1): 밥 -> 진지") def test_more_1(): sent = "밥 먹어" - assert "밥 먹어.", styler(sent, 1) - assert "밥 먹어요", styler(sent, 2) - assert "진지 잡수세요", styler(sent, 3) + assert "밥 먹어.", style(sent, 1) + assert "밥 먹어요", style(sent, 2) + assert "진지 잡수세요", style(sent, 3) @pytest.mark.skip("추가할만한 기능 (2): 존대를 할 때는 주어를 생략할 때가 있다") def test_more_2(): sent = "자네만 믿고 있겠네" # 만약.. 들어오는 입력이 반말이라면, 굳이 반말인 경우를 수정할 필요가 없다. - assert "자네만 믿고 있겠네.", styler(sent, 1) - assert "믿고 있겠어요.", styler(sent, 2) - assert "믿고 있겠습니다.", styler(sent, 3) + assert "자네만 믿고 있겠네.", style(sent, 1) + assert "믿고 있겠어요.", style(sent, 2) + assert "믿고 있겠습니다.", style(sent, 3) @pytest.mark.skip() -def test_khaiii_error_1(styler): +def test_khaiii_error_1(): """ 이건 khaiii에서의 문제다. "줍"만을 어간으로 추출해야하는데 알 수 없는 이유로 그렇게 되지 않는다. @@ -561,48 +557,48 @@ def test_khaiii_error_1(styler): 만을 고려하게된다. 그래서 ㅂ 블규칙이 적용되지 않음. """ sent = "길가다가 동전을 주웠어." - assert "길가다가 동전을 주웠어.", styler(sent, 1) - assert "길가다가 동전을 주웠어요.", styler(sent, 2) - assert "길가다가 동전을 주웠습니다.", styler(sent, 3) + assert "길가다가 동전을 주웠어.", style(sent, 1) + assert "길가다가 동전을 주웠어요.", style(sent, 2) + assert "길가다가 동전을 주웠습니다.", style(sent, 3) sent = "길가다가 동전을 주웠어요." # 아... 줍우... 줍이 아니라.. 줍우.. - assert "길가다가 동전을 주웠어.", styler(sent, 1) - assert "길가다가 동전을 주웠어요.", styler(sent, 2) - assert "길가다가 동전을 주웠습니다.", styler(sent, 3) + assert "길가다가 동전을 주웠어.", style(sent, 1) + assert "길가다가 동전을 주웠어요.", style(sent, 2) + assert "길가다가 동전을 주웠습니다.", style(sent, 3) @pytest.mark.skip() -def test_khaiii_error_2(styler): +def test_khaiii_error_2(): """ 이것도 khaiii에서의 문제다. 걷어를 맥락을 고려하지 않고 무조건적으로 걸어로 분석한다. """ sent = "이참에 돈을 걷어가자." - assert "이참에 돈을 걷어가자.", styler(sent, 1) - assert "이참에 돈을 걷어가요.", styler(sent, 2) - assert "이참에 돈을 걷어갑시다.", styler(sent, 3) + assert "이참에 돈을 걷어가자.", style(sent, 1) + assert "이참에 돈을 걷어가요.", style(sent, 2) + assert "이참에 돈을 걷어갑시다.", style(sent, 3) @pytest.mark.skip() -def test_khaiii_error_3(styler): +def test_khaiii_error_3(): sent = "가까우니까 걸어가요." - assert "가까우니까 걸어가자.", styler(sent, 1) - assert "가까우니까 걸어가요.", styler(sent, 2) - assert "가까우니까 걸어갑시다.", styler(sent, 3) + assert "가까우니까 걸어가자.", style(sent, 1) + assert "가까우니까 걸어가요.", style(sent, 2) + assert "가까우니까 걸어갑시다.", style(sent, 3) @pytest.mark.skip() -def test_contextual_1(styler): +def test_contextual_1(): # 이런 식으로 맥락이 필요한 경우도 대응이 어렵다. (존대 종결어미 선정에 맥락이 관여하는 경우) # 이제, 밥을 등, 단어 선택에 따라 formal의 형태가 달라지는데, 이것에 대응하는 것은 불가능하다. # 맥락이 필요하다. 오직 규칙만으로는 불가능하다. sent = "자 이제 먹어요." - assert "자 이제 먹읍시다", styler(sent, 3) + assert "자 이제 먹읍시다", style(sent, 3) sent = "전 밥을 먹어요." - assert "전 밥을 먹습니다", styler(sent, 3) + assert "전 밥을 먹습니다", style(sent, 3) @pytest.mark.skip() -def test_contextual_2(styler): +def test_contextual_2(): """ -르 불규칙 (conjugation 규칙에 맥락이 관여하는 경우) e.g. 이르 + 어 -> 이르러 @@ -611,40 +607,40 @@ def test_contextual_2(styler): 여기 이슈참고: https://github.com/eubinecto/politely/issues/56#issue-1233231686 """ sent = "하지말라고 일렀다." - assert "하지말라고 일렀다.", styler(sent, 1) - assert "하지말라고 일렀어요.", styler(sent, 2) - assert "하지말라고 일렀습니다.", styler(sent, 3) + assert "하지말라고 일렀다.", style(sent, 1) + assert "하지말라고 일렀어요.", style(sent, 2) + assert "하지말라고 일렀습니다.", style(sent, 3) sent = "드디어 정상에 이르렀다." - assert "드디어 정상에 이르렀다.", styler(sent, 1) - assert "드디어 정상에 이르렀어요.", styler(sent, 2) - assert "드디어 정상에 이르렀습니다.", styler(sent, 3) + assert "드디어 정상에 이르렀다.", style(sent, 1) + assert "드디어 정상에 이르렀어요.", style(sent, 2) + assert "드디어 정상에 이르렀습니다.", style(sent, 3) @pytest.mark.skip() -def test_contextual_3(styler): +def test_contextual_3(): """ 쓰레기를 주워요 -> 쓰레기를 주웁시다 / 쓰레기를 줍습니다 (존대 종결어미 선정에 맥락이 관여하는 경우) 둘다 가능하다. 이 경우는 맥락이 필요하다. 규칙만으로는 불가능하다. # 자세한 설명: https://github.com/eubinecto/politely/issues/60#issuecomment-1126839221 """ sent = "저는 쓰레기를 주워요." - assert "나는 쓰레기를 주워.", styler(sent, 1) - assert "저는 쓰레기를 주워요.", styler(sent, 2) - assert "저는 쓰레기를 줍습니다.", styler(sent, 3) + assert "나는 쓰레기를 주워.", style(sent, 1) + assert "저는 쓰레기를 주워요.", style(sent, 2) + assert "저는 쓰레기를 줍습니다.", style(sent, 3) sent = "같이 쓰레기를 주워요." - assert "같이 쓰레기를 줍자.", styler(sent, 1) - assert "같이 쓰레기를 주워요.", styler(sent, 2) - assert "같이 쓰레기를 주웁시다.", styler(sent, 3) + assert "같이 쓰레기를 줍자.", style(sent, 1) + assert "같이 쓰레기를 주워요.", style(sent, 2) + assert "같이 쓰레기를 주웁시다.", style(sent, 3) @pytest.mark.skip() -def test_contextual_4(styler): +def test_contextual_4(): """ 이것도 마찬가지로 맥락이 필요하다. 떠나요 -> 떠나 / 떠나자, 둘 중 무엇이 정답인지는 맥락을 보아야만 알 수 있다. 떠나요 -> 떠납니다 / 떠납시다 -> 둘 중 무엇이 맞는지도... 마찬가지 """ sent = "자, 떠나요. 동해바다로." - assert "자, 떠나자. 동해바다로.", styler(sent, 1) - assert "자, 떠나요. 동해바다로.", styler(sent, 2) - assert "자, 떠납시다. 동해바다로.", styler(sent, 3) + assert "자, 떠나자. 동해바다로.", style(sent, 1) + assert "자, 떠나요. 동해바다로.", style(sent, 2) + assert "자, 떠납시다. 동해바다로.", style(sent, 3) diff --git a/politely/__init__.py b/politely/__init__.py index 3d92df1..fc009f6 100644 --- a/politely/__init__.py +++ b/politely/__init__.py @@ -1,12 +1,11 @@ -from politely.fetchers import fetch_rules, fetch_honorifics -from politely.stylers import styler -from khaiii.khaiii import KhaiiiApi +from politely.fetchers import fetch_rules, fetch_honorifics, fetch_listeners, fetch_environs import pandas as pd # noqa -# initialise the resources to use +# initialise the global constants here RULES = fetch_rules() HONORIFICS = fetch_honorifics() -LISTENERS = pd.DataFrame(RULES).transpose().index -ENVIRONS = pd.DataFrame(RULES).transpose().columns -# initialise the analyser to use -analyser = KhaiiiApi() +LISTENERS = fetch_listeners() +ENVIRONS = fetch_environs() + +# quick access +from politely.stylers import style diff --git a/politely/fetchers.py b/politely/fetchers.py index 8674418..4cd551f 100644 --- a/politely/fetchers.py +++ b/politely/fetchers.py @@ -1,4 +1,5 @@ import oyaml as yaml +import pandas as pd # noqa from politely.paths import HONORIFICS_YAML, RULES_YAML @@ -10,3 +11,13 @@ def fetch_honorifics() -> dict: def fetch_rules() -> dict: with open(str(RULES_YAML), "r") as fh: return yaml.safe_load(fh) + + +def fetch_listeners() -> list: + rules = fetch_rules() + return pd.DataFrame(rules).transpose().index.tolist() + + +def fetch_environs() -> list: + rules = fetch_rules() + return pd.DataFrame(rules).transpose().columns.tolist() diff --git a/politely/stylers.py b/politely/stylers.py index a520dab..c23364b 100644 --- a/politely/stylers.py +++ b/politely/stylers.py @@ -1,71 +1,74 @@ -import inspect import re import requests # noqa import pandas as pd # noqa from politely.errors import EFNotIncludedError, EFNotSupportedError -from politely import analyser, RULES, HONORIFICS +from politely import RULES, HONORIFICS from politely.hangle import conjugate as politely_conjugate from multipledispatch import dispatch from functools import wraps +from khaiii.khaiii import KhaiiiApi + +# to be used within functions +analyser = KhaiiiApi() # --- decorators --- # -def log(f): +def _log(f): """ log the in's and out's of the function """ + @wraps(f) def wrapper(*args, **kwargs): out = f(*args, **kwargs) # TODO: log the in's and out's return out + return wrapper -def preprocess(sent: str) -> str: +def _preprocess(sent: str) -> str: out = sent.strip() # khaiii model is sensitive to empty spaces, so we should get rid of it. if not out.endswith("?") and not out.endswith("!"): out = out + "." if not out.endswith(".") else out # for accurate pos-tagging return out -def matched(pattern: str, string: str) -> bool: +def _matched(pattern: str, string: str) -> bool: return True if re.match(f"(^|.*\\+){re.escape(pattern)}(\\+.*|$)", string) else False -def check(tokens: list) -> list: +def _check(tokens: list) -> list: """ Check if your assumption holds. Raises a custom error if any of them does not hold. """ - efs = [ - "+".join(map(str, token.morphs)) for token in tokens if "EF" in "+".join(map(str, token.morphs)) - ] + efs = ["+".join(map(str, token.morphs)) for token in tokens if "EF" in "+".join(map(str, token.morphs))] # assumption 1: the sentence must include more than 1 EF's if not efs: raise EFNotIncludedError("|".join(["+".join(map(str, token.morphs)) for token in tokens])) # assumption 2: all EF's should be supported by KPS. for ef in efs: for pattern in HONORIFICS.keys(): - if matched(pattern, ef): + if _matched(pattern, ef): break else: raise EFNotSupportedError(ef) return tokens -@log -def analyze(sent: str) -> list: +@_log +def _analyze(sent: str) -> list: return analyser.analyze(sent) -@log -def honorify(tokens: list, politeness: int) -> list: +@_log +def _honorify(tokens: list, politeness: int) -> list: lex2morphs = [(token.lex, list(map(str, token.morphs))) for token in tokens] out = list() for lex, morphs in lex2morphs: tuned = "+".join(morphs) for pattern in HONORIFICS.keys(): - if matched(pattern, tuned): + if _matched(pattern, tuned): honorific = HONORIFICS[pattern][politeness] tuned = tuned.replace(pattern, honorific) # TODO: log the honorifics here @@ -79,8 +82,8 @@ def honorify(tokens: list, politeness: int) -> list: return out -@log -def conjugate(tokens: list) -> str: +@_log +def _conjugate(tokens: list) -> str: """ Progressively conjugate morphemes from left to right. """ @@ -97,24 +100,26 @@ def conjugate(tokens: list) -> str: return " ".join(out) +# --- stylers --- # +@dispatch(str, int) +def style(sent: str, politeness: int) -> str: + """ + The first way of using style. + """ + out = _preprocess(sent) + out = _analyze(out) + out = _check(out) + out = _honorify(out, politeness) + out = _conjugate(out) + return out + + @dispatch(str, str, str) def style(sent: str, listener: str, environ: str) -> str: + """ + The second way of using style. + """ case = RULES[listener][environ] # TODO: log the case - out = preprocess(sent) - out = analyze(out) - out = check(out) - out = honorify(out, case['politeness']) - out = conjugate(out) + out = style(sent, case["politeness"]) return out - - -@dispatch(str, int) -def style(sent: str, politeness: int) -> str: - out = preprocess(sent) - out = analyze(out) - out = check(out) - out = honorify(out, politeness) - out = conjugate(out) - return out -