|
|
@ -1,6 +1,8 @@
|
|
|
|
package com.sztzjy.marketing.service.impl;
|
|
|
|
package com.sztzjy.marketing.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
|
|
|
|
import com.google.gson.reflect.TypeToken;
|
|
|
|
import com.hankcs.hanlp.HanLP;
|
|
|
|
import com.hankcs.hanlp.HanLP;
|
|
|
|
import com.hankcs.hanlp.seg.common.Term;
|
|
|
|
import com.hankcs.hanlp.seg.common.Term;
|
|
|
|
import com.sztzjy.marketing.config.Constant;
|
|
|
|
import com.sztzjy.marketing.config.Constant;
|
|
|
@ -88,7 +90,8 @@ public class StuDigitalMarketingModelServiceImpl implements StuDigitalMarketingM
|
|
|
|
if(modelType.equals(Constant.COMMENT_EXTRACTION)){ //评论观点抽取
|
|
|
|
if(modelType.equals(Constant.COMMENT_EXTRACTION)){ //评论观点抽取
|
|
|
|
String commentUrl = "https://aip.baidubce.com/rpc/2.0/nlp/v2/comment_tag?charset=UTF-8&access_token="+ getAccessToken();
|
|
|
|
String commentUrl = "https://aip.baidubce.com/rpc/2.0/nlp/v2/comment_tag?charset=UTF-8&access_token="+ getAccessToken();
|
|
|
|
|
|
|
|
|
|
|
|
RequestBody body = RequestBody.create(mediaType, "{\"text\":\""+content+"\",\"type\":8}");
|
|
|
|
|
|
|
|
|
|
|
|
RequestBody body = RequestBody.create(mediaType, "{\"text\":\""+content+"\",\"type\":\""+id+"\"}");
|
|
|
|
|
|
|
|
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(commentUrl)
|
|
|
|
.url(commentUrl)
|
|
|
@ -98,8 +101,26 @@ public class StuDigitalMarketingModelServiceImpl implements StuDigitalMarketingM
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
Response response = HTTP_CLIENT.newCall(request).execute();
|
|
|
|
Response response = HTTP_CLIENT.newCall(request).execute();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String string = response.body().string();
|
|
|
|
|
|
|
|
// Gson对象
|
|
|
|
|
|
|
|
Gson gson = new Gson();
|
|
|
|
|
|
|
|
Map<String, Object> data = gson.fromJson(string, new TypeToken<Map<String, Object>>(){}.getType());
|
|
|
|
|
|
|
|
// Object object = data.get("items");
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if(object instanceof List){
|
|
|
|
|
|
|
|
// ArrayList<String> tagList = (ArrayList<String>) object;
|
|
|
|
|
|
|
|
// if (tagList.isEmpty()) {
|
|
|
|
|
|
|
|
// return new ResultEntity(HttpStatus.ACCEPTED,"请重新选择评论类型");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
if(data.containsKey("error_msg")){
|
|
|
|
|
|
|
|
return new ResultEntity(HttpStatus.ACCEPTED,"评论异常");
|
|
|
|
|
|
|
|
}
|
|
|
|
if (response.body() != null) {
|
|
|
|
if (response.body() != null) {
|
|
|
|
return new ResultEntity(HttpStatus.OK,"成功",response.body().string());
|
|
|
|
return new ResultEntity(HttpStatus.OK, "成功", string);
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
|
|
|
return new ResultEntity(HttpStatus.ACCEPTED,"评论异常");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -114,8 +135,17 @@ public class StuDigitalMarketingModelServiceImpl implements StuDigitalMarketingM
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
Response response = HTTP_CLIENT.newCall(request).execute();
|
|
|
|
Response response = HTTP_CLIENT.newCall(request).execute();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String string = response.body().string();
|
|
|
|
|
|
|
|
// Gson对象
|
|
|
|
|
|
|
|
Gson gson = new Gson();
|
|
|
|
|
|
|
|
Map<String, Object> data = gson.fromJson(string, new TypeToken<Map<String, Object>>(){}.getType());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(data.containsKey("error_msg")){
|
|
|
|
|
|
|
|
return new ResultEntity(HttpStatus.ACCEPTED,"评论异常");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (response.body() != null) {
|
|
|
|
if (response.body() != null) {
|
|
|
|
return new ResultEntity(HttpStatus.OK, "成功", response.body().string());
|
|
|
|
return new ResultEntity(HttpStatus.OK, "成功", string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -171,15 +201,9 @@ public class StuDigitalMarketingModelServiceImpl implements StuDigitalMarketingM
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 过滤标点符号的函数
|
|
|
|
// 过滤标点符号的函数
|
|
|
|
private String filterPunctuation(String originalContent) {
|
|
|
|
private String filterPunctuation(String content) {
|
|
|
|
// 创建一个正则表达式,用于匹配所有标点符号
|
|
|
|
//标点符号
|
|
|
|
String punctuationPattern = "[\\p{Punct}]";
|
|
|
|
return content.replaceAll("[,。、?!:;,.?!:'“”’‘]", "");
|
|
|
|
// 创建一个 Pattern 对象
|
|
|
|
|
|
|
|
Pattern pattern = Pattern.compile(punctuationPattern);
|
|
|
|
|
|
|
|
// 创建一个 Matcher 对象
|
|
|
|
|
|
|
|
Matcher matcher = pattern.matcher(originalContent);
|
|
|
|
|
|
|
|
// 使用 Matcher 的 replaceAll 方法替换所有匹配的标点符号为 ""
|
|
|
|
|
|
|
|
return matcher.replaceAll("");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|