How to use the pyhanlp.static.HANLP_JAR_PATH function in pyhanlp

To help you get started, we’ve selected a few pyhanlp 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 hankcs / pyhanlp / pyhanlp / __init__.py View on Github external
raise ValueError(
                "配置错误: STATIC_ROOT=%s 目录下没有data文件夹" %
                STATIC_ROOT)
        else:
            raise ValueError(
                "配置错误: 数据包 %s 不存在,请修改配置文件中的root" %
                HANLP_DATA_PATH)
    elif not os.path.isfile(PATH_CONFIG):
        raise ValueError(
            "配置错误: STATIC_ROOT=%s 目录下没有hanlp.properties" %
            STATIC_ROOT)
    else:
        HANLP_JAR_VERSION = os.path.basename(HANLP_JAR_PATH)[len('hanlp-'):-len('.jar')]

        if HANLP_VERBOSE:
            print("加载 HanLP jar [%s] ..." % HANLP_JAR_PATH)
            print("加载 HanLP config [%s/hanlp.properties] ..." % (STATIC_ROOT))
            print("加载 HanLP data [%s/data] ..." % (STATIC_ROOT))

    java_url = 'https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html'
    pathsep = os.pathsep
    jvm_path = None
    try:
        jvm_path = getDefaultJVMPath()
    except JVMNotFoundException as e:
        eprint('找不到Java,请安装JDK8:%s' % java_url)
        browser_open(java_url)
        exit(1)
    except JVMNotSupportedException as e:
        eprint('Java位数与Python不一致,请重新安装一致的Java、Python、JPype1(必须都为32位或64位)')
        browser_open(java_url)
        exit(1)
github hankcs / pyhanlp / pyhanlp / __init__.py View on Github external
if "HANLP_JAR_PATH" in ENVIRON:
        HANLP_JAR_PATH = ENVIRON["HANLP_JAR_PATH"]
        if HANLP_VERBOSE:
            print('使用环境变量 HANLP_JAR_PATH={}'.format(HANLP_JAR_PATH))
    else:
        from pyhanlp.static import HANLP_JAR_PATH
    if "HANLP_JVM_XMS" in ENVIRON:
        HANLP_JVM_XMS = ENVIRON["HANLP_JVM_XMS"]
    else:
        HANLP_JVM_XMS = "1g"
    if "HANLP_JVM_XMX" in ENVIRON:
        HANLP_JVM_XMX = ENVIRON["HANLP_JVM_XMX"]
    else:
        HANLP_JVM_XMX = "2g"
    PATH_CONFIG = os.path.join(STATIC_ROOT, 'hanlp.properties')
    if not os.path.exists(HANLP_JAR_PATH):
        raise ValueError(
            "配置错误: HANLP_JAR_PATH=%s 不存在" %
            HANLP_JAR_PATH)
    elif not os.path.isfile(HANLP_JAR_PATH) or not HANLP_JAR_PATH.endswith('.jar'):
        raise ValueError(
            "配置错误: HANLP_JAR_PATH=%s 不是jar文件" %
            HANLP_JAR_PATH)
    elif not os.path.exists(STATIC_ROOT):
        raise ValueError(
            "配置错误: STATIC_ROOT=%s 不存在" %
            STATIC_ROOT)
    elif not os.path.isdir(HANLP_DATA_PATH):
        if HANLP_DATA_PATH.startswith(STATIC_ROOT):
            raise ValueError(
                "配置错误: STATIC_ROOT=%s 目录下没有data文件夹" %
                STATIC_ROOT)