This repository has been archived by the owner on Sep 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathListTrainingPhrases.java
66 lines (57 loc) · 2.53 KB
/
ListTrainingPhrases.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dialogflow.cx;
// [START dialogflow_list_training_phrases]
import com.google.cloud.dialogflow.cx.v3.GetIntentRequest;
import com.google.cloud.dialogflow.cx.v3.Intent;
import com.google.cloud.dialogflow.cx.v3.IntentName;
import com.google.cloud.dialogflow.cx.v3.IntentsClient;
import java.io.IOException;
import java.util.List;
public class ListTrainingPhrases {
public static void main(String[] args) throws IOException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "my-project-id";
String location = "location";
String agentId = "my-agent-id";
String intentId = "my-intent-id";
listTrainingPhrases(projectId, location, agentId, intentId);
}
// DialogFlow API List Training Phrases sample.
public static void listTrainingPhrases(
String projectId, String location, String agentId, String intentId) throws IOException {
// Note: close() needs to be called on the IntentsClient object to clean up resources
// such as threads. In the example below, try-with-resources is used,
// which automatically calls close().
try (IntentsClient client = IntentsClient.create()) {
// Set the intent name
IntentName name = IntentName.of(projectId, location, agentId, intentId);
// Compose the get-intent request
GetIntentRequest request = GetIntentRequest.newBuilder().setName(name.toString()).build();
// Make API request to get intent
Intent response = client.getIntent(request);
// Loop through the results
for (Intent.TrainingPhrase phrase : response.getTrainingPhrasesList()) {
System.out.println("***********************************************");
List<Intent.TrainingPhrase.Part> parts = phrase.getPartsList();
for (Intent.TrainingPhrase.Part part : parts) {
System.out.println(String.format("Training Phrase: %s", part.getText()));
}
}
}
}
}
// [END dialogflow_list_training_phrases]