-
Notifications
You must be signed in to change notification settings - Fork 0
/
tagger.py
50 lines (38 loc) · 1005 Bytes
/
tagger.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
48
49
50
__author__ = 'Sereni'
from sklearn.externals import joblib
from feature_extractor import Token
clf = joblib.load('model2.pkl')
vec = joblib.load('feature_transformer2.pkl')
def pos(word):
"""
Determine the word's part of speech using our model
>>> pos('тёплый')
'A'
>>> pos('кот')
'S'
>>> pos('мяукает')
'V'
>>> pos('кросскатегориальность')
'S'
>>> pos('шпиль')
'S'
>>> pos('стекло')
'S'
>>> pos('мой')
'A-PRO'
>>> pos('он')
'S-PRO'
"""
features = Token((word, None)).features_dict
vector = vec.transform(features)
return clf.predict(vector)[0][0]
if __name__ == "__main__":
# clf = joblib.load('model.pkl')
# vec = joblib.load('feature_transformer.pkl')
# demo part
phrase = input('Введите фразу: ')
words = phrase.split()
for word in words:
print(word, pos(word))
#import doctest
#doctest.testmod()