語義搜索相關配置
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;
}
本文來自博客園,作者:zwbsoft,轉載請注明原文鏈接:http://www.rzrgm.cn/zwbsoft/p/18147201
電話微信:13514280351

浙公網安備 33010602011771號