1+ import os
12import nose
3+
24from PyKomoran .core import *
35from PyKomoran .type import *
46
810
911def test_to_init_Komoran ():
1012 """
11- init Komoran with default model (models_full)
13+ Core Test: init Komoran with default model (models_full)
1214 :return:
1315 """
1416 global komoran
@@ -19,19 +21,9 @@ def test_to_init_Komoran():
1921 assert komoran ._komoran .isInitialized ()
2022
2123
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-
3224def test_to_analyze_get_nouns ():
3325 """
34- analyze test string with get_nouns() and check result is as expected
26+ Core Test: analyze with get_nouns()
3527 :return:
3628 """
3729 global komoran
@@ -46,7 +38,7 @@ def test_to_analyze_get_nouns():
4638
4739def test_to_analyze_get_morphes_by_tags ():
4840 """
49- analyze test string with get_morphes_by_tags() and check result is as expected
41+ Core Test: analyze with get_morphes_by_tags()
5042 :return:
5143 """
5244 global komoran
@@ -61,7 +53,7 @@ def test_to_analyze_get_morphes_by_tags():
6153
6254def test_to_analyze_get_morphes_by_invalid_tags ():
6355 """
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
6557 :return:
6658 """
6759 global komoran
@@ -76,7 +68,7 @@ def test_to_analyze_get_morphes_by_invalid_tags():
7668
7769def test_to_analyze_get_morphes_by_no_given_tags ():
7870 """
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=[])
8072 :return:
8173 """
8274 global komoran
@@ -91,7 +83,7 @@ def test_to_analyze_get_morphes_by_no_given_tags():
9183
9284def test_to_analyze_get_plain_text ():
9385 """
94- analyze test string with get_plain_text() and check result is as expected
86+ Core Test: analyze with get_plain_text()
9587 :return:
9688 """
9789 global komoran
@@ -107,7 +99,7 @@ def test_to_analyze_get_plain_text():
10799
108100def test_to_analyze_get_token_list_with_flatten ():
109101 """
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)
111103 :return:
112104 """
113105 global komoran
@@ -145,7 +137,7 @@ def test_to_analyze_get_token_list_with_flatten():
145137
146138def test_to_analyze_get_token_list_with_flatten_and_use_pos_name ():
147139 """
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)
149141 :return:
150142 """
151143 global komoran
@@ -183,7 +175,7 @@ def test_to_analyze_get_token_list_with_flatten_and_use_pos_name():
183175
184176def test_to_analyze_get_token_list_without_flatten ():
185177 """
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)
187179 :return:
188180 """
189181 global komoran
@@ -222,7 +214,7 @@ def test_to_analyze_get_token_list_without_flatten():
222214
223215def test_to_analyze_get_token_list_without_flatten_and_use_pos_name ():
224216 """
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)
226218 :return:
227219 """
228220 global komoran
@@ -261,7 +253,7 @@ def test_to_analyze_get_token_list_without_flatten_and_use_pos_name():
261253
262254def test_to_analyze_get_list ():
263255 """
264- analyze test string with get_list() and check result is as expected
256+ Core Test: analyze with get_list()
265257 :return:
266258 """
267259 global komoran
@@ -291,5 +283,110 @@ def test_to_analyze_get_list():
291283 # @formatter:on
292284
293285
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+
294391if __name__ == '__main__' :
295392 nose .runmodule ()
0 commit comments