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

今日头条

1114人已加入

描述

HanLP官方GitHub地址

HanLP

在java项目中配置HanLP

推荐使用Maven方法

在poem.xml中加入以下代码


    com.hankcs
    hanlp
    portable-1.3.3

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

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

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

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

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

  3. 将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的博客

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 相关推荐

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分