Skip to content

Commit

Permalink
samples: update shared config (#2443)
Browse files Browse the repository at this point in the history
* update shared config

* Update to 1.0.13

* lint

* Fix linting

* lint

* fix imports

Co-authored-by: Les Vogel <lesv@users.noreply.github.com>
  • Loading branch information
2 people authored and Shabirmean committed Nov 18, 2022
1 parent bd07453 commit b1e9793
Show file tree
Hide file tree
Showing 27 changed files with 13 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.google.cloud.translate.v3.LocationName;
import com.google.cloud.translate.v3.OutputConfig;
import com.google.cloud.translate.v3.TranslationServiceClient;

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
Expand All @@ -54,7 +53,7 @@ public static void batchTranslateText(
String targetLanguage,
String inputUri,
String outputUri)
throws IOException, ExecutionException, InterruptedException, TimeoutException {
throws IOException, ExecutionException, InterruptedException, TimeoutException {

// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.google.cloud.translate.v3.OutputConfig;
import com.google.cloud.translate.v3.TranslateTextGlossaryConfig;
import com.google.cloud.translate.v3.TranslationServiceClient;

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.google.cloud.translate.v3.OutputConfig;
import com.google.cloud.translate.v3.TranslateTextGlossaryConfig;
import com.google.cloud.translate.v3.TranslationServiceClient;

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.google.cloud.translate.v3.LocationName;
import com.google.cloud.translate.v3.OutputConfig;
import com.google.cloud.translate.v3.TranslationServiceClient;

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -57,7 +56,7 @@ public static void batchTranslateTextWithModel(
String inputUri,
String outputUri,
String modelId)
throws IOException, ExecutionException, InterruptedException, TimeoutException {
throws IOException, ExecutionException, InterruptedException, TimeoutException {

// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.google.cloud.translate.v3.GlossaryName;
import com.google.cloud.translate.v3.LocationName;
import com.google.cloud.translate.v3.TranslationServiceClient;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.google.cloud.translate.v3.DeleteGlossaryResponse;
import com.google.cloud.translate.v3.GlossaryName;
import com.google.cloud.translate.v3.TranslationServiceClient;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.google.cloud.translate.v3.DetectedLanguage;
import com.google.cloud.translate.v3.LocationName;
import com.google.cloud.translate.v3.TranslationServiceClient;

import java.io.IOException;

public class DetectLanguage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.google.cloud.translate.v3.Glossary;
import com.google.cloud.translate.v3.GlossaryName;
import com.google.cloud.translate.v3.TranslationServiceClient;

import java.io.IOException;

public class GetGlossary {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.google.cloud.translate.v3.SupportedLanguage;
import com.google.cloud.translate.v3.SupportedLanguages;
import com.google.cloud.translate.v3.TranslationServiceClient;

import java.io.IOException;

public class GetSupportedLanguages {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.google.cloud.translate.v3.SupportedLanguage;
import com.google.cloud.translate.v3.SupportedLanguages;
import com.google.cloud.translate.v3.TranslationServiceClient;

import java.io.IOException;

public class GetSupportedLanguagesForTarget {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.google.cloud.translate.v3.ListGlossariesRequest;
import com.google.cloud.translate.v3.LocationName;
import com.google.cloud.translate.v3.TranslationServiceClient;

import java.io.IOException;

public class ListGlossaries {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ public static void main(String... args) throws Exception {
// Translates some text into Russian
Translation translation =
translate.translate(
text,
TranslateOption.sourceLanguage("en"),
TranslateOption.targetLanguage("ru"));

text, TranslateOption.sourceLanguage("en"), TranslateOption.targetLanguage("ru"));

System.out.printf("Text: %s%n", text);
System.out.printf("Translation: %s%n", translation.getTranslatedText());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.google.cloud.translate.v3.TranslateTextResponse;
import com.google.cloud.translate.v3.Translation;
import com.google.cloud.translate.v3.TranslationServiceClient;

import java.io.IOException;

public class TranslateText {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.google.cloud.translate.v3.TranslateTextResponse;
import com.google.cloud.translate.v3.Translation;
import com.google.cloud.translate.v3.TranslationServiceClient;

import java.io.IOException;

public class TranslateTextWithGlossary {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.google.cloud.translate.v3.TranslateTextResponse;
import com.google.cloud.translate.v3.Translation;
import com.google.cloud.translate.v3.TranslationServiceClient;

import java.io.IOException;

public class TranslateTextWithGlossaryAndModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.google.cloud.translate.v3.TranslateTextResponse;
import com.google.cloud.translate.v3.Translation;
import com.google.cloud.translate.v3.TranslationServiceClient;

import java.io.IOException;

public class TranslateTextWithModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@
import com.google.cloud.storage.Blob;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;

import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
Expand All @@ -46,7 +44,7 @@ public class BatchTranslateTextTests {
private static final String INPUT_URI = "gs://cloud-samples-data/translation/text.txt";
private static final String PREFIX = "BATCH_TRANSLATION_OUTPUT/";
private static final String OUTPUT_URI =
String.format("gs://%s/%s%s/", PROJECT_ID, PREFIX, UUID.randomUUID());
String.format("gs://%s/%s%s/", PROJECT_ID, PREFIX, UUID.randomUUID());

private ByteArrayOutputStream bout;
private PrintStream out;
Expand Down Expand Up @@ -105,8 +103,7 @@ public void tearDown() {
@Test
public void testBatchTranslateText()
throws InterruptedException, ExecutionException, IOException, TimeoutException {
BatchTranslateText.batchTranslateText(
PROJECT_ID, "en", "es", INPUT_URI, OUTPUT_URI);
BatchTranslateText.batchTranslateText(PROJECT_ID, "en", "es", INPUT_URI, OUTPUT_URI);
String got = bout.toString();
assertThat(got).contains("Total Characters: 13");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,10 @@
import static com.google.common.truth.Truth.assertThat;
import static junit.framework.TestCase.assertNotNull;

import com.google.api.gax.longrunning.OperationFuture;
import com.google.api.gax.paging.Page;
import com.google.cloud.storage.Blob;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;
import com.google.cloud.translate.v3.CreateGlossaryMetadata;
import com.google.cloud.translate.v3.CreateGlossaryRequest;
import com.google.cloud.translate.v3.DeleteGlossaryMetadata;
import com.google.cloud.translate.v3.DeleteGlossaryRequest;
import com.google.cloud.translate.v3.DeleteGlossaryResponse;
import com.google.cloud.translate.v3.GcsSource;
import com.google.cloud.translate.v3.Glossary;
import com.google.cloud.translate.v3.GlossaryInputConfig;
import com.google.cloud.translate.v3.GlossaryName;
import com.google.cloud.translate.v3.LocationName;
import com.google.cloud.translate.v3.TranslationServiceClient;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
Expand All @@ -44,7 +31,6 @@
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;

import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
Expand All @@ -66,7 +52,7 @@ public class BatchTranslateTextWithGlossaryAndModelTests {
"gs://cloud-samples-data/translation/glossary_ja.csv";
private static final String PREFIX = "BATCH_TRANSLATION_OUTPUT/";
private static final String OUTPUT_URI =
String.format("gs://%s/%s%s/", PROJECT_ID, PREFIX, UUID.randomUUID());
String.format("gs://%s/%s%s/", PROJECT_ID, PREFIX, UUID.randomUUID());

private ByteArrayOutputStream bout;
private PrintStream out;
Expand Down Expand Up @@ -136,13 +122,7 @@ public void tearDown() throws InterruptedException, ExecutionException, IOExcept
public void testBatchTranslateTextWithGlossaryAndModel()
throws InterruptedException, ExecutionException, IOException, TimeoutException {
BatchTranslateTextWithGlossaryAndModel.batchTranslateTextWithGlossaryAndModel(
PROJECT_ID,
"en",
"ja",
INPUT_URI,
OUTPUT_URI,
GLOSSARY_ID,
MODEL_ID);
PROJECT_ID, "en", "ja", INPUT_URI, OUTPUT_URI, GLOSSARY_ID, MODEL_ID);
String got = bout.toString();
assertThat(got).contains("Total Characters: 25");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,10 @@
import static com.google.common.truth.Truth.assertThat;
import static junit.framework.TestCase.assertNotNull;

import com.google.api.gax.longrunning.OperationFuture;
import com.google.api.gax.paging.Page;
import com.google.cloud.storage.Blob;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;
import com.google.cloud.translate.v3.CreateGlossaryMetadata;
import com.google.cloud.translate.v3.CreateGlossaryRequest;
import com.google.cloud.translate.v3.DeleteGlossaryMetadata;
import com.google.cloud.translate.v3.DeleteGlossaryRequest;
import com.google.cloud.translate.v3.DeleteGlossaryResponse;
import com.google.cloud.translate.v3.GcsSource;
import com.google.cloud.translate.v3.Glossary;
import com.google.cloud.translate.v3.GlossaryInputConfig;
import com.google.cloud.translate.v3.GlossaryName;
import com.google.cloud.translate.v3.LocationName;
import com.google.cloud.translate.v3.TranslationServiceClient;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
Expand All @@ -44,7 +31,6 @@
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;

import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
Expand All @@ -65,7 +51,7 @@ public class BatchTranslateTextWithGlossaryTests {
String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26));
private static final String PREFIX = "BATCH_TRANSLATION_OUTPUT/";
private static final String OUTPUT_URI =
String.format("gs://%s/%s%s/", PROJECT_ID, PREFIX, UUID.randomUUID());
String.format("gs://%s/%s%s/", PROJECT_ID, PREFIX, UUID.randomUUID());

private ByteArrayOutputStream bout;
private PrintStream out;
Expand Down Expand Up @@ -136,12 +122,7 @@ public void tearDown() throws InterruptedException, ExecutionException, IOExcept
public void testBatchTranslateTextWithGlossary()
throws InterruptedException, ExecutionException, IOException, TimeoutException {
BatchTranslateTextWithGlossary.batchTranslateTextWithGlossary(
PROJECT_ID,
"en",
"ja",
INPUT_URI,
OUTPUT_URI,
GLOSSARY_ID);
PROJECT_ID, "en", "ja", INPUT_URI, OUTPUT_URI, GLOSSARY_ID);
String got = bout.toString();
assertThat(got).contains("Total Characters: 9");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static junit.framework.TestCase.assertNotNull;

import com.google.api.gax.paging.Page;

import com.google.cloud.storage.Blob;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;
Expand All @@ -30,7 +29,6 @@
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;

import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
Expand All @@ -48,7 +46,7 @@ public class BatchTranslateTextWithModelTests {
private static final String MODEL_ID = "TRL2188848820815848149";
private static final String PREFIX = "BATCH_TRANSLATION_OUTPUT/";
private static final String OUTPUT_URI =
String.format("gs://%s/%s%s/", PROJECT_ID, PREFIX, UUID.randomUUID());
String.format("gs://%s/%s%s/", PROJECT_ID, PREFIX, UUID.randomUUID());

private ByteArrayOutputStream bout;
private PrintStream out;
Expand Down Expand Up @@ -108,12 +106,7 @@ public void tearDown() {
public void testBatchTranslateTextWithModel()
throws InterruptedException, ExecutionException, IOException, TimeoutException {
BatchTranslateTextWithModel.batchTranslateTextWithModel(
PROJECT_ID,
"en",
"ja",
INPUT_URI,
OUTPUT_URI,
MODEL_ID);
PROJECT_ID, "en", "ja", INPUT_URI, OUTPUT_URI, MODEL_ID);
String got = bout.toString();
assertThat(got).contains("Total Characters: 15");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ExecutionException;

import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ExecutionException;

import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -81,8 +80,7 @@ public void tearDown() {
}

@Test
public void testDeleteGlossary()
throws InterruptedException, ExecutionException, IOException {
public void testDeleteGlossary() throws InterruptedException, ExecutionException, IOException {
DeleteGlossary.deleteGlossary(PROJECT_ID, GLOSSARY_ID);
String got = bout.toString();
assertThat(got).contains("us-central1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,13 @@
import static com.google.common.truth.Truth.assertThat;
import static junit.framework.TestCase.assertNotNull;

import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.translate.v3.CreateGlossaryMetadata;
import com.google.cloud.translate.v3.CreateGlossaryRequest;
import com.google.cloud.translate.v3.DeleteGlossaryMetadata;
import com.google.cloud.translate.v3.DeleteGlossaryRequest;
import com.google.cloud.translate.v3.DeleteGlossaryResponse;
import com.google.cloud.translate.v3.GcsSource;
import com.google.cloud.translate.v3.Glossary;
import com.google.cloud.translate.v3.GlossaryInputConfig;
import com.google.cloud.translate.v3.GlossaryName;
import com.google.cloud.translate.v3.LocationName;
import com.google.cloud.translate.v3.TranslationServiceClient;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ExecutionException;

import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
Expand Down
Loading

0 comments on commit b1e9793

Please sign in to comment.