Skip to content

Commit 238688e

Browse files
authored
Merge pull request #7 from shineware/#6_add_heap_size_param
JVM Heap size 반영 및 테스트 코드 추가
2 parents 8571384 + 01bc219 commit 238688e

File tree

8 files changed

+140
-39
lines changed

8 files changed

+140
-39
lines changed

python/MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ include README.md
33
include requirements.txt
44
include PyKomoran/libs/**
55
include PyKomoran/models_*/**
6+
include PyKomoran/tests/test_data/**

python/PyKomoran/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ class Komoran:
2222
Komoran Wrapper class
2323
"""
2424

25-
def __init__(self, model_path="./models_full"):
25+
def __init__(self, model_path="./models_full", max_heap=1024):
2626
self._base_path = os.path.dirname(os.path.realpath(__file__))
2727
self._model_path = os.path.abspath(os.path.join(self._base_path, model_path))
2828

2929
assert os.path.exists(self._model_path)
3030

31-
jvm.init_jvm()
31+
jvm.init_jvm(max_heap)
3232
self._komoran = jvm.get_jvm().kr.co.shineware.nlp.pykomoran.KomoranEntryPoint()
3333

3434
self._komoran.init(self._model_path)

python/PyKomoran/jvm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
jvm_gateway = None
1111

1212

13-
def init_jvm(jar_path="./libs", max_heap=1024):
13+
def init_jvm(max_heap, jar_path="./libs"):
1414
base_path = os.path.dirname(os.path.realpath(__file__))
1515
jar_path = os.path.abspath(os.path.join(base_path, jar_path))
1616

python/PyKomoran/tests/_jvm_test.py renamed to python/PyKomoran/tests/ajvm_test.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
""" This test filename has _ prefix because this test should run before running other tests """
1+
""" This test filename has 'a' prefix because this test should run before running other tests """
22
import nose
3+
34
from PyKomoran.jvm import *
45

6+
global jvm_gateway
57
if jvm_gateway is not None:
68
jvm_gateway.shutdown()
79
test_jvm1 = None
8-
test_jvm2 = None
910

1011

1112
def test_to_before_init_Jvm():
1213
"""
13-
before jvm_init(), jvm_gateway should be None
14+
JVM Test: before jvm_init(), jvm_gateway should be None
1415
:return:
1516
"""
1617
global jvm_gateway
@@ -20,7 +21,7 @@ def test_to_before_init_Jvm():
2021

2122
def test_to_get_Jvm_before_init():
2223
"""
23-
before jvm_init(), get_jvm() should be None
24+
JVM Test: before jvm_init(), get_jvm() should be None
2425
:return:
2526
"""
2627
global test_jvm1
@@ -32,25 +33,25 @@ def test_to_get_Jvm_before_init():
3233

3334
def test_to_init_Jvm():
3435
"""
35-
when call jvm_init() first time, jvm object should be returned
36+
JVM Test: when call jvm_init() first time, jvm object should be returned
3637
:return:
3738
"""
3839
global test_jvm1
3940

40-
test_jvm1 = init_jvm()
41+
test_jvm1 = init_jvm(1024)
4142

4243
assert test_jvm1 is not None
4344

4445

4546
def test_to_duplicate_init_Jvm():
4647
"""
47-
when call jvm_init() more than once, None should be returned
48+
JVM Test: when call jvm_init() more than once, None should be returned
4849
:return:
4950
"""
5051
global test_jvm1
5152

52-
test_jvm2 = init_jvm()
53-
test_jvm3 = init_jvm()
53+
test_jvm2 = init_jvm(1024)
54+
test_jvm3 = init_jvm(1024)
5455

5556
assert test_jvm1 is not None
5657
assert test_jvm2 is None
@@ -59,7 +60,7 @@ def test_to_duplicate_init_Jvm():
5960

6061
def test_to_get_Jvm_after_init():
6162
"""
62-
when call get_jvm() after init_jvm(), jvm object should be returned
63+
JVM Test: when call get_jvm() after init_jvm(), jvm object should be returned
6364
:return:
6465
"""
6566
test_jvm2 = get_jvm()
@@ -69,7 +70,7 @@ def test_to_get_Jvm_after_init():
6970

7071
def test_to_duplicate_get_Jvm_after_init():
7172
"""
72-
when call get_jvm() after init_jvm() more than once, returned values should be same
73+
JVM Test: when call get_jvm() after init_jvm() more than once, returned values should be same
7374
:return:
7475
"""
7576
global test_jvm1

python/PyKomoran/tests/core_test.py

Lines changed: 118 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import os
12
import nose
3+
24
from PyKomoran.core import *
35
from PyKomoran.type import *
46

@@ -8,7 +10,7 @@
810

911
def 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-
3224
def 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

4739
def 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

6254
def 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

7769
def 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

9284
def 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

108100
def 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

146138
def 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

184176
def 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

223215
def 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

262254
def 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+
294391
if __name__ == '__main__':
295392
nose.runmodule()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
테스트 단어
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
테스트 테/NNG 스/NNG 트/NNG

python/PyKomoran/tests/type_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
def test_to_init_Token():
66
"""
7-
init Token using given Dict, and validate given values with Token methods
7+
Type Test: init Token using given Dict, and validate given values with Token methods
88
:return:
99
"""
1010
# @formatter:off
@@ -33,7 +33,7 @@ def test_to_init_Token():
3333

3434
def test_to_init_Token_using_Pos_name():
3535
"""
36-
init Token using given Dict with use_pos_name parameter, and validate given values with Token methods
36+
Type Test: init Token using given Dict with use_pos_name parameter, and validate given values with Token methods
3737
:return:
3838
"""
3939
# @formatter:off
@@ -62,7 +62,7 @@ def test_to_init_Token_using_Pos_name():
6262

6363
def test_to_init_Pair():
6464
"""
65-
init Pair using given Dict, and validate given values with Pair methods
65+
Type Test: init Pair using given Dict, and validate given values with Pair methods
6666
:return:
6767
"""
6868
# @formatter:off
@@ -85,7 +85,7 @@ def test_to_init_Pair():
8585

8686
def test_to_pos_table():
8787
"""
88-
check pos_table is initialized well
88+
Type Test: check pos_table is initialized well
8989
:return:
9090
"""
9191
global pos_table

0 commit comments

Comments
 (0)