HanLP官方GitHub位址
HanLP
在java項目中配置HanLP
推薦使用Maven方法
在poem.xml中加入以下代碼
<groupId>com.hankcs</groupId>
<artifactId>hanlp</artifactId>
<version>portable-1.3.3</version>
但是在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
import com.hankcs.hanlp.dictionary.CoreSynonymDictionary;
隻需要以上語句便可以使用HanLP
//使用hanlp計算語義距離
double[] numarray = new double[title_list.size()];
for (int i = 0; i < results.size(); i++) {
for (int j = 0; j < title_list.size(); j++) {
numarray[j] += CoreSynonymDictionary.similarity(results.get(i).name().toString(), title_list.get(j).toString());
}
}
文章來源于citySouth的部落格