File size: 1,721 Bytes
b6f14c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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"]