-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmorph_comparison.py
78 lines (66 loc) · 2.14 KB
/
morph_comparison.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# -*- coding: utf-8 -*-
import timeit, time
from random import randint
from konlpy.tag import Hannanum, Kkma, Komoran, Mecab, Okt
from khaiii import KhaiiiApi
import matplotlib.pyplot as plt
import matplotlib.ticker as mtick
f = open('dataset/sample-context.txt','r')
lines = f.readlines()
print('total lines : ',len(lines))
n = randint(0, len(lines))
def measure_time(analyzer, n, lines, name):
y = []
print('=== ',name,' ===')
print('Original Sentence : ',lines[n])
print('Random Analyze Result : ', analyzer.morphs(lines[n]))
start = time.time()
analyzer.morphs(''.join(lines[:11]))
y.append(time.time()-start)
start = time.time()
analyzer.morphs(''.join(lines[:101]))
y.append(time.time()-start)
start = time.time()
analyzer.morphs(''.join(lines[:1001]))
y.append(time.time()-start)
start = time.time()
analyzer.morphs(''.join(lines))
y.append(time.time()-start)
print('Measured time : ',y)
draw_plot(y, name)
def measure_khaiii_time(analyzer, n, lines):
y = []
print('=== Khaiii ===')
print('Original Sentene : ',lines[n])
print('Random Analyze Result : ', end='')
for word in analyzer.analyze(lines[n]):
for morph in word.morphs:
res = str(morph)
idx = res.find('/')
print(res[:idx], end=',')
print()
start = time.time()
analyzer.analyze(''.join(lines[:11]))
y.append(time.time()-start)
start = time.time()
analyzer.analyze(''.join(lines[:101]))
y.append(time.time()-start)
start = time.time()
analyzer.analyze(''.join(lines[:1001]))
y.append(time.time()-start)
start = time.time()
analyzer.analyze(''.join(lines))
y.append(time.time()-start)
print('Measured time : ',y)
draw_plot(y, 'Khaiii')
def draw_plot(y, name):
x = [10, 100, 1000, 10000]
plt.plot(x, y, label=name)
measure_time(Hannanum(), n, lines, 'Hannanum')
measure_time(Kkma(), n, lines, 'Kkma')
measure_time(Komoran(), n, lines, 'Komoran')
measure_time(Mecab(), n, lines, 'Mecab')
measure_time(Okt(), n, lines, 'Okt')
measure_khaiii_time(KhaiiiApi(), n, lines)
plt.legend()
plt.savefig('morph_result.png')