语义搜索相关配置

1.打开services项目,在pom文件中引入依赖如下
<dependency>
    <groupId>com.hankcs</groupId>
    <artifactId>hanlp</artifactId>
    <version>portable-1.8.3</version>
</dependency>

2.在hanlp github下载语言模型,放入项目根目录下

3.在services项目中,找到hanlpconfig,配置需要加载的模型路径

4.调用相关接口返回相关结果

public List<String> getSearchTerms(String text){
//加载hanlp模型
@Autowired
private WordVectorModel wordVectorModel;
//调用接口
List<Map.Entry<String,Float>>list=wordVectorModel.nearest(text,20);
    List<String> result = new ArrayList<>();
for(Map.Entry<String,float>entry:list){
result.add(entry.getKey());
}
//返回结果
result result;

}

 

posted @ 2024-04-20 09:15  zwbsoft  阅读(3)  评论(0编辑  收藏  举报