Skip to content

Commit

Permalink
下载非portable版的jar,体积更小速度更快
Browse files Browse the repository at this point in the history
  • Loading branch information
hankcs committed Mar 23, 2018
1 parent 06f6725 commit 3d55813
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand All @@ -180,7 +180,7 @@ hanlp
│   ├── dictionary
│   └── model
├── hanlp.properties
└── hanlp-portable-1.6.0.jar
└── hanlp-1.6.0.jar
```

## 测试
Expand Down
14 changes: 11 additions & 3 deletions pyhanlp/static/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import print_function

import os
import shutil
import sys

curdir = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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())
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 3d55813

Please sign in to comment.