|
|
@@ -23,28 +23,25 @@ public class DmWordProcessServiceImpl implements IDmWordProcessService { |
|
|
|
|
|
|
|
public WordProcessVo semanticIntegrityDetection (WordProcessVo wordProcessVo){ |
|
|
|
log.info("元数据:" + wordProcessVo.getMetadata()); |
|
|
|
String body = "grant_type=client_credentials&client_id=" + baiduConfig.getApiKey() + "&client_secret=" + baiduConfig.getSecretKey(); |
|
|
|
JSONObject accessJson = remoteBaiduNLPService.getAccessToken(body); |
|
|
|
JSONObject accessJson = remoteBaiduNLPService.getAccessToken(baiduConfig.getApiKey(), baiduConfig.getSecretKey(), "client_credentials"); |
|
|
|
JSONObject result = remoteBaiduNLPService.detected("UTF-8", accessJson.getString("access_token"), "{\"text\":\"" + wordProcessVo.getMetadata() + "\"}"); |
|
|
|
if(result.containsKey("ppl")){ |
|
|
|
if(result != null){ |
|
|
|
if(result.containsKey("error_code")){ |
|
|
|
String errorMsg = String.format("语义完整性检测失败,错误码:%d,错误信息:%s", result.getInteger("error_code"),result.getString("error_msg")); |
|
|
|
log.error(errorMsg); |
|
|
|
if(result != null){ |
|
|
|
if(result.containsKey("error_code")){ |
|
|
|
String errorMsg = String.format("语义完整性检测失败,错误码:%d,错误信息:%s", result.getInteger("error_code"),result.getString("error_msg")); |
|
|
|
log.error(errorMsg); |
|
|
|
}else{ |
|
|
|
Double ppl = result.getDouble("ppl"); |
|
|
|
if(ppl < 300) { |
|
|
|
wordProcessVo.setProcessedResult("2"); |
|
|
|
}else if(ppl > 1000){ |
|
|
|
wordProcessVo.setProcessedResult("0"); |
|
|
|
}else{ |
|
|
|
Double ppl = result.getDouble("ppl"); |
|
|
|
if(ppl < 300) { |
|
|
|
wordProcessVo.setProcessedResult("2"); |
|
|
|
}else if(ppl > 1000){ |
|
|
|
wordProcessVo.setProcessedResult("0"); |
|
|
|
}else{ |
|
|
|
wordProcessVo.setProcessedResult("1"); |
|
|
|
} |
|
|
|
log.info("语义完整性检测结果:" + wordProcessVo.getProcessedResult()); |
|
|
|
wordProcessVo.setProcessedResult("1"); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
log.error("语义完整性检测失败,未获取到返回结果"); |
|
|
|
log.info("语义完整性检测结果:" + wordProcessVo.getProcessedResult()); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
log.error("语义完整性检测失败,未获取到返回结果"); |
|
|
|
} |
|
|
|
return wordProcessVo; |
|
|
|
} |
|
|
|