web / tests /test_analyzer.py
qkrm's picture
deploy: no-singo site + FastAPI/Kiwi backend
b6f14c9 verified
Raw History Blame Contribute Delete
1.72 kB
import pytest
from analyzer import analyze
@pytest.mark.parametrize("text", [
"니 지금 뭐하노?",
"느그 아버지 뭐하시노?",
"이기 머꼬?",
"이기 뭐고?",
"밥 뭇나?",
"묵었나?",
"니가 학생이가?",
"와 이라노?",
"어디서 왔노?",
"어데 가노?",
"니 몇 살이고?",
])
def test_ok(text):
r = analyze(text)
assert r["state"] == "ok", (text, r.get("realPos"), r.get("whList"), r.get("morphs"))
@pytest.mark.parametrize("text,fixed", [
("오늘 출근하노?", "오늘 출근하나?"),
("이기 최고노", "이기 최고가?"),
("어디서 왔가?", "어디서 왔노?"),
("니 밥 먹었고?", "니 밥 먹었나?"),
("지금 자노?", "지금 자나?"),
])
def test_bad(text, fixed):
r = analyze(text)
assert r["state"] == "bad", (text, r.get("realPos"), r.get("whList"), r.get("morphs"))
assert r["fixed"] == fixed, (text, r["fixed"])
@pytest.mark.parametrize("text", [
"안녕하세요",
"점심 먹자",
"오늘 날씨 좋다",
])
def test_na(text):
assert analyze(text)["state"] == "na"
def test_empty():
assert analyze("")["state"] == "empty"
assert analyze("ㅋㅋㅋ??")["state"] == "empty"
def test_wh_highlight_offsets():
r = analyze("느그 아버지 뭐하시노?")
assert r["hasWh"]
(w,) = r["whList"]
# 원문에서 해당 span이 실제 의문사 어절을 가리켜야 한다
assert "뭐" in r["stripped"][w["start"]:w["end"]]
def test_dialect_wh_normalization():
# '어데'(=어디), '와'(=왜) 방언형도 의문사로 인식
assert analyze("어데 가노?")["hasWh"]
assert analyze("와 이라노?")["hasWh"]