1
+ import os
1
2
import nose
3
+
2
4
from PyKomoran .core import *
3
5
from PyKomoran .type import *
4
6
8
10
9
11
def test_to_init_Komoran ():
10
12
"""
11
- init Komoran with default model (models_full)
13
+ Core Test: init Komoran with default model (models_full)
12
14
:return:
13
15
"""
14
16
global komoran
@@ -19,19 +21,9 @@ def test_to_init_Komoran():
19
21
assert komoran ._komoran .isInitialized ()
20
22
21
23
22
- def test_to_set_user_dic ():
23
- # TODO: implement test_to_set_user_dic() test code
24
- pass
25
-
26
-
27
- def test_to_set_fw_dic ():
28
- # TODO: implement test_to_set_fw_dic() test code
29
- pass
30
-
31
-
32
24
def test_to_analyze_get_nouns ():
33
25
"""
34
- analyze test string with get_nouns() and check result is as expected
26
+ Core Test: analyze with get_nouns()
35
27
:return:
36
28
"""
37
29
global komoran
@@ -46,7 +38,7 @@ def test_to_analyze_get_nouns():
46
38
47
39
def test_to_analyze_get_morphes_by_tags ():
48
40
"""
49
- analyze test string with get_morphes_by_tags() and check result is as expected
41
+ Core Test: analyze with get_morphes_by_tags()
50
42
:return:
51
43
"""
52
44
global komoran
@@ -61,7 +53,7 @@ def test_to_analyze_get_morphes_by_tags():
61
53
62
54
def test_to_analyze_get_morphes_by_invalid_tags ():
63
55
"""
64
- analyze test string with get_morphes_by_tags(tag_list=['INVALID','POS']) and invalid tag_list and check result is as expected
56
+ Core Test: analyze with get_morphes_by_tags(tag_list=['INVALID','POS']) & invalid tag_list
65
57
:return:
66
58
"""
67
59
global komoran
@@ -76,7 +68,7 @@ def test_to_analyze_get_morphes_by_invalid_tags():
76
68
77
69
def test_to_analyze_get_morphes_by_no_given_tags ():
78
70
"""
79
- analyze test string with get_morphes_by_tags(tag_list=[]) and check result is as expected
71
+ Core Test: analyze with get_morphes_by_tags(tag_list=[])
80
72
:return:
81
73
"""
82
74
global komoran
@@ -91,7 +83,7 @@ def test_to_analyze_get_morphes_by_no_given_tags():
91
83
92
84
def test_to_analyze_get_plain_text ():
93
85
"""
94
- analyze test string with get_plain_text() and check result is as expected
86
+ Core Test: analyze with get_plain_text()
95
87
:return:
96
88
"""
97
89
global komoran
@@ -107,7 +99,7 @@ def test_to_analyze_get_plain_text():
107
99
108
100
def test_to_analyze_get_token_list_with_flatten ():
109
101
"""
110
- analyze test string with get_token_list(flatten=False,use_pos_name=False) and check result is as expected
102
+ Core Test: analyze with get_token_list(flatten=False,use_pos_name=False)
111
103
:return:
112
104
"""
113
105
global komoran
@@ -145,7 +137,7 @@ def test_to_analyze_get_token_list_with_flatten():
145
137
146
138
def test_to_analyze_get_token_list_with_flatten_and_use_pos_name ():
147
139
"""
148
- analyze test string with get_token_list(flatten=True,use_pos_name=True) and check result is as expected
140
+ Core Test: analyze with get_token_list(flatten=True,use_pos_name=True)
149
141
:return:
150
142
"""
151
143
global komoran
@@ -183,7 +175,7 @@ def test_to_analyze_get_token_list_with_flatten_and_use_pos_name():
183
175
184
176
def test_to_analyze_get_token_list_without_flatten ():
185
177
"""
186
- analyze test string with get_token_list(flatten=False,use_pos_name=False) and check result is as expected
178
+ Core Test: analyze with get_token_list(flatten=False,use_pos_name=False)
187
179
:return:
188
180
"""
189
181
global komoran
@@ -222,7 +214,7 @@ def test_to_analyze_get_token_list_without_flatten():
222
214
223
215
def test_to_analyze_get_token_list_without_flatten_and_use_pos_name ():
224
216
"""
225
- analyze test string with get_token_list(flatten=False,use_pos_name=True) and check result is as expected
217
+ Core Test: analyze with get_token_list(flatten=False,use_pos_name=True)
226
218
:return:
227
219
"""
228
220
global komoran
@@ -261,7 +253,7 @@ def test_to_analyze_get_token_list_without_flatten_and_use_pos_name():
261
253
262
254
def test_to_analyze_get_list ():
263
255
"""
264
- analyze test string with get_list() and check result is as expected
256
+ Core Test: analyze with get_list()
265
257
:return:
266
258
"""
267
259
global komoran
@@ -291,5 +283,110 @@ def test_to_analyze_get_list():
291
283
# @formatter:on
292
284
293
285
286
+ def test_to_set_user_dic ():
287
+ """
288
+ Core Test: test with set_user_dic()
289
+ :return:
290
+ """
291
+ global komoran
292
+
293
+ if komoran is None :
294
+ komoran = Komoran (model_path = './models_full' )
295
+
296
+ tokens = komoran .get_token_list ("테스트 단어" )
297
+
298
+ # @formatter:off
299
+ assert isinstance (tokens , list )
300
+ assert len (tokens ) == 2
301
+ assert isinstance (tokens [0 ], Token )
302
+ assert tokens [0 ] == Token ({
303
+ 'morph' : '테스트' ,
304
+ 'pos' : 'NNP' ,
305
+ 'beginIndex' : 0 ,
306
+ 'endIndex' : 3
307
+ })
308
+ assert tokens [1 ] == Token ({
309
+ 'morph' : '단어' ,
310
+ 'pos' : 'NNG' ,
311
+ 'beginIndex' : 4 ,
312
+ 'endIndex' : 6
313
+ })
314
+ # @formatter:on
315
+
316
+ base_path = os .path .dirname (os .path .realpath (__file__ ))
317
+ komoran .set_user_dic (os .path .join (base_path , "./test_data/dic.user" ))
318
+
319
+ tokens = komoran .get_token_list ("테스트 단어" )
320
+
321
+ # @formatter:off
322
+ assert isinstance (tokens , list )
323
+ assert len (tokens ) == 1
324
+ assert isinstance (tokens [0 ], Token )
325
+ assert tokens [0 ] == Token ({
326
+ 'morph' : '테스트 단어' ,
327
+ 'pos' : 'NNP' ,
328
+ 'beginIndex' : 0 ,
329
+ 'endIndex' : 6
330
+ })
331
+ # @formatter:on
332
+
333
+ pass
334
+
335
+
336
+ def test_to_set_fw_dic ():
337
+ # TODO: implement test_to_set_fw_dic() test code
338
+ """
339
+ Core Test: test with set_fw_dic()
340
+ :return:
341
+ """
342
+ global komoran
343
+
344
+ if komoran is None :
345
+ komoran = Komoran (model_path = './models_full' )
346
+
347
+ tokens = komoran .get_token_list ("테스트" )
348
+
349
+ # @formatter:off
350
+ assert isinstance (tokens , list )
351
+ assert len (tokens ) == 1
352
+ assert isinstance (tokens [0 ], Token )
353
+ assert tokens [0 ] == Token ({
354
+ 'morph' : '테스트' ,
355
+ 'pos' : 'NNP' ,
356
+ 'beginIndex' : 0 ,
357
+ 'endIndex' : 3
358
+ })
359
+ # @formatter:on
360
+
361
+ base_path = os .path .dirname (os .path .realpath (__file__ ))
362
+ komoran .set_fw_dic (os .path .join (base_path , "./test_data/fwd.user" ))
363
+
364
+ tokens = komoran .get_token_list ("테스트" )
365
+
366
+ # @formatter:off
367
+ assert isinstance (tokens , list )
368
+ assert len (tokens ) == 3
369
+ assert isinstance (tokens [0 ], Token )
370
+ assert tokens [0 ] == Token ({
371
+ 'morph' : '테' ,
372
+ 'pos' : 'NNG' ,
373
+ 'beginIndex' : 0 ,
374
+ 'endIndex' : 3 # TODO: Check and fix KOMORAN
375
+ })
376
+ assert tokens [1 ] == Token ({
377
+ 'morph' : '스' ,
378
+ 'pos' : 'NNG' ,
379
+ 'beginIndex' : 0 , # TODO: Check and fix KOMORAN
380
+ 'endIndex' : 3 # TODO: Check and fix KOMORAN
381
+ })
382
+ assert tokens [2 ] == Token ({
383
+ 'morph' : '트' ,
384
+ 'pos' : 'NNG' ,
385
+ 'beginIndex' : 0 , # TODO: Check and fix KOMORAN
386
+ 'endIndex' : 3 # TODO: Check and fix KOMORAN
387
+ })
388
+ # @formatter:on
389
+
390
+
294
391
if __name__ == '__main__' :
295
392
nose .runmodule ()
0 commit comments