diff --git a/README.md b/README.md index 060720c..2167fe3 100644 --- a/README.md +++ b/README.md @@ -160,14 +160,14 @@ hanlp segment --config path/to/another/hanlp.properties 注意: -1. **使用pip初次安装 pyhanlp 后,不设置上述变量,程序会自动下载所需依赖到默认位置。如果是设置了上述变量,则不进行下载。因为文件比较大,网络下载稳定性等原因,建议提前准备好[jar](https://mvnrepository.com/artifact/com.hankcs/hanlp)包,[配置文件](https://github.com/hankcs/HanLP#3%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6)和[data](https://github.com/hankcs/HanLP#2%E4%B8%8B%E8%BD%BDdata),并使用环境变量进行配置。** +1. **使用pip初次安装 pyhanlp 后,不设置上述变量,程序会自动下载所需依赖到默认位置。如果是设置了上述变量,则不进行下载。因为文件比较大,网络下载稳定性等原因,建议提前准备好[jar](https://github.com/hankcs/HanLP/releases)包,[配置文件](https://github.com/hankcs/HanLP#3%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6)和[data](https://github.com/hankcs/HanLP#2%E4%B8%8B%E8%BD%BDdata),并使用环境变量进行配置。** 2. 保证 hanlp.properties 中的 root 是指向正确的data路径。 比如: ``` -export HANLP_JAR_PATH=/hanlp/hanlp-portable-1.6.0.jar +export HANLP_JAR_PATH=/hanlp/hanlp-1.6.0.jar export HANLP_STATIC_ROOT=/hanlp ``` @@ -180,7 +180,7 @@ hanlp │   ├── dictionary │   └── model ├── hanlp.properties -└── hanlp-portable-1.6.0.jar +└── hanlp-1.6.0.jar ``` ## 测试 diff --git a/pyhanlp/static/__init__.py b/pyhanlp/static/__init__.py index ca37ef0..dddddb4 100644 --- a/pyhanlp/static/__init__.py +++ b/pyhanlp/static/__init__.py @@ -5,6 +5,7 @@ from __future__ import print_function import os +import shutil import sys curdir = os.path.dirname(os.path.abspath(__file__)) @@ -168,7 +169,10 @@ def install_hanlp_jar(version=None): # for f in archive.namelist(): # print(f) archive.extract('hanlp-{}-release/hanlp-{}.jar'.format(version, version), STATIC_ROOT) - # todo: jar is in pyhanlp/static/hanlp-1.6.0-release, should move to upper folder + zip_folder = os.path.join(STATIC_ROOT, 'hanlp-{}-release'.format(version)) + jar_file_name = 'hanlp-{}.jar'.format(version) + os.rename(os.path.join(zip_folder, jar_file_name), os.path.join(STATIC_ROOT, jar_file_name)) + shutil.rmtree(zip_folder) remove_file(jar_zip) global HANLP_JAR_VERSION HANLP_JAR_VERSION = version @@ -244,6 +248,11 @@ def uninstall_hanlp_jar(version='old'): if version == 'old': vs = hanlp_installed_jar_versions() if len(vs) > 1: + if vs[0].startswith('portable'): + remove_file(hanlp_jar_path(vs[0])) + vs = vs[1:] + global HANLP_JAR_VERSION + HANLP_JAR_VERSION = vs[0] for v in vs[1:]: remove_file(hanlp_jar_path(v)) else: @@ -268,5 +277,4 @@ def uninstall_hanlp_jar(version='old'): # write_config(data_version='1.6.0') # print(hanlp_installed_data_versions()) # download('http://storage.live.com/items/D4A741A579C555F7!65703:/data-for-1.6.0.zip', 'tmp') -# print(hanlp_installed_data_version()) -# update_hanlp() +# print(hanlp_installed_data_version()) \ No newline at end of file diff --git a/setup.py b/setup.py index a2ea7df..c280acb 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ setup( name='pyhanlp', - version='0.1.18', + version='0.1.21', description='Python wrapper for HanLP: Han Language Processing', long_description=long_description, url='https://github.com/hankcs/pyhanlp',