-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.py
More file actions
59 lines (48 loc) · 1.95 KB
/
debug.py
File metadata and controls
59 lines (48 loc) · 1.95 KB
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
import MeCab
import pandas as pd
df = pd.read_csv("datas/output/jeonla_dialect_data_processed_1.csv", index_col=0)
def pos(sentence: str):
"""한국어 토큰을 분리합니다. 토큰과 품사를 튜플 리스트로 반환합니다.
매개변수:
sentence (str): 토큰화할 문장
반환값:
token list (list[tuple]): 토큰과 품사 리스트
"""
t = MeCab.Tagger()
tag_result = t.parse(sentence)
tag_result = tag_result.replace("\t", ".@!").replace("\n", ".@!").split(".@!")
tag_word = tag_result[::2][:-1] # 마지막 EOS는 자른다
tag_info = tag_result[1::2][:-1] # 마지막 EOS는 자른다
return [(word, info.split(',')[0]) for word, info in zip(tag_word, tag_info)]
def morphs(sentence: str):
"""한국어 토큰을 분리합니다. 토큰의 리스트를 반환합니다.
매개변수:
sentence (str): 토큰화할 문장
반환값:
token list (list): 토큰 리스트
"""
t = MeCab.Tagger()
tag_result = t.parse(sentence)
tag_result = tag_result.replace("\t", ".@!").replace("\n", ".@!").split(".@!")
return tag_result[::2][:-1]
def morph_and_preprocess(sentence: str):
"""한국어 토큰을 분리하고 전처리합니다. 토큰의 리스트를 반환합니다.
매개변수:
sentence (str): 토큰화할 문장
반환값:
token list (list): 토큰 리스트
"""
pos_result = pos(sentence)
word_list = []
for word, info in pos_result:
if info == "NNP":
# 고유명사일 경우 "고유"라는 단일 명사로 표현하도록 대체
word_list.append("고유")
else:
word_list.append(word)
return word_list
df = df.dropna()
dialect_list = df["방언"].to_list()
for i in range(len(dialect_list)):
sentence = dialect_list[i]
dialect_list[i] = morph_and_preprocess(sentence)