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