use of com.google.cloud.dialogflow.v2.Intent in project java-dialogflow by googleapis.
the class ITSystemTest method listIntentsTest.
@Test
public void listIntentsTest() {
ListIntentsRequest request = ListIntentsRequest.newBuilder().setParent(PROJECT_AGENT_NAME.toString()).build();
for (Intent actualIntent : intentsClient.listIntents(request).iterateAll()) {
if (intent.getName().equals(actualIntent.getName())) {
assertEquals(intent.getDisplayName(), actualIntent.getDisplayName());
assertEquals(intent.getAction(), actualIntent.getAction());
assertEquals(intent.getEvents(0), actualIntent.getEvents(0));
assertEquals(intent.getEventsCount(), actualIntent.getEventsCount());
}
}
}
use of com.google.cloud.dialogflow.v2.Intent in project java-dialogflow by googleapis.
the class ITSystemTest method getIntentTest.
@Test
public void getIntentTest() {
GetIntentRequest request = GetIntentRequest.newBuilder().setName(intentName.toString()).build();
Intent actualIntent = intentsClient.getIntent(request);
assertEquals(intent.getName(), actualIntent.getName());
assertEquals(intent.getDisplayName(), actualIntent.getDisplayName());
assertEquals(intent.getAction(), actualIntent.getAction());
assertEquals(intent.getEvents(0), actualIntent.getEvents(0));
assertEquals(intent.getEventsCount(), actualIntent.getEventsCount());
}
use of com.google.cloud.dialogflow.v2.Intent in project java-dialogflow by googleapis.
the class DetectIntentWithSentimentAnalysis method detectIntentSentimentAnalysis.
public static Map<String, QueryResult> detectIntentSentimentAnalysis(String projectId, List<String> texts, String sessionId, String languageCode) throws IOException, ApiException {
Map<String, QueryResult> queryResults = Maps.newHashMap();
// Instantiates a client
try (SessionsClient sessionsClient = SessionsClient.create()) {
// Set the session name using the sessionId (UUID) and projectID (my-project-id)
SessionName session = SessionName.of(projectId, sessionId);
System.out.println("Session Path: " + session.toString());
// Detect intents for each text input
for (String text : texts) {
// Set the text (hello) and language code (en-US) for the query
TextInput.Builder textInput = TextInput.newBuilder().setText(text).setLanguageCode(languageCode);
// Build the query with the TextInput
QueryInput queryInput = QueryInput.newBuilder().setText(textInput).build();
//
SentimentAnalysisRequestConfig sentimentAnalysisRequestConfig = SentimentAnalysisRequestConfig.newBuilder().setAnalyzeQueryTextSentiment(true).build();
QueryParameters queryParameters = QueryParameters.newBuilder().setSentimentAnalysisRequestConfig(sentimentAnalysisRequestConfig).build();
DetectIntentRequest detectIntentRequest = DetectIntentRequest.newBuilder().setSession(session.toString()).setQueryInput(queryInput).setQueryParams(queryParameters).build();
// Performs the detect intent request
DetectIntentResponse response = sessionsClient.detectIntent(detectIntentRequest);
// Display the query result
QueryResult queryResult = response.getQueryResult();
System.out.println("====================");
System.out.format("Query Text: '%s'\n", queryResult.getQueryText());
System.out.format("Detected Intent: %s (confidence: %f)\n", queryResult.getIntent().getDisplayName(), queryResult.getIntentDetectionConfidence());
System.out.format("Fulfillment Text: '%s'\n", queryResult.getFulfillmentMessagesCount() > 0 ? queryResult.getFulfillmentMessages(0).getText() : "Triggered Default Fallback Intent");
System.out.format("Sentiment Score: '%s'\n", queryResult.getSentimentAnalysisResult().getQueryTextSentiment().getScore());
queryResults.put(text, queryResult);
}
}
return queryResults;
}
use of com.google.cloud.dialogflow.v2.Intent in project java-dialogflow by googleapis.
the class DetectIntentWithTextToSpeechResponse method detectIntentWithTexttoSpeech.
public static Map<String, QueryResult> detectIntentWithTexttoSpeech(String projectId, List<String> texts, String sessionId, String languageCode) throws IOException, ApiException {
Map<String, QueryResult> queryResults = Maps.newHashMap();
// Instantiates a client
try (SessionsClient sessionsClient = SessionsClient.create()) {
// Set the session name using the sessionId (UUID) and projectID (my-project-id)
SessionName session = SessionName.of(projectId, sessionId);
System.out.println("Session Path: " + session.toString());
// Detect intents for each text input
for (String text : texts) {
// Set the text (hello) and language code (en-US) for the query
TextInput.Builder textInput = TextInput.newBuilder().setText(text).setLanguageCode(languageCode);
// Build the query with the TextInput
QueryInput queryInput = QueryInput.newBuilder().setText(textInput).build();
//
OutputAudioEncoding audioEncoding = OutputAudioEncoding.OUTPUT_AUDIO_ENCODING_LINEAR_16;
int sampleRateHertz = 16000;
OutputAudioConfig outputAudioConfig = OutputAudioConfig.newBuilder().setAudioEncoding(audioEncoding).setSampleRateHertz(sampleRateHertz).build();
DetectIntentRequest dr = DetectIntentRequest.newBuilder().setQueryInput(queryInput).setOutputAudioConfig(outputAudioConfig).setSession(session.toString()).build();
// Performs the detect intent request
DetectIntentResponse response = sessionsClient.detectIntent(dr);
// Display the query result
QueryResult queryResult = response.getQueryResult();
System.out.println("====================");
System.out.format("Query Text: '%s'\n", queryResult.getQueryText());
System.out.format("Detected Intent: %s (confidence: %f)\n", queryResult.getIntent().getDisplayName(), queryResult.getIntentDetectionConfidence());
System.out.format("Fulfillment Text: '%s'\n", queryResult.getFulfillmentMessagesCount() > 0 ? queryResult.getFulfillmentMessages(0).getText() : "Triggered Default Fallback Intent");
queryResults.put(text, queryResult);
}
}
return queryResults;
}
use of com.google.cloud.dialogflow.v2.Intent in project java-dialogflow by googleapis.
the class IntentManagement method listIntents.
// [START dialogflow_list_intents]
/**
* List intents
*
* @param projectId Project/Agent Id.
* @return Intents found.
*/
public static List<Intent> listIntents(String projectId) throws ApiException, IOException {
List<Intent> intents = Lists.newArrayList();
// Instantiates a client
try (IntentsClient intentsClient = IntentsClient.create()) {
// Set the project agent name using the projectID (my-project-id)
AgentName parent = AgentName.of(projectId);
// Performs the list intents request
for (Intent intent : intentsClient.listIntents(parent).iterateAll()) {
System.out.println("====================");
System.out.format("Intent name: '%s'\n", intent.getName());
System.out.format("Intent display name: '%s'\n", intent.getDisplayName());
System.out.format("Action: '%s'\n", intent.getAction());
System.out.format("Root followup intent: '%s'\n", intent.getRootFollowupIntentName());
System.out.format("Parent followup intent: '%s'\n", intent.getParentFollowupIntentName());
System.out.format("Input contexts:\n");
for (String inputContextName : intent.getInputContextNamesList()) {
System.out.format("\tName: %s\n", inputContextName);
}
System.out.format("Output contexts:\n");
for (Context outputContext : intent.getOutputContextsList()) {
System.out.format("\tName: %s\n", outputContext.getName());
}
intents.add(intent);
}
}
return intents;
}
Aggregations