-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex_dictionary.py
More file actions
43 lines (36 loc) · 1.44 KB
/
ex_dictionary.py
File metadata and controls
43 lines (36 loc) · 1.44 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
# -*- coding: utf-8 -*-
import pickle
class ExDictionary:
@staticmethod
def make_ex_dictionary():
dictionary = list()
with open('.\\res\\exception_expression.txt', 'r', encoding='utf-8-sig') as ex_data_file:
for each_line in ex_data_file:
try:
expression = each_line.strip()
morpheme = expression.split('+')
expression = list()
for i in range(len(morpheme)):
expression.append(morpheme[i].split('/'))
eojeol = list()
eojeol_type = list()
for i in range(len(expression)):
eojeol.append(expression[i][0])
eojeol_type.append(expression[i][1])
expression = list()
expression.append(eojeol)
expression.append(eojeol_type)
dictionary.append(expression)
except IndexError as error:
print(error)
return None
dictionary = dictionary[1:]
return dictionary
@staticmethod
def save_dictionary(data, path):
with open(path, 'wb') as dictionary:
pickle.dump(data, dictionary)
@staticmethod
def load_dictionary(path):
with open(path, 'rb') as dictionary:
return pickle.load(dictionary, encoding='utf-8')