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

HanLP官方GitHub地址

HanLPjava

在java项目中配置HanLP

推荐使用Maven方法

在poem.xml中加入如下代码git

<dependency>
    <groupId>com.hankcs</groupId>
    <artifactId>hanlp</artifactId>
    <version>portable-1.3.3</version>
</dependency>

可是在AndroidStudio中,没有Maven,因此在build.gradle的dependencies中加入以下代码github

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

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

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

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

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

调用HanLP

import com.hankcs.hanlp.dictionary.CoreSynonymDictionary;

只须要以上语句即可以使用HanLPcode

//使用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的博客xml

相关文章
相关标签/搜索