use of com.mizhousoft.cloudsdk.nlp.RecognitionResult in project cloud-sdk by mizhousoft.
the class TestSensitiveWordsRecognitionServiceImpl method testRecognizes.
@Test
public void testRecognizes() {
String text1 = "ddddddddddddddddddd";
String text2 = "ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd我的敏感词包二奶仓井空";
text1 = StringUtils.leftPad(text1, 1950, "0");
try {
RecognitionResult result = this.sensitiveWordsRecognitionService.recognize(text1, text2);
Assert.assertTrue(result.isContainSensitiveWord());
} catch (CloudSDKException e) {
Assert.fail(e.getMessage());
}
}
use of com.mizhousoft.cloudsdk.nlp.RecognitionResult in project cloud-sdk by mizhousoft.
the class SensitiveWordsRecognitionServiceImpl method recognize.
/**
* {@inheritDoc}
*/
@Override
public RecognitionResult recognize(String... texts) throws CloudSDKException {
RecognitionResult result = new RecognitionResult();
if (ArrayUtils.isEmpty(texts)) {
return result;
}
StringBuilder buffer = new StringBuilder(100);
for (String text : texts) {
if (!StringUtils.isBlank(text)) {
buffer.append(text.trim());
}
}
String value = buffer.toString();
while (true) {
if (value.length() > MAX_TEXT_LENGTH) {
String data = value.substring(0, MAX_TEXT_LENGTH);
result = recognizeOne(data);
if (result.isContainSensitiveWord()) {
break;
} else {
value = value.substring(MAX_TEXT_LENGTH);
}
} else {
result = recognizeOne(value);
break;
}
}
return result;
}
use of com.mizhousoft.cloudsdk.nlp.RecognitionResult in project cloud-sdk by mizhousoft.
the class SensitiveWordsRecognitionServiceImpl method recognizeOne.
public RecognitionResult recognizeOne(String text) throws CloudSDKException {
RecognitionResult result = new RecognitionResult();
if (StringUtils.isBlank(text)) {
return result;
}
try {
SensitiveWordsRecognitionRequest request = new SensitiveWordsRecognitionRequest();
request.setText(text);
SensitiveWordsRecognitionResponse resp = nlpClient.SensitiveWordsRecognition(request);
String[] words = resp.getSensitiveWords();
if (!ArrayUtils.isEmpty(words)) {
result.setSensitiveWords(Arrays.asList(words));
}
} catch (TencentCloudSDKException e) {
throw new CloudSDKException(e.getMessage(), e);
}
return result;
}
use of com.mizhousoft.cloudsdk.nlp.RecognitionResult in project cloud-sdk by mizhousoft.
the class TestSensitiveWordsRecognitionServiceImpl method testRecognize.
@Test
public void testRecognize() {
String text = "我的敏感词包二奶仓井空";
try {
RecognitionResult result = this.sensitiveWordsRecognitionService.recognize(text);
Assert.assertTrue(result.isContainSensitiveWord());
} catch (CloudSDKException e) {
Assert.fail(e.getMessage());
}
}
Aggregations