Search in sources :

Example 11 with GlossaryName

use of com.google.cloud.translate.v3.GlossaryName in project java-translate by googleapis.

the class GetGlossary method getGlossary.

// Get a particular glossary based on the glossary ID
public static void getGlossary(String projectId, String glossaryId) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (TranslationServiceClient client = TranslationServiceClient.create()) {
        // Supported Locations: `global`, [glossary location], or [model location]
        // Glossaries must be hosted in `us-central1`
        // Custom Models must use the same location as your model. (us-central1)
        GlossaryName glossaryName = GlossaryName.of(projectId, "us-central1", glossaryId);
        GetGlossaryRequest request = GetGlossaryRequest.newBuilder().setName(glossaryName.toString()).build();
        Glossary response = client.getGlossary(request);
        System.out.printf("Glossary name: %s\n", response.getName());
        System.out.printf("Entry count: %s\n", response.getEntryCount());
        System.out.printf("Input URI: %s\n", response.getInputConfig().getGcsSource().getInputUri());
    }
}
Also used : GetGlossaryRequest(com.google.cloud.translate.v3.GetGlossaryRequest) TranslationServiceClient(com.google.cloud.translate.v3.TranslationServiceClient) Glossary(com.google.cloud.translate.v3.Glossary) GlossaryName(com.google.cloud.translate.v3.GlossaryName)

Example 12 with GlossaryName

use of com.google.cloud.translate.v3.GlossaryName in project google-cloud-java by GoogleCloudPlatform.

the class TranslateSnippetsBeta method createGlossary.

// [END translate_batch_translate_text_beta]
/**
 * Creates a glossary.
 *
 * @param projectId - Id of the project.
 * @param location - location name.
 * @param name - Glossary name.
 * @param gcsUri - Google Cloud Storage URI where glossary is stored in csv format.
 */
// [START translate_create_glossary_beta]
static Glossary createGlossary(String projectId, String location, String name, String gcsUri) {
    try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
        LocationName locationName = LocationName.newBuilder().setProject(projectId).setLocation(location).build();
        LanguageCodesSet languageCodesSet = LanguageCodesSet.newBuilder().addLanguageCodes("en").addLanguageCodes("es").build();
        GcsSource gcsSource = GcsSource.newBuilder().setInputUri(gcsUri).build();
        GlossaryInputConfig glossaryInputConfig = GlossaryInputConfig.newBuilder().setGcsSource(gcsSource).build();
        GlossaryName glossaryName = GlossaryName.newBuilder().setProject(projectId).setLocation(location).setGlossary(name).build();
        Glossary glossary = Glossary.newBuilder().setLanguageCodesSet(languageCodesSet).setInputConfig(glossaryInputConfig).setName(glossaryName.toString()).build();
        CreateGlossaryRequest request = CreateGlossaryRequest.newBuilder().setParent(locationName.toString()).setGlossary(glossary).build();
        // Call the API
        Glossary response = translationServiceClient.createGlossaryAsync(request).get(300, TimeUnit.SECONDS);
        System.out.format("Created: %s\n", response.getName());
        System.out.format("Input Uri: %s\n", response.getInputConfig().getGcsSource());
        return response;
    } catch (Exception e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : LanguageCodesSet(com.google.cloud.translate.v3beta1.Glossary.LanguageCodesSet) TranslationServiceClient(com.google.cloud.translate.v3beta1.TranslationServiceClient) GcsSource(com.google.cloud.translate.v3beta1.GcsSource) CreateGlossaryRequest(com.google.cloud.translate.v3beta1.CreateGlossaryRequest) GlossaryInputConfig(com.google.cloud.translate.v3beta1.GlossaryInputConfig) Glossary(com.google.cloud.translate.v3beta1.Glossary) GlossaryName(com.google.cloud.translate.v3beta1.GlossaryName) LocationName(com.google.cloud.translate.v3beta1.LocationName)

Example 13 with GlossaryName

use of com.google.cloud.translate.v3.GlossaryName in project google-cloud-java by GoogleCloudPlatform.

the class TranslateSnippetsBeta method deleteGlossary.

// [END translate_translate_text_with_glossary_beta]
/**
 * Deletes a glossary.
 *
 * @param projectId - Id of the project.
 * @param location - location name.
 * @param name - Glossary name.
 */
// [START translate_delete_glossary_beta]
static DeleteGlossaryResponse deleteGlossary(String projectId, String location, String name) {
    try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
        GlossaryName glossaryName = GlossaryName.newBuilder().setProject(projectId).setLocation(location).setGlossary(name).build();
        // Call the API
        DeleteGlossaryResponse response = translationServiceClient.deleteGlossaryAsync(glossaryName.toString()).get(300, TimeUnit.SECONDS);
        System.out.format("Deleted: %s\n", response.getName());
        return response;
    } catch (Exception e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : DeleteGlossaryResponse(com.google.cloud.translate.v3beta1.DeleteGlossaryResponse) TranslationServiceClient(com.google.cloud.translate.v3beta1.TranslationServiceClient) GlossaryName(com.google.cloud.translate.v3beta1.GlossaryName)

Example 14 with GlossaryName

use of com.google.cloud.translate.v3.GlossaryName in project google-cloud-java by googleapis.

the class TranslateSnippetsBeta method getGlossary.

// [END translate_list_glossary_beta]
/**
 * Retrieves a glossary.
 *
 * @param projectId - Id of the project.
 * @param location - location name.
 * @param name - Glossary name.
 */
// [START translate_get_glossary_beta]
static Glossary getGlossary(String projectId, String location, String name) {
    try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
        GlossaryName glossaryName = GlossaryName.newBuilder().setProject(projectId).setLocation(location).setGlossary(name).build();
        // Call the API
        Glossary response = translationServiceClient.getGlossary(glossaryName.toString());
        System.out.format("Got: %s\n", response.getName());
        return response;
    } catch (Exception e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : TranslationServiceClient(com.google.cloud.translate.v3beta1.TranslationServiceClient) Glossary(com.google.cloud.translate.v3beta1.Glossary) GlossaryName(com.google.cloud.translate.v3beta1.GlossaryName)

Example 15 with GlossaryName

use of com.google.cloud.translate.v3.GlossaryName in project google-cloud-java by googleapis.

the class TranslateSnippetsBeta method deleteGlossary.

// [END translate_translate_text_with_glossary_beta]
/**
 * Deletes a glossary.
 *
 * @param projectId - Id of the project.
 * @param location - location name.
 * @param name - Glossary name.
 */
// [START translate_delete_glossary_beta]
static DeleteGlossaryResponse deleteGlossary(String projectId, String location, String name) {
    try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
        GlossaryName glossaryName = GlossaryName.newBuilder().setProject(projectId).setLocation(location).setGlossary(name).build();
        // Call the API
        DeleteGlossaryResponse response = translationServiceClient.deleteGlossaryAsync(glossaryName.toString()).get(300, TimeUnit.SECONDS);
        System.out.format("Deleted: %s\n", response.getName());
        return response;
    } catch (Exception e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : DeleteGlossaryResponse(com.google.cloud.translate.v3beta1.DeleteGlossaryResponse) TranslationServiceClient(com.google.cloud.translate.v3beta1.TranslationServiceClient) GlossaryName(com.google.cloud.translate.v3beta1.GlossaryName)

Aggregations

GlossaryName (com.google.cloud.translate.v3beta1.GlossaryName)8 TranslationServiceClient (com.google.cloud.translate.v3beta1.TranslationServiceClient)8 GlossaryName (com.google.cloud.translate.v3.GlossaryName)7 TranslationServiceClient (com.google.cloud.translate.v3.TranslationServiceClient)7 LocationName (com.google.cloud.translate.v3.LocationName)5 TranslateTextGlossaryConfig (com.google.cloud.translate.v3.TranslateTextGlossaryConfig)4 Glossary (com.google.cloud.translate.v3beta1.Glossary)4 LocationName (com.google.cloud.translate.v3beta1.LocationName)4 GcsSource (com.google.cloud.translate.v3.GcsSource)3 BatchTranslateMetadata (com.google.cloud.translate.v3.BatchTranslateMetadata)2 BatchTranslateResponse (com.google.cloud.translate.v3.BatchTranslateResponse)2 BatchTranslateTextRequest (com.google.cloud.translate.v3.BatchTranslateTextRequest)2 GcsDestination (com.google.cloud.translate.v3.GcsDestination)2 Glossary (com.google.cloud.translate.v3.Glossary)2 InputConfig (com.google.cloud.translate.v3.InputConfig)2 OutputConfig (com.google.cloud.translate.v3.OutputConfig)2 TranslateTextRequest (com.google.cloud.translate.v3.TranslateTextRequest)2 TranslateTextResponse (com.google.cloud.translate.v3.TranslateTextResponse)2 Translation (com.google.cloud.translate.v3.Translation)2 BatchTranslateTextRequest (com.google.cloud.translate.v3beta1.BatchTranslateTextRequest)2