以下为全文:
#! /usr/bin/env python2.7
#coding=utf-8
from jpype import *
# startJVM(getDefaultJVMPath(), "-Djava.class.path=home/javawork/Hanlp/hanlp-1.2.7.jar;home/javawork/Hanlp/", "-Xms1g", "-Xmx1g")
startJVM(getDefaultJVMPath(), "-Djava.class.path=/home/qinghua/javawork/Hanlp/hanlp-1.2.7.jar:/home/qinghua/javawork/Hanlp")
HanLP = JClass('com.hankcs.hanlp.HanLP')
# 中文分词
print(HanLP.segment('你好,欢迎在Python中调用HanLP的API'))
testCases = [
"商品和服务",
"结婚的和尚未结婚的确实在干扰分词啊",
"买水果然后来世博园最后去世博会"]
for sentence in testCases: print(HanLP.segment(sentence))
# 命名实体识别与词性标注
NLPTokenizer = JClass('com.hankcs.hanlp.tokenizer.NLPTokenizer')
print(NLPTokenizer.segment('中国科学院计算技术研究所的宗成庆教授正在教授自然语言处理课程'))
# 关键词提取
document = "水利部水资源司司长陈明忠9月29日在国务院新闻办举行的新闻发布会上透露," \
"根据刚刚完成了水资源管理制度的考核,有部分省接近了红线的指标," \
"有部分省超过红线的指标。对一些超过红线的地方,陈明忠表示,对一些取用水项目进行区域的限批," \
"严格地进行水资源论证和取水许可的批准。"
print(HanLP.extractKeyword(document, 2))
# 自动摘要
print(HanLP.extractSummary(document, 3))
# 依存句法分析
print(HanLP.parseDependency("徐先生还具体帮助他确定了把画雄鹰、松鼠和麻雀作为主攻目标。"))shutdownJVM()
github.com/hankcs/HanLP/issues?page=3&q=is%3Aissue+is%3Aopen