master 分支
对于 master 分支,编译方法如下 :
git clone https://github.com/hankcs/HanLP.git
mvn install -DskipTests
· 由于目前一些 test 不够规范,使用了硬编码路径下的资源,所以暂时跳过单元测试。
· 该方法不会将 src/main/resources 目录下的任何资源(包括 hanlp.properties )打包进 jar ,如果需要打包资源文件,请切换到 portable 分支。
portable 分支
git checkout portable
然后将需要的 data 放入 src/main/resources ,最后执行:
mvn install -DskipTests
运行 jar
目前 jar 包中有一些模块可以命令行执行,以感知机词法分析器为例。由于这些模块一般需要加载外部 data ,所以需要在运行时指定 hanlp.properties 。运行时,一个典型的目录结构如下:
· 此处只列出了重要的目录。
· 一个良好的实践是把 hanlp.properties 放到 resources 目录下。
命令行需要指定 jar 包和 hanlp.properties 所在的目录:
$ java -cp target/hanlp-1.6.0.jar:src/main/resources com.hankcs.hanlp.model.perceptron.Main -test \
<<< ' 华安集团胡花蕊来到纽约艺术博物馆参观 '
[ 华安 /nz 集团 /n]/nt 胡花蕊 /nr 来到 /v [ 纽约 /ns 艺术 /n 博物馆 /n]/ns 参观 /v
· Windows 用户请使用分号 java -cp target/hanlp-1.6.0.jar;src/main/resources
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31524777/viewspace-2637672/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/31524777/viewspace-2637672/