Skip to content

Commit

Permalink
feat: Add Adaptive MT API (#6879)
Browse files Browse the repository at this point in the history
docs: Fixes a typo in docs
PiperOrigin-RevId: 591019768
Source-Link: googleapis/googleapis@cf5b5fc
Source-Link: googleapis/googleapis-gen@53c2d23
Copy-Tag: eyJwIjoiVHJhbnNsYXRlLy5Pd2xCb3QueWFtbCIsImgiOiI1M2MyZDIzNmExYjZhYWFlNDBhNDE0ZWZjZWExMTlkOTI1NTE4MzM1In0=
  • Loading branch information
gcf-owl-bot[bot] authored Dec 15, 2023
1 parent 0c1cbf9 commit cf2a0b7
Show file tree
Hide file tree
Showing 44 changed files with 6,509 additions and 173 deletions.
Binary file added Translate/metadata/V3/AdaptiveMt.php
Binary file not shown.
36 changes: 36 additions & 0 deletions Translate/metadata/V3/Common.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Translate/metadata/V3/TranslationService.php
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/*
* Copyright 2023 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
*
* https://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.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START translate_v3_generated_TranslationService_AdaptiveMtTranslate_sync]
use Google\ApiCore\ApiException;
use Google\Cloud\Translate\V3\AdaptiveMtTranslateResponse;
use Google\Cloud\Translate\V3\TranslationServiceClient;

/**
* Translate text using Adaptive MT.
*
* @param string $formattedParent Location to make a regional call.
*
* Format: `projects/{project-number-or-id}/locations/{location-id}`. Please see
* {@see TranslationServiceClient::locationName()} for help formatting this field.
* @param string $formattedDataset The resource name for the dataset to use for adaptive MT.
* `projects/{project}/locations/{location-id}/adaptiveMtDatasets/{dataset}`
* Please see {@see TranslationServiceClient::adaptiveMtDatasetName()} for help formatting this field.
* @param string $contentElement The content of the input in string format.
* For now only one sentence per request is supported.
*/
function adaptive_mt_translate_sample(
string $formattedParent,
string $formattedDataset,
string $contentElement
): void {
// Create a client.
$translationServiceClient = new TranslationServiceClient();

// Prepare any non-scalar elements to be passed along with the request.
$content = [$contentElement,];

// Call the API and handle any network failures.
try {
/** @var AdaptiveMtTranslateResponse $response */
$response = $translationServiceClient->adaptiveMtTranslate(
$formattedParent,
$formattedDataset,
$content
);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}

/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = TranslationServiceClient::locationName('[PROJECT]', '[LOCATION]');
$formattedDataset = TranslationServiceClient::adaptiveMtDatasetName(
'[PROJECT]',
'[LOCATION]',
'[DATASET]'
);
$contentElement = '[CONTENT]';

adaptive_mt_translate_sample($formattedParent, $formattedDataset, $contentElement);
}
// [END translate_v3_generated_TranslationService_AdaptiveMtTranslate_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/*
* Copyright 2023 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
*
* https://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.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START translate_v3_generated_TranslationService_CreateAdaptiveMtDataset_sync]
use Google\ApiCore\ApiException;
use Google\Cloud\Translate\V3\AdaptiveMtDataset;
use Google\Cloud\Translate\V3\TranslationServiceClient;

/**
* Creates an Adaptive MT dataset.
*
* @param string $formattedParent Name of the parent project. In form of
* `projects/{project-number-or-id}/locations/{location-id}`
* Please see {@see TranslationServiceClient::locationName()} for help formatting this field.
* @param string $formattedAdaptiveMtDatasetName The resource name of the dataset, in form of
* `projects/{project-number-or-id}/locations/{location_id}/adaptiveMtDatasets/{dataset_id}`
* Please see {@see TranslationServiceClient::adaptiveMtDatasetName()} for help formatting this field.
*/
function create_adaptive_mt_dataset_sample(
string $formattedParent,
string $formattedAdaptiveMtDatasetName
): void {
// Create a client.
$translationServiceClient = new TranslationServiceClient();

// Prepare any non-scalar elements to be passed along with the request.
$adaptiveMtDataset = (new AdaptiveMtDataset())
->setName($formattedAdaptiveMtDatasetName);

// Call the API and handle any network failures.
try {
/** @var AdaptiveMtDataset $response */
$response = $translationServiceClient->createAdaptiveMtDataset(
$formattedParent,
$adaptiveMtDataset
);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}

/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = TranslationServiceClient::locationName('[PROJECT]', '[LOCATION]');
$formattedAdaptiveMtDatasetName = TranslationServiceClient::adaptiveMtDatasetName(
'[PROJECT]',
'[LOCATION]',
'[DATASET]'
);

create_adaptive_mt_dataset_sample($formattedParent, $formattedAdaptiveMtDatasetName);
}
// [END translate_v3_generated_TranslationService_CreateAdaptiveMtDataset_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/*
* Copyright 2023 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
*
* https://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.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START translate_v3_generated_TranslationService_DeleteAdaptiveMtDataset_sync]
use Google\ApiCore\ApiException;
use Google\Cloud\Translate\V3\TranslationServiceClient;

/**
* Deletes an Adaptive MT dataset, including all its entries and associated
* metadata.
*
* @param string $formattedName Name of the dataset. In the form of
* `projects/{project-number-or-id}/locations/{location-id}/adaptiveMtDatasets/{adaptive-mt-dataset-id}`
* Please see {@see TranslationServiceClient::adaptiveMtDatasetName()} for help formatting this field.
*/
function delete_adaptive_mt_dataset_sample(string $formattedName): void
{
// Create a client.
$translationServiceClient = new TranslationServiceClient();

// Call the API and handle any network failures.
try {
$translationServiceClient->deleteAdaptiveMtDataset($formattedName);
printf('Call completed successfully.' . PHP_EOL);
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}

/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = TranslationServiceClient::adaptiveMtDatasetName(
'[PROJECT]',
'[LOCATION]',
'[DATASET]'
);

delete_adaptive_mt_dataset_sample($formattedName);
}
// [END translate_v3_generated_TranslationService_DeleteAdaptiveMtDataset_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/*
* Copyright 2023 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
*
* https://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.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START translate_v3_generated_TranslationService_DeleteAdaptiveMtFile_sync]
use Google\ApiCore\ApiException;
use Google\Cloud\Translate\V3\TranslationServiceClient;

/**
* Deletes an AdaptiveMtFile along with its sentences.
*
* @param string $formattedName The resource name of the file to delete, in form of
* `projects/{project-number-or-id}/locations/{location_id}/adaptiveMtDatasets/{dataset}/adaptiveMtFiles/{file}`
* Please see {@see TranslationServiceClient::adaptiveMtFileName()} for help formatting this field.
*/
function delete_adaptive_mt_file_sample(string $formattedName): void
{
// Create a client.
$translationServiceClient = new TranslationServiceClient();

// Call the API and handle any network failures.
try {
$translationServiceClient->deleteAdaptiveMtFile($formattedName);
printf('Call completed successfully.' . PHP_EOL);
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}

/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = TranslationServiceClient::adaptiveMtFileName(
'[PROJECT]',
'[LOCATION]',
'[DATASET]',
'[FILE]'
);

delete_adaptive_mt_file_sample($formattedName);
}
// [END translate_v3_generated_TranslationService_DeleteAdaptiveMtFile_sync]
Loading

0 comments on commit cf2a0b7

Please sign in to comment.