Update backend/spellchecker.py
Browse files- backend/spellchecker.py +191 -191
backend/spellchecker.py
CHANGED
@@ -1,191 +1,191 @@
|
|
1 |
-
import json
|
2 |
-
import difflib
|
3 |
-
from hanspell import spell_checker
|
4 |
-
from hanspell.constants import CheckResult
|
5 |
-
from kiwipiepy import Kiwi
|
6 |
-
|
7 |
-
ERROR_TYPE_MAPPING = {
|
8 |
-
CheckResult.PASSED: 0, # ๋ฌธ์ ๊ฐ ์๋ ๋จ์ด ๋๋ ๊ตฌ์
|
9 |
-
CheckResult.WRONG_SPELLING: 1, # ๋ง์ถค๋ฒ์ ๋ฌธ์ ๊ฐ ์๋ ๋จ์ด ๋๋ ๊ตฌ์
|
10 |
-
CheckResult.WRONG_SPACING: 2, # ๋์ด์ฐ๊ธฐ์ ๋ฌธ์ ๊ฐ ์๋ ๋จ์ด ๋๋ ๊ตฌ์
|
11 |
-
CheckResult.AMBIGUOUS: 3, # ํ์ค์ด๊ฐ ์์ฌ๋๋ ๋จ์ด ๋๋ ๊ตฌ์
|
12 |
-
CheckResult.STATISTICAL_CORRECTION: 4, # ํต๊ณ์ ๊ต์ ์ ๋ฐ๋ฅธ ๋จ์ด ๋๋ ๊ตฌ์
|
13 |
-
}
|
14 |
-
import difflib
|
15 |
-
|
16 |
-
|
17 |
-
def update_corrections_by_error_text(original_text, checked_text, corrections):
|
18 |
-
updated = []
|
19 |
-
|
20 |
-
for corr in corrections:
|
21 |
-
error = corr["error"]
|
22 |
-
start_pos = original_text.find(error)
|
23 |
-
|
24 |
-
if start_pos == -1:
|
25 |
-
# error ๋ฌธ์ฅ์ ๋ชป ์ฐพ์ ๊ฒฝ์ฐ position ๊ธฐ๋ฐ์ผ๋ก fallback
|
26 |
-
start_pos = corr["position"]
|
27 |
-
|
28 |
-
length = len(error)
|
29 |
-
# checked_text์์ ๋์ผ ์์น ์ถ์
|
30 |
-
corrected_text = checked_text[start_pos : start_pos + length]
|
31 |
-
|
32 |
-
new_corr = corr.copy()
|
33 |
-
new_corr["checked"] = corrected_text
|
34 |
-
new_corr["position"] = start_pos # ์์น ๋ณด์
|
35 |
-
new_corr["length"] = length
|
36 |
-
updated.append(new_corr)
|
37 |
-
|
38 |
-
return updated
|
39 |
-
|
40 |
-
|
41 |
-
def extract_phrase(text: str, position: int) -> str:
|
42 |
-
if position < 0 or position >= len(text):
|
43 |
-
return ""
|
44 |
-
|
45 |
-
# ์ผ์ชฝ ํ์: position - 1 ๋ถํฐ ๊ณต๋ฐฑ์ด ๋์ฌ ๋๊น์ง
|
46 |
-
left = position - 1
|
47 |
-
while left >= 0 and text[left] != " ":
|
48 |
-
left -= 1
|
49 |
-
|
50 |
-
# ์ค๋ฅธ์ชฝ ํ์: position + 1 ๋ถํฐ ๊ณต๋ฐฑ์ด ๋์ฌ ๋๊น์ง
|
51 |
-
right = position + 1
|
52 |
-
while right < len(text) and text[right] != " ":
|
53 |
-
right += 1
|
54 |
-
|
55 |
-
return text[left + 1 : right]
|
56 |
-
|
57 |
-
|
58 |
-
def get_space_diffs(original: str, corrected: str):
|
59 |
-
diffs = []
|
60 |
-
orig_len = len(original)
|
61 |
-
corr_len = len(corrected)
|
62 |
-
o_idx = c_idx = 0
|
63 |
-
|
64 |
-
while o_idx < orig_len and c_idx < corr_len:
|
65 |
-
o_char = original[o_idx]
|
66 |
-
c_char = corrected[c_idx]
|
67 |
-
|
68 |
-
# ๋์ผ ๋ฌธ์๋ฉด ํต๊ณผ
|
69 |
-
if o_char == c_char:
|
70 |
-
o_idx += 1
|
71 |
-
c_idx += 1
|
72 |
-
continue
|
73 |
-
# ์๋ฌธ์ ๊ณต๋ฐฑ์ด ์๊ณ ๊ต์ ๋ฌธ์ ์์ผ๋ฉด โ delete_space
|
74 |
-
if o_char == " " and c_char != " ":
|
75 |
-
error = extract_phrase(original, o_idx)
|
76 |
-
check = spell_checker.check(error).as_dict()["checked"]
|
77 |
-
diffs.append(
|
78 |
-
{
|
79 |
-
"error": error,
|
80 |
-
"checked": check,
|
81 |
-
"position": o_idx,
|
82 |
-
"length": -1,
|
83 |
-
"errortype": ERROR_TYPE_MAPPING[2],
|
84 |
-
}
|
85 |
-
)
|
86 |
-
o_idx += 1 # ๊ณต๋ฐฑ์ ๋๊น
|
87 |
-
|
88 |
-
# ๊ต์ ๋ฌธ์ ๊ณต๋ฐฑ์ด ์๊ณ ์๋ฌธ์ ์์ผ๋ฉด โ insert_space
|
89 |
-
elif c_char == " " and o_char != " ":
|
90 |
-
# ๊ณต๋ฐฑ์ ๊ทธ "์ ๋ฌธ์" ๋ค์ ์ฝ์
ํ๋ค๊ณ ๊ฐ์
|
91 |
-
error = extract_phrase(original, o_idx)
|
92 |
-
check = spell_checker.check(error).as_dict()["checked"]
|
93 |
-
diffs.append(
|
94 |
-
{
|
95 |
-
"error": error,
|
96 |
-
"checked": check,
|
97 |
-
"position": o_idx, # ์๋ฌธ ๊ธฐ์ค ์ฝ์
์์น
|
98 |
-
"length": 1,
|
99 |
-
"errortype": ERROR_TYPE_MAPPING[2],
|
100 |
-
}
|
101 |
-
)
|
102 |
-
c_idx += 1 # ๊ณต๋ฐฑ์ ๋๊น
|
103 |
-
|
104 |
-
# ๋ ๋ค ๋ค๋ฅด์ง๋ง ๊ณต๋ฐฑ๋ ์๋ ๋ (๋ฌธ๋ฒ ๊ต์ ๋ฑ): ๊ทธ๋ฅ ๋๊น
|
105 |
-
else:
|
106 |
-
o_idx += 1
|
107 |
-
c_idx += 1
|
108 |
-
|
109 |
-
return diffs
|
110 |
-
|
111 |
-
|
112 |
-
def check(text: str):
|
113 |
-
ch_text = spell_checker.check(text)
|
114 |
-
info = ch_text.as_dict()
|
115 |
-
orig_text = info["original"]
|
116 |
-
corr_text = info["checked"]
|
117 |
-
time = info["time"]
|
118 |
-
if orig_text == corr_text:
|
119 |
-
flag = 0
|
120 |
-
else:
|
121 |
-
flag = 1
|
122 |
-
print(info["words"])
|
123 |
-
space = get_space_diffs(orig_text, corr_text)
|
124 |
-
# 1) originalโcorrected ๊ฐ ๋ฌธ์ ๋จ์ ๋งคํ ์์ฑ
|
125 |
-
sm = difflib.SequenceMatcher(None, orig_text, corr_text)
|
126 |
-
mapping = {}
|
127 |
-
for tag, i1, i2, j1, j2 in sm.get_opcodes():
|
128 |
-
if tag == "equal":
|
129 |
-
# ์ผ์น ๋ธ๋ก: 1:1 ๋งคํ
|
130 |
-
for offset in range(i2 - i1):
|
131 |
-
mapping[j1 + offset] = i1 + offset
|
132 |
-
elif tag in ("replace", "insert"):
|
133 |
-
# ๊ต์ฒด๋ธ๋กยท์ฝ์
๋ธ๋ก: ๊ต์ ๋ฌธ์ ๋ชจ๋ ์๋ณธ ๋ธ๋ก ์์ ์์น๋ก ๋งคํ
|
134 |
-
for offset in range(j2 - j1):
|
135 |
-
mapping[j1 + offset] = i1
|
136 |
-
# 2) ํ ํฐ๋ณ๋ก ์์น ๋ฐ ์๋ ํ๋ฆฐ ๋จ์ด ์ถ์ถ
|
137 |
-
corrections = []
|
138 |
-
for token, status in info["words"].items():
|
139 |
-
if status == CheckResult.PASSED or status == CheckResult.WRONG_SPACING:
|
140 |
-
continue
|
141 |
-
|
142 |
-
corr_pos = corr_text.find(token)
|
143 |
-
|
144 |
-
if corr_pos != -1 and corr_pos in mapping:
|
145 |
-
orig_pos = mapping[corr_pos]
|
146 |
-
# ์๋ณธ ํ
์คํธ์์ token ๊ธธ์ด๋งํผ ์๋ผ๋ธ๋ค๋ค.
|
147 |
-
error_word = orig_text[orig_pos : orig_pos + len(token)]
|
148 |
-
else:
|
149 |
-
orig_pos = None
|
150 |
-
error_word = token
|
151 |
-
length = len(error_word)
|
152 |
-
corrections.append(
|
153 |
-
{
|
154 |
-
"error": error_word,
|
155 |
-
"checked": token,
|
156 |
-
"position": orig_pos,
|
157 |
-
"length": length,
|
158 |
-
"errortype": ERROR_TYPE_MAPPING[status],
|
159 |
-
}
|
160 |
-
)
|
161 |
-
combined = corrections + space
|
162 |
-
|
163 |
-
sorted_combined = sorted(combined, key=lambda x: x["position"])
|
164 |
-
result = {
|
165 |
-
"flag": flag,
|
166 |
-
"original_text": info["original"],
|
167 |
-
"checked_text": info["checked"],
|
168 |
-
"corrections": sorted_combined,
|
169 |
-
"time": time,
|
170 |
-
}
|
171 |
-
|
172 |
-
return result
|
173 |
-
|
174 |
-
|
175 |
-
if __name__ == "__main__":
|
176 |
-
sample = "๋๋ ์ค๋ ์์นจ๋ฐฅ์ ๋จน๊ณ ํ๊ต ๋ฅผ ๊ฐ๋ค.ํ๊ต ๋ฅผ ์๋ ์น๊ตฌ๋ค์ด ๋ง์น๋ง, ์ค๋์ ๋ณ๋ฃจ ๋ณด์ด์ง ์์๋ค. ํ๊ต์ ๋ฌธ๊ตฌ์ ์์ ๋ณผํ์ ์๋๋ฐ, ๊ทธ ๋ณผํ์ ์ํฌ๊ฐ ์์ฃผ ๋ง๋ผ์ ์์ฃผ ๋ฐ๊ฟ์ผํ๋ค. ํ๊ต์์ ํ๊ต ํ์ฌ์ ๋ํ ์๊ธฐ๋ฅผ ๋ค์๋๋ฐ, ๋ณ๋ฃจ ๊ธฐ๋๋ ์๋๋ค."
|
177 |
-
sample2 = "ํ๋ ๊ต์ก์ ๋จ์ํ ์ง์์ ์ ๋ฌํ๋ ๊ฒ์ ๋์ด์, ํ์์ ์ ์ธ์ ์ฑ์์ ๋ชฉํ๋ก ํ๋ค. ์ด์ ๋ฐ๋ผ ์ ์์ ์ง์ง์ ์ฌํ์ฑ ๊ต์ก๋ ์ ์ ์ค์ํด์ง๊ณ ์์๋ค. ๊ทธ๋ฌ๋ ์์ง๋ ๋ง์ ํ๊ต์์๋ ์ฃผ์
์ ๊ต์ก์ด ์ค์ฌ์ด ๋์ด, ํ์๋ค์ด ์ฃผ๋์ ์ผ๋ก ํ์ตํ ๊ธฐํ๊ฐ ์ ๋ค. ๋ํ, ๊ต์ฌ๋ค์ ๊ณผ๋ํ ํ์ ์
๋ฌด๋ก ์ธํด ์์
์ค๋น์ ์ถฉ๋ถํ ์๊ฐ์ ๊ฐ์ง์ ์๊ณ , ์ด๋ ๊ต์ก์ ์ง ์ ํ๋ก ์ด์ด์ง ์ ์๋ฐ. ์ง์์ ์ธ ๊ต์ฌ ์ฐ์์ ๊ต์กํ๊ฒฝ ๊ฐ์ ์ด ๋ท๋ฐ์นจ๋์ด์ผ๋ง ๋ฏธ๋ํ ๊ต์ก์ด ์คํ๋ ์ ์์ฌ ๊ฒ์ด๋ค."
|
178 |
-
output = check(sample2)
|
179 |
-
print(json.dumps(output, ensure_ascii=False, indent=2))
|
180 |
-
print(sample2[79])
|
181 |
-
# "flag": ๋ฌธ์ฅ์ ๋ง์ถค๋ฒ ์ค๋ฅ๊ฐ ์๋์ง์ ์ฌ๋ถ(0: ์์/1: ์์)
|
182 |
-
# "original_text": ์๋ณธ ๋ฌธ์ฅ
|
183 |
-
# "checked_text": ๋ง์ถค๋ฒ์ด ์์ ๋ ๋ฌธ์ฅ
|
184 |
-
# "corrections"[
|
185 |
-
# {
|
186 |
-
# "error": ๋ง์ถค๋ฒ์ด ํ๋ฆฐ ๋จ์ด
|
187 |
-
# "position": ํ๋ฆฐ ๋จ์ด์ ๋ฌธ์ฅ ๋ด ์์น(์์์ )
|
188 |
-
# "errortype": ์ค๋ฅ ์ ํ(1~4)
|
189 |
-
# },
|
190 |
-
# ]
|
191 |
-
# "time": ์์ ์๊ฐ
|
|
|
1 |
+
import json
|
2 |
+
import difflib
|
3 |
+
from backend.hanspell import spell_checker
|
4 |
+
from backend.hanspell.constants import CheckResult
|
5 |
+
from kiwipiepy import Kiwi
|
6 |
+
|
7 |
+
ERROR_TYPE_MAPPING = {
|
8 |
+
CheckResult.PASSED: 0, # ๋ฌธ์ ๊ฐ ์๋ ๋จ์ด ๋๋ ๊ตฌ์
|
9 |
+
CheckResult.WRONG_SPELLING: 1, # ๋ง์ถค๋ฒ์ ๋ฌธ์ ๊ฐ ์๋ ๋จ์ด ๋๋ ๊ตฌ์
|
10 |
+
CheckResult.WRONG_SPACING: 2, # ๋์ด์ฐ๊ธฐ์ ๋ฌธ์ ๊ฐ ์๋ ๋จ์ด ๋๋ ๊ตฌ์
|
11 |
+
CheckResult.AMBIGUOUS: 3, # ํ์ค์ด๊ฐ ์์ฌ๋๋ ๋จ์ด ๋๋ ๊ตฌ์
|
12 |
+
CheckResult.STATISTICAL_CORRECTION: 4, # ํต๊ณ์ ๊ต์ ์ ๋ฐ๋ฅธ ๋จ์ด ๋๋ ๊ตฌ์
|
13 |
+
}
|
14 |
+
import difflib
|
15 |
+
|
16 |
+
|
17 |
+
def update_corrections_by_error_text(original_text, checked_text, corrections):
|
18 |
+
updated = []
|
19 |
+
|
20 |
+
for corr in corrections:
|
21 |
+
error = corr["error"]
|
22 |
+
start_pos = original_text.find(error)
|
23 |
+
|
24 |
+
if start_pos == -1:
|
25 |
+
# error ๋ฌธ์ฅ์ ๋ชป ์ฐพ์ ๊ฒฝ์ฐ position ๊ธฐ๋ฐ์ผ๋ก fallback
|
26 |
+
start_pos = corr["position"]
|
27 |
+
|
28 |
+
length = len(error)
|
29 |
+
# checked_text์์ ๋์ผ ์์น ์ถ์
|
30 |
+
corrected_text = checked_text[start_pos : start_pos + length]
|
31 |
+
|
32 |
+
new_corr = corr.copy()
|
33 |
+
new_corr["checked"] = corrected_text
|
34 |
+
new_corr["position"] = start_pos # ์์น ๋ณด์
|
35 |
+
new_corr["length"] = length
|
36 |
+
updated.append(new_corr)
|
37 |
+
|
38 |
+
return updated
|
39 |
+
|
40 |
+
|
41 |
+
def extract_phrase(text: str, position: int) -> str:
|
42 |
+
if position < 0 or position >= len(text):
|
43 |
+
return ""
|
44 |
+
|
45 |
+
# ์ผ์ชฝ ํ์: position - 1 ๋ถํฐ ๊ณต๋ฐฑ์ด ๋์ฌ ๋๊น์ง
|
46 |
+
left = position - 1
|
47 |
+
while left >= 0 and text[left] != " ":
|
48 |
+
left -= 1
|
49 |
+
|
50 |
+
# ์ค๋ฅธ์ชฝ ํ์: position + 1 ๋ถํฐ ๊ณต๋ฐฑ์ด ๋์ฌ ๋๊น์ง
|
51 |
+
right = position + 1
|
52 |
+
while right < len(text) and text[right] != " ":
|
53 |
+
right += 1
|
54 |
+
|
55 |
+
return text[left + 1 : right]
|
56 |
+
|
57 |
+
|
58 |
+
def get_space_diffs(original: str, corrected: str):
|
59 |
+
diffs = []
|
60 |
+
orig_len = len(original)
|
61 |
+
corr_len = len(corrected)
|
62 |
+
o_idx = c_idx = 0
|
63 |
+
|
64 |
+
while o_idx < orig_len and c_idx < corr_len:
|
65 |
+
o_char = original[o_idx]
|
66 |
+
c_char = corrected[c_idx]
|
67 |
+
|
68 |
+
# ๋์ผ ๋ฌธ์๋ฉด ํต๊ณผ
|
69 |
+
if o_char == c_char:
|
70 |
+
o_idx += 1
|
71 |
+
c_idx += 1
|
72 |
+
continue
|
73 |
+
# ์๋ฌธ์ ๊ณต๋ฐฑ์ด ์๊ณ ๊ต์ ๋ฌธ์ ์์ผ๋ฉด โ delete_space
|
74 |
+
if o_char == " " and c_char != " ":
|
75 |
+
error = extract_phrase(original, o_idx)
|
76 |
+
check = spell_checker.check(error).as_dict()["checked"]
|
77 |
+
diffs.append(
|
78 |
+
{
|
79 |
+
"error": error,
|
80 |
+
"checked": check,
|
81 |
+
"position": o_idx,
|
82 |
+
"length": -1,
|
83 |
+
"errortype": ERROR_TYPE_MAPPING[2],
|
84 |
+
}
|
85 |
+
)
|
86 |
+
o_idx += 1 # ๊ณต๋ฐฑ์ ๋๊น
|
87 |
+
|
88 |
+
# ๊ต์ ๋ฌธ์ ๊ณต๋ฐฑ์ด ์๊ณ ์๋ฌธ์ ์์ผ๋ฉด โ insert_space
|
89 |
+
elif c_char == " " and o_char != " ":
|
90 |
+
# ๊ณต๋ฐฑ์ ๊ทธ "์ ๋ฌธ์" ๋ค์ ์ฝ์
ํ๋ค๊ณ ๊ฐ์
|
91 |
+
error = extract_phrase(original, o_idx)
|
92 |
+
check = spell_checker.check(error).as_dict()["checked"]
|
93 |
+
diffs.append(
|
94 |
+
{
|
95 |
+
"error": error,
|
96 |
+
"checked": check,
|
97 |
+
"position": o_idx, # ์๋ฌธ ๊ธฐ์ค ์ฝ์
์์น
|
98 |
+
"length": 1,
|
99 |
+
"errortype": ERROR_TYPE_MAPPING[2],
|
100 |
+
}
|
101 |
+
)
|
102 |
+
c_idx += 1 # ๊ณต๋ฐฑ์ ๋๊น
|
103 |
+
|
104 |
+
# ๋ ๋ค ๋ค๋ฅด์ง๋ง ๊ณต๋ฐฑ๋ ์๋ ๋ (๋ฌธ๋ฒ ๊ต์ ๋ฑ): ๊ทธ๋ฅ ๋๊น
|
105 |
+
else:
|
106 |
+
o_idx += 1
|
107 |
+
c_idx += 1
|
108 |
+
|
109 |
+
return diffs
|
110 |
+
|
111 |
+
|
112 |
+
def check(text: str):
|
113 |
+
ch_text = spell_checker.check(text)
|
114 |
+
info = ch_text.as_dict()
|
115 |
+
orig_text = info["original"]
|
116 |
+
corr_text = info["checked"]
|
117 |
+
time = info["time"]
|
118 |
+
if orig_text == corr_text:
|
119 |
+
flag = 0
|
120 |
+
else:
|
121 |
+
flag = 1
|
122 |
+
print(info["words"])
|
123 |
+
space = get_space_diffs(orig_text, corr_text)
|
124 |
+
# 1) originalโcorrected ๊ฐ ๋ฌธ์ ๋จ์ ๋งคํ ์์ฑ
|
125 |
+
sm = difflib.SequenceMatcher(None, orig_text, corr_text)
|
126 |
+
mapping = {}
|
127 |
+
for tag, i1, i2, j1, j2 in sm.get_opcodes():
|
128 |
+
if tag == "equal":
|
129 |
+
# ์ผ์น ๋ธ๋ก: 1:1 ๋งคํ
|
130 |
+
for offset in range(i2 - i1):
|
131 |
+
mapping[j1 + offset] = i1 + offset
|
132 |
+
elif tag in ("replace", "insert"):
|
133 |
+
# ๊ต์ฒด๋ธ๋กยท์ฝ์
๋ธ๋ก: ๊ต์ ๋ฌธ์ ๋ชจ๋ ์๋ณธ ๋ธ๋ก ์์ ์์น๋ก ๋งคํ
|
134 |
+
for offset in range(j2 - j1):
|
135 |
+
mapping[j1 + offset] = i1
|
136 |
+
# 2) ํ ํฐ๋ณ๋ก ์์น ๋ฐ ์๋ ํ๋ฆฐ ๋จ์ด ์ถ์ถ
|
137 |
+
corrections = []
|
138 |
+
for token, status in info["words"].items():
|
139 |
+
if status == CheckResult.PASSED or status == CheckResult.WRONG_SPACING:
|
140 |
+
continue
|
141 |
+
|
142 |
+
corr_pos = corr_text.find(token)
|
143 |
+
|
144 |
+
if corr_pos != -1 and corr_pos in mapping:
|
145 |
+
orig_pos = mapping[corr_pos]
|
146 |
+
# ์๋ณธ ํ
์คํธ์์ token ๊ธธ์ด๋งํผ ์๋ผ๋ธ๋ค๋ค.
|
147 |
+
error_word = orig_text[orig_pos : orig_pos + len(token)]
|
148 |
+
else:
|
149 |
+
orig_pos = None
|
150 |
+
error_word = token
|
151 |
+
length = len(error_word)
|
152 |
+
corrections.append(
|
153 |
+
{
|
154 |
+
"error": error_word,
|
155 |
+
"checked": token,
|
156 |
+
"position": orig_pos,
|
157 |
+
"length": length,
|
158 |
+
"errortype": ERROR_TYPE_MAPPING[status],
|
159 |
+
}
|
160 |
+
)
|
161 |
+
combined = corrections + space
|
162 |
+
|
163 |
+
sorted_combined = sorted(combined, key=lambda x: x["position"])
|
164 |
+
result = {
|
165 |
+
"flag": flag,
|
166 |
+
"original_text": info["original"],
|
167 |
+
"checked_text": info["checked"],
|
168 |
+
"corrections": sorted_combined,
|
169 |
+
"time": time,
|
170 |
+
}
|
171 |
+
|
172 |
+
return result
|
173 |
+
|
174 |
+
|
175 |
+
if __name__ == "__main__":
|
176 |
+
sample = "๋๋ ์ค๋ ์์นจ๋ฐฅ์ ๋จน๊ณ ํ๊ต ๋ฅผ ๊ฐ๋ค.ํ๊ต ๋ฅผ ์๋ ์น๊ตฌ๋ค์ด ๋ง์น๋ง, ์ค๋์ ๋ณ๋ฃจ ๋ณด์ด์ง ์์๋ค. ํ๊ต์ ๋ฌธ๊ตฌ์ ์์ ๋ณผํ์ ์๋๋ฐ, ๊ทธ ๋ณผํ์ ์ํฌ๊ฐ ์์ฃผ ๋ง๋ผ์ ์์ฃผ ๋ฐ๊ฟ์ผํ๋ค. ํ๊ต์์ ํ๊ต ํ์ฌ์ ๋ํ ์๊ธฐ๋ฅผ ๋ค์๋๋ฐ, ๋ณ๋ฃจ ๊ธฐ๋๋ ์๋๋ค."
|
177 |
+
sample2 = "ํ๋ ๊ต์ก์ ๋จ์ํ ์ง์์ ์ ๋ฌํ๋ ๊ฒ์ ๋์ด์, ํ์์ ์ ์ธ์ ์ฑ์์ ๋ชฉํ๋ก ํ๋ค. ์ด์ ๋ฐ๋ผ ์ ์์ ์ง์ง์ ์ฌํ์ฑ ๊ต์ก๋ ์ ์ ์ค์ํด์ง๊ณ ์์๋ค. ๊ทธ๋ฌ๋ ์์ง๋ ๋ง์ ํ๊ต์์๋ ์ฃผ์
์ ๊ต์ก์ด ์ค์ฌ์ด ๋์ด, ํ์๋ค์ด ์ฃผ๋์ ์ผ๋ก ํ์ตํ ๊ธฐํ๊ฐ ์ ๋ค. ๋ํ, ๊ต์ฌ๋ค์ ๊ณผ๋ํ ํ์ ์
๋ฌด๋ก ์ธํด ์์
์ค๋น์ ์ถฉ๋ถํ ์๊ฐ์ ๊ฐ์ง์ ์๊ณ , ์ด๋ ๊ต์ก์ ์ง ์ ํ๋ก ์ด์ด์ง ์ ์๋ฐ. ์ง์์ ์ธ ๊ต์ฌ ์ฐ์์ ๊ต์กํ๊ฒฝ ๊ฐ์ ์ด ๋ท๋ฐ์นจ๋์ด์ผ๋ง ๋ฏธ๋ํ ๊ต์ก์ด ์คํ๋ ์ ์์ฌ ๊ฒ์ด๋ค."
|
178 |
+
output = check(sample2)
|
179 |
+
print(json.dumps(output, ensure_ascii=False, indent=2))
|
180 |
+
print(sample2[79])
|
181 |
+
# "flag": ๋ฌธ์ฅ์ ๋ง์ถค๋ฒ ์ค๋ฅ๊ฐ ์๋์ง์ ์ฌ๋ถ(0: ์์/1: ์์)
|
182 |
+
# "original_text": ์๋ณธ ๋ฌธ์ฅ
|
183 |
+
# "checked_text": ๋ง์ถค๋ฒ์ด ์์ ๋ ๋ฌธ์ฅ
|
184 |
+
# "corrections"[
|
185 |
+
# {
|
186 |
+
# "error": ๋ง์ถค๋ฒ์ด ํ๋ฆฐ ๋จ์ด
|
187 |
+
# "position": ํ๋ฆฐ ๋จ์ด์ ๋ฌธ์ฅ ๋ด ์์น(์์์ )
|
188 |
+
# "errortype": ์ค๋ฅ ์ ํ(1~4)
|
189 |
+
# },
|
190 |
+
# ]
|
191 |
+
# "time": ์์ ์๊ฐ
|