Search in sources :

Example 21 with LocationName

use of com.google.cloud.security.privateca.v1.LocationName in project java-aiplatform by googleapis.

the class CreateDatasetTabularGcsSample method createDatasetTableGcs.

static void createDatasetTableGcs(String project, String datasetDisplayName, String gcsSourceUri) throws IOException, ExecutionException, InterruptedException, TimeoutException {
    DatasetServiceSettings settings = DatasetServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (DatasetServiceClient datasetServiceClient = DatasetServiceClient.create(settings)) {
        String location = "us-central1";
        String metadataSchemaUri = "gs://google-cloud-aiplatform/schema/dataset/metadata/tables_1.0.0.yaml";
        LocationName locationName = LocationName.of(project, location);
        String jsonString = "{\"input_config\": {\"gcs_source\": {\"uri\": [\"" + gcsSourceUri + "\"]}}}";
        Value.Builder metaData = Value.newBuilder();
        JsonFormat.parser().merge(jsonString, metaData);
        Dataset dataset = Dataset.newBuilder().setDisplayName(datasetDisplayName).setMetadataSchemaUri(metadataSchemaUri).setMetadata(metaData).build();
        OperationFuture<Dataset, CreateDatasetOperationMetadata> datasetFuture = datasetServiceClient.createDatasetAsync(locationName, dataset);
        System.out.format("Operation name: %s\n", datasetFuture.getInitialFuture().get().getName());
        System.out.println("Waiting for operation to finish...");
        Dataset datasetResponse = datasetFuture.get(300, TimeUnit.SECONDS);
        System.out.println("Create Dataset Table GCS sample");
        System.out.format("Name: %s\n", datasetResponse.getName());
        System.out.format("Display Name: %s\n", datasetResponse.getDisplayName());
        System.out.format("Metadata Schema Uri: %s\n", datasetResponse.getMetadataSchemaUri());
        System.out.format("Metadata: %s\n", datasetResponse.getMetadata());
    }
}
Also used : DatasetServiceSettings(com.google.cloud.aiplatform.v1.DatasetServiceSettings) CreateDatasetOperationMetadata(com.google.cloud.aiplatform.v1.CreateDatasetOperationMetadata) Dataset(com.google.cloud.aiplatform.v1.Dataset) DatasetServiceClient(com.google.cloud.aiplatform.v1.DatasetServiceClient) Value(com.google.protobuf.Value) LocationName(com.google.cloud.aiplatform.v1.LocationName)

Example 22 with LocationName

use of com.google.cloud.security.privateca.v1.LocationName in project google-cloud-java by googleapis.

the class TranslateSnippetsBeta method translateTextWithGlossary.

// [END translate_get_glossary_beta]
/**
 * Translates a given text using a glossary.
 *
 * @param projectId - Id of the project.
 * @param location - location name.
 * @param name - Glossary name.
 * @param text - Text to be translated. e.g. "Hello World!"
 * @param sourceLanguageCode - Language code of text. e.g. "en"
 * @param targetLanguageCode - Language code for translation. e.g. "sr"
 */
// [START translate_translate_text_with_glossary_beta]
static TranslateTextResponse translateTextWithGlossary(String projectId, String location, String name, String text, String sourceLanguageCode, String targetLanguageCode) {
    try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
        LocationName locationName = LocationName.newBuilder().setProject(projectId).setLocation(location).build();
        GlossaryName glossaryName = GlossaryName.newBuilder().setProject(projectId).setLocation(location).setGlossary(name).build();
        TranslateTextGlossaryConfig translateTextGlossaryConfig = TranslateTextGlossaryConfig.newBuilder().setGlossary(glossaryName.toString()).build();
        TranslateTextRequest translateTextRequest = TranslateTextRequest.newBuilder().setParent(locationName.toString()).setMimeType("text/plain").setSourceLanguageCode(sourceLanguageCode).setTargetLanguageCode(targetLanguageCode).addContents(text).setGlossaryConfig(translateTextGlossaryConfig).build();
        // Call the API
        TranslateTextResponse response = translationServiceClient.translateText(translateTextRequest);
        System.out.format("Translated text: %s", response.getGlossaryTranslationsList().get(0).getTranslatedText());
        return response;
    } catch (Exception e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : TranslationServiceClient(com.google.cloud.translate.v3beta1.TranslationServiceClient) BatchTranslateTextRequest(com.google.cloud.translate.v3beta1.BatchTranslateTextRequest) TranslateTextRequest(com.google.cloud.translate.v3beta1.TranslateTextRequest) GlossaryName(com.google.cloud.translate.v3beta1.GlossaryName) TranslateTextGlossaryConfig(com.google.cloud.translate.v3beta1.TranslateTextGlossaryConfig) TranslateTextResponse(com.google.cloud.translate.v3beta1.TranslateTextResponse) LocationName(com.google.cloud.translate.v3beta1.LocationName)

Example 23 with LocationName

use of com.google.cloud.security.privateca.v1.LocationName in project google-cloud-java by googleapis.

the class TranslateSnippetsBeta method detectLanguageOfText.

// [END translate_list_language_names_beta]
/**
 * Detects the language of a given text.
 *
 * @param projectId - Id of the project.
 * @param location - location name.
 * @param text - Text for detection
 */
// [START translate_detect_language_beta]
static DetectLanguageResponse detectLanguageOfText(String projectId, String location, String text) {
    try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
        LocationName locationName = LocationName.newBuilder().setProject(projectId).setLocation(location).build();
        DetectLanguageRequest detectLanguageRequest = DetectLanguageRequest.newBuilder().setParent(locationName.toString()).setMimeType("text/plain").setContent(text).build();
        // Call the API
        DetectLanguageResponse response = translationServiceClient.detectLanguage(detectLanguageRequest);
        System.out.format("Detected Language Code: %s", response.getLanguages(0).getLanguageCode());
        return response;
    } catch (Exception e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : TranslationServiceClient(com.google.cloud.translate.v3beta1.TranslationServiceClient) DetectLanguageResponse(com.google.cloud.translate.v3beta1.DetectLanguageResponse) DetectLanguageRequest(com.google.cloud.translate.v3beta1.DetectLanguageRequest) LocationName(com.google.cloud.translate.v3beta1.LocationName)

Example 24 with LocationName

use of com.google.cloud.security.privateca.v1.LocationName in project google-cloud-java by googleapis.

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 25 with LocationName

use of com.google.cloud.security.privateca.v1.LocationName in project google-cloud-java by GoogleCloudPlatform.

the class TranslateSnippetsBeta method translateTextWithGlossary.

// [END translate_get_glossary_beta]
/**
 * Translates a given text using a glossary.
 *
 * @param projectId - Id of the project.
 * @param location - location name.
 * @param name - Glossary name.
 * @param text - Text to be translated. e.g. "Hello World!"
 * @param sourceLanguageCode - Language code of text. e.g. "en"
 * @param targetLanguageCode - Language code for translation. e.g. "sr"
 */
// [START translate_translate_text_with_glossary_beta]
static TranslateTextResponse translateTextWithGlossary(String projectId, String location, String name, String text, String sourceLanguageCode, String targetLanguageCode) {
    try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
        LocationName locationName = LocationName.newBuilder().setProject(projectId).setLocation(location).build();
        GlossaryName glossaryName = GlossaryName.newBuilder().setProject(projectId).setLocation(location).setGlossary(name).build();
        TranslateTextGlossaryConfig translateTextGlossaryConfig = TranslateTextGlossaryConfig.newBuilder().setGlossary(glossaryName.toString()).build();
        TranslateTextRequest translateTextRequest = TranslateTextRequest.newBuilder().setParent(locationName.toString()).setMimeType("text/plain").setSourceLanguageCode(sourceLanguageCode).setTargetLanguageCode(targetLanguageCode).addContents(text).setGlossaryConfig(translateTextGlossaryConfig).build();
        // Call the API
        TranslateTextResponse response = translationServiceClient.translateText(translateTextRequest);
        System.out.format("Translated text: %s", response.getGlossaryTranslationsList().get(0).getTranslatedText());
        return response;
    } catch (Exception e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : TranslationServiceClient(com.google.cloud.translate.v3beta1.TranslationServiceClient) BatchTranslateTextRequest(com.google.cloud.translate.v3beta1.BatchTranslateTextRequest) TranslateTextRequest(com.google.cloud.translate.v3beta1.TranslateTextRequest) GlossaryName(com.google.cloud.translate.v3beta1.GlossaryName) TranslateTextGlossaryConfig(com.google.cloud.translate.v3beta1.TranslateTextGlossaryConfig) TranslateTextResponse(com.google.cloud.translate.v3beta1.TranslateTextResponse) LocationName(com.google.cloud.translate.v3beta1.LocationName)

Aggregations

LocationName (com.google.cloud.aiplatform.v1.LocationName)36 Test (org.junit.Test)36 LocationName (com.google.privacy.dlp.v2.LocationName)22 OrganizationLocationName (com.google.privacy.dlp.v2.OrganizationLocationName)22 AbstractMessage (com.google.protobuf.AbstractMessage)19 LocationName (com.google.cloud.translate.v3beta1.LocationName)18 TranslationServiceClient (com.google.cloud.translate.v3beta1.TranslationServiceClient)18 AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)17 LocationName (com.google.cloud.automl.v1.LocationName)17 JobServiceClient (com.google.cloud.aiplatform.v1.JobServiceClient)15 JobServiceSettings (com.google.cloud.aiplatform.v1.JobServiceSettings)15 Value (com.google.protobuf.Value)15 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)14 Model (com.google.cloud.aiplatform.v1.Model)14 StatusRuntimeException (io.grpc.StatusRuntimeException)14 PipelineServiceClient (com.google.cloud.aiplatform.v1.PipelineServiceClient)13 PipelineServiceSettings (com.google.cloud.aiplatform.v1.PipelineServiceSettings)13 TrainingPipeline (com.google.cloud.aiplatform.v1.TrainingPipeline)13 LocationName (com.google.cloud.translate.v3.LocationName)13 TranslationServiceClient (com.google.cloud.translate.v3.TranslationServiceClient)13