use of com.google.cloud.dialogflow.v2beta1.DocumentName in project java-dialogflow by googleapis.
the class DetectIntentKnowledgeTest method testDetectIntentKnowledge.
@Test
public void testDetectIntentKnowledge() throws Exception {
KnowledgeBaseName knowledgeBaseName = KnowledgeBaseName.newBuilder().setProject(PROJECT_ID).setKnowledgeBase(TEST_KNOWLEDGE_BASE_ID).build();
DocumentName documentName = DocumentName.newBuilder().setProject(PROJECT_ID).setKnowledgeBase(TEST_KNOWLEDGE_BASE_ID).setDocument(TEST_DOCUMENT_ID).build();
Map<String, KnowledgeAnswers> allAnswers = DetectIntentKnowledge.detectIntentKnowledge(PROJECT_ID, knowledgeBaseName.toString(), SESSION_ID, LANGUAGE_CODE, TEXTS);
assertEquals(TEXTS.size(), allAnswers.size());
int answersFound = 0;
for (String text : TEXTS) {
KnowledgeAnswers knowledgeAnswers = allAnswers.get(text);
if (knowledgeAnswers.getAnswersCount() > 0) {
Answer answer = knowledgeAnswers.getAnswers(0);
if (text.equals(answer.getFaqQuestion()) && documentName.toString().equals(answer.getSource())) {
answersFound++;
}
}
}
// To make the test less flaky, check that half of the texts got a result.
assertThat(answersFound).isGreaterThan(TEXTS.size() / 2);
}
Aggregations