forked from shelari/prereform_to_contemporary
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dict_settings.py
47 lines (45 loc) · 1.13 KB
/
dict_settings.py
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
# -*- coding: utf-8 -*-
__author__ = 'ElenaSidorova'
import codecs
dicts = [
'freq.csv',
'ozhegov.csv',
'sharov.csv',
'ushakov.csv',
'zaliznyak.csv'
]
wrong_dicts = [
'adjectives_ija_ends.csv',
'perfect_verbs.csv'
]
ok_dicts = [
'soft_sign_ends.csv'
]
prefixes = [
'all_prefixes.csv'
]
class DictLoader(object):
@classmethod
def load_dicts(cls):
named_dicts = cls.read_data(dicts)
wrong = cls.read_data(wrong_dicts)
ok = cls.read_data(ok_dicts)
all_prefixes = cls.read_data(prefixes)
dict_settings = [named_dicts, wrong, ok, all_prefixes]
return dict_settings
@classmethod
def read_data(cls, arr):
result = []
for d in arr:
with codecs.open(d, 'r', 'utf-8') as inf:
data = inf.read().strip()
data = data.replace(u'\r', u'').lower().split(u'\n')
if 'freq' in d:
new = []
for el in data:
new.append(el.split()[0])
data = new
result.append(data)
return result
# a = DictLoader()
# b = a.load_dicts()