利用HanLP计算中文词语语义相似度

2018-11-02  本文已影响0人  lanlantian123

HanLP官方GitHub地址

HanLP

在java项目中配置HanLP

推荐使用Maven方法

在poem.xml中加入以下代码

com.hankcshanlpportable-1.3.3

但是在AndroidStudio中,没有Maven,所以在build.gradle的dependencies中加入如下代码

compile"com.hankcs:hanlp:portable-1.3.3"

还可以下载jar包和data包,使用hanlp.properties进行手动配置

在 IntelliJ IDEA中进入file -> project structure,在Libraries中添加jar包

更改hanlp.properties中的首行,指向data包所在的位置

将hanlp.properties放在out -> production -> name目录下

调用HanLP

importcom.hankcs.hanlp.dictionary.CoreSynonymDictionary;

只需要以上语句便可以使用HanLP

//使用hanlp计算语义距离double[] numarray =newdouble[title_list.size()];for(inti =0; i < results.size(); i++) {for(intj =0; j < title_list.size(); j++) {            numarray[j] += CoreSynonymDictionary.similarity(results.get(i).name().toString(), title_list.get(j).toString());        }    }

文章来源于citySouth的博客

上一篇 下一篇

猜你喜欢

热点阅读