How to use the konlpy.utils.installpath function in konlpy

To help you get started, we’ve selected a few konlpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github konlpy / konlpy / konlpy / jvm.py View on Github external
"""

    if jpype.isJVMStarted():
        logging.warning('JVM is already running. Do not init twice!')
        return

    folder_suffix = [
        '{0}', '{0}{1}bin',
        '{0}{1}jhannanum-0.8.4.jar',
        '{0}{1}kkma-2.0.jar',
        '{0}{1}komoran-2.4-e.jar',
        '{0}{1}shineware-common-2.0.jar', '{0}{1}shineware-ds-1.0.jar',
        '{0}{1}snakeyaml-1.12.jar', '{0}{1}scala-library-2.11.4.jar', '{0}{1}twitter-korean-text-2.4.3.jar', '{0}{1}twitter-text-1.10.1.jar',
        '{0}{1}*']

    javadir = '%s%sjava' % (utils.installpath, os.sep)

    args = [javadir, os.sep]
    classpath = os.pathsep.join(f.format(*args) for f in folder_suffix)

    jvmpath = jvmpath or jpype.getDefaultJVMPath()

    # NOTE: Temporary patch for Issue #76. Erase when possible.
    if sys.platform == 'darwin'\
            and jvmpath.find('1.8.0') > 0\
            and jvmpath.endswith('libjvm.dylib'):
        jvmpath = '%s/lib/jli/libjli.dylib' % jvmpath.split('/lib/')[0]

    if jvmpath:
        jpype.startJVM(jvmpath, '-Djava.class.path=%s' % classpath,
                                '-Dfile.encoding=UTF8',
                                '-ea', '-Xmx1024m')
github konlpy / konlpy / konlpy / tag / _hannanum.py View on Github external
def __init__(self, jvmpath=None):
        if not jpype.isJVMStarted():
            jvm.init_jvm(jvmpath)

        jhannanumJavaPackage = jpype.JPackage('kr.lucypark.jhannanum.comm')
        HannanumInterfaceJavaClass = jhannanumJavaPackage.HannanumInterface
        self.jhi = HannanumInterfaceJavaClass()  # Java instance
        self.tagset = utils.read_json('%s/data/tagset/hannanum.json' % utils.installpath)
github konlpy / konlpy / konlpy / tag / _kkma.py View on Github external
def __init__(self, jvmpath=None):
        if not jpype.isJVMStarted():
            jvm.init_jvm(jvmpath)

        kkmaJavaPackage = jpype.JPackage('kr.lucypark.kkma')
        KkmaInterfaceJavaClass = kkmaJavaPackage.KkmaInterface
        self.jki = KkmaInterfaceJavaClass()  # Java instance
        self.tagset = utils.read_json('%s/data/tagset/kkma.json' % utils.installpath)
github konlpy / konlpy / konlpy / corpus.py View on Github external
def abspath(self, filename=None):
        """Absolute path of corpus file.
        If ``filename`` is *None*, returns absolute path of corpus.

        :param filename: Name of a particular file in the corpus.
        """
        basedir = '%s/data/corpus/%s' % (utils.installpath, self.name)
        if filename:
            return '%s/%s' % (basedir, filename)
        else:
            return '%s/' % basedir
github konlpy / konlpy / konlpy / tag / _mecab.py View on Github external
def __init__(self, dicpath='/usr/local/lib/mecab/dic/mecab-ko-dic'):
        self.dicpath = dicpath
        try:
            self.tagger = Tagger('-d %s' % dicpath)
            self.tagset = utils.read_json('%s/data/tagset/mecab.json' % utils.installpath)
        except RuntimeError:
            raise Exception('The MeCab dictionary does not exist at "%s". Is the dictionary correctly installed?\nYou can also try entering the dictionary path when initializing the Mecab class: "Mecab(\'/some/dic/path\')"' % dicpath)
        except NameError:
            raise Exception('Install MeCab in order to use it: http://konlpy.org/en/latest/install/')
github konlpy / konlpy / konlpy / tag / _twitter.py View on Github external
def __init__(self, jvmpath=None):
        if not jpype.isJVMStarted():
            jvm.init_jvm(jvmpath)

        tktJavaPackage = jpype.JPackage('kr.lucypark.tkt')
        TktInterfaceJavaClass = tktJavaPackage.TktInterface
        self.jki = TktInterfaceJavaClass()
        self.tagset = utils.read_json('%s/data/tagset/twitter.json' % utils.installpath)
github konlpy / konlpy / konlpy / tag / _komoran.py View on Github external
if not jpype.isJVMStarted():
            jvm.init_jvm(jvmpath)
        komoranJavaPackage = jpype.JPackage('kr.lucypark.komoran')
        KomoranInterfaceJavaClass = komoranJavaPackage.KomoranInterface
        try:
            self.jki = KomoranInterfaceJavaClass()
        except TypeError:  # Package kr.lucypark.komoran.KomoranInterface is not Callable
            raise IOError("Cannot access komoran-dic. Please leave an issue at https://github.com/konlpy/konlpy/issues")

        if dicpath:
            self.dicpath = dicpath
        else:
            # FIXME: Cannot execute without sudoing
            # java.lang.NoClassDefFoundErrorPyRaisable: java.lang.NoClassDefFoundError: kr/co/shineware/nlp/komoran/core/analyzer/Komoran
            self.dicpath = os.path.join(utils.installpath, 'java', 'data', 'models')
            self.tagset = utils.read_json('%s/data/tagset/komoran.json' % utils.installpath)
github konlpy / konlpy / konlpy / data.py View on Github external
path += [
        r'C:\konlpy_data', r'D:\konlpy_data', r'E:\konlpy_data',
        os.path.join(sys.prefix, 'konlpy_data'),
        os.path.join(sys.prefix, 'lib', 'konlpy_data'),
        os.path.join(os.environ.get('APPDATA', 'C:\\'), 'konlpy_data')]

# UNIX & OS X common locations
else:
    path += [
        '/usr/share/konlpy_data',
        '/usr/local/share/konlpy_data',
        '/usr/lib/konlpy_data',
        '/usr/local/lib/konlpy_data']

# Include KoNLPy installpath
path += ['%s/data' % utils.installpath]


def find(resource_url):
    """Find the path of a given resource URL by searching through
    directories in ``konlpy.data.path``.
    If the given resource is not found, raise a ``LookupError``,
    whose message gives a pointer to the installation instructions
    for ``konlpy.download()``.

    :type resource_url: str
    :param resource_url: The URL of the resource to search for.
        URLs are posix-style relative path names, such as ``corpora/kolaw``.
        In particular, directory names should always be separated by
        the forward slash character (i.e., '/'), which will be automatically
        converted to a platform-appropriate path separator by KoNLPy.
    """
github konlpy / konlpy / konlpy / tag / _komoran.py View on Github external
def __init__(self, jvmpath=None, dicpath=None):
        if not jpype.isJVMStarted():
            jvm.init_jvm(jvmpath)
        komoranJavaPackage = jpype.JPackage('kr.lucypark.komoran')
        KomoranInterfaceJavaClass = komoranJavaPackage.KomoranInterface
        try:
            self.jki = KomoranInterfaceJavaClass()
        except TypeError:  # Package kr.lucypark.komoran.KomoranInterface is not Callable
            raise IOError("Cannot access komoran-dic. Please leave an issue at https://github.com/konlpy/konlpy/issues")

        if dicpath:
            self.dicpath = dicpath
        else:
            # FIXME: Cannot execute without sudoing
            # java.lang.NoClassDefFoundErrorPyRaisable: java.lang.NoClassDefFoundError: kr/co/shineware/nlp/komoran/core/analyzer/Komoran
            self.dicpath = os.path.join(utils.installpath, 'java', 'data', 'models')
            self.tagset = utils.read_json('%s/data/tagset/komoran.json' % utils.installpath)