Skip to content

Commit

Permalink
Merge 7413e71 into 6da01c7
Browse files Browse the repository at this point in the history
  • Loading branch information
lovit committed Aug 1, 2018
2 parents 6da01c7 + 7413e71 commit 130793a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
5 changes: 3 additions & 2 deletions konlpy/jvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
from konlpy import utils


def init_jvm(jvmpath=None):
def init_jvm(jvmpath=None, max_heap_size=1024):
"""Initializes the Java virtual machine (JVM).
:param jvmpath: The path of the JVM. If left empty, inferred by :py:func:`jpype.getDefaultJVMPath`.
:param max_heap_size: Maximum memory usage limitation (Megabyte). Default is 1024 (1GB). If you set this value too small, you may got out of memory. We recommend that you set it 1024 ~ 2048 or more at least. However, if this value is too large, you may see inefficient memory usage.
"""

Expand Down Expand Up @@ -62,6 +63,6 @@ def init_jvm(jvmpath=None):
if jvmpath:
jpype.startJVM(jvmpath, '-Djava.class.path=%s' % classpath,
'-Dfile.encoding=UTF8',
'-ea', '-Xmx1024m')
'-ea', '-Xmx{}m'.format(max_heap_size))
else:
raise ValueError("Please specify the JVM path.")
5 changes: 3 additions & 2 deletions konlpy/tag/_hannanum.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Hannanum():
[('웃', 'P'), ('으면', 'E'), ('더', 'M'), ('행복', 'N'), ('하', 'X'), ('ㅂ니다', 'E'), ('!', 'S')]
:param jvmpath: The path of the JVM passed to :py:func:`.init_jvm`.
:param max_heap_size: Maximum memory usage limitation (Megabyte) :py:func:`.init_jvm`.
"""

def analyze(self, phrase):
Expand Down Expand Up @@ -102,9 +103,9 @@ def morphs(self, phrase):

return [s for s, t in self.pos(phrase)]

def __init__(self, jvmpath=None):
def __init__(self, jvmpath=None, max_heap_size=1024):
if not jpype.isJVMStarted():
jvm.init_jvm(jvmpath)
jvm.init_jvm(jvmpath, max_heap_size)

jhannanumJavaPackage = jpype.JPackage('kr.lucypark.jhannanum.comm')
HannanumInterfaceJavaClass = jhannanumJavaPackage.HannanumInterface
Expand Down
5 changes: 3 additions & 2 deletions konlpy/tag/_kkma.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Kkma():
There are reports that ``Kkma()`` is weak for long strings with no spaces between words. See issue :issue:`73` for details.
:param jvmpath: The path of the JVM passed to :py:func:`.init_jvm`.
:param max_heap_size: Maximum memory usage limitation (Megabyte) :py:func:`.init_jvm`.
"""

def nouns(self, phrase):
Expand Down Expand Up @@ -89,9 +90,9 @@ def sentences(self, phrase):
if not sentences: return []
return [sentences.get(i).getSentence() for i in range(sentences.size())]

def __init__(self, jvmpath=None):
def __init__(self, jvmpath=None, max_heap_size=1024):
if not jpype.isJVMStarted():
jvm.init_jvm(jvmpath)
jvm.init_jvm(jvmpath, max_heap_size)

kkmaJavaPackage = jpype.JPackage('kr.lucypark.kkma')
KkmaInterfaceJavaClass = kkmaJavaPackage.KkmaInterface
Expand Down
5 changes: 3 additions & 2 deletions konlpy/tag/_komoran.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Komoran():
If a particular POS is not assigned for a token or phrase, it will be tagged as NNP.
:param modelpath: The path to the Komoran HMM model.
:param max_heap_size: Maximum memory usage limitation (Megabyte) :py:func:`.init_jvm`.
"""

def pos(self, phrase, flatten=True, join=False):
Expand Down Expand Up @@ -85,9 +86,9 @@ def morphs(self, phrase):

return [s for s, t in self.pos(phrase)]

def __init__(self, jvmpath=None, userdic=None, modelpath=None):
def __init__(self, jvmpath=None, userdic=None, modelpath=None, max_heap_size=1024):
if not jpype.isJVMStarted():
jvm.init_jvm(jvmpath)
jvm.init_jvm(jvmpath, max_heap_size)

if modelpath:
self.modelpath = modelpath
Expand Down
5 changes: 3 additions & 2 deletions konlpy/tag/_okt.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Okt():
[('이', 'Determiner'), ('것', 'Noun'), ('도', 'Josa'), ('되다', 'Verb'), ('ㅋㅋ', 'KoreanParticle')]
:param jvmpath: The path of the JVM passed to :py:func:`.init_jvm`.
:param max_heap_size: Maximum memory usage limitation (Megabyte) :py:func:`.init_jvm`.
"""

def pos(self, phrase, norm=False, stem=False, join=False):
Expand Down Expand Up @@ -81,9 +82,9 @@ def phrases(self, phrase):

return [p for p in self.jki.phrases(phrase).toArray()]

def __init__(self, jvmpath=None):
def __init__(self, jvmpath=None, max_heap_size=1024):
if not jpype.isJVMStarted():
jvm.init_jvm(jvmpath)
jvm.init_jvm(jvmpath, max_heap_size)

oktJavaPackage = jpype.JPackage('kr.lucypark.okt')
OktInterfaceJavaClass = oktJavaPackage.OktInterface
Expand Down

0 comments on commit 130793a

Please sign in to comment.