Search in sources :

Example 1 with AnnotateTextResponse

use of com.google.cloud.language.v1beta2.AnnotateTextResponse in project google-cloud-java by GoogleCloudPlatform.

the class LanguageServiceClientTest method annotateTextTest.

@Test
@SuppressWarnings("all")
public void annotateTextTest() {
    String language = "language-1613589672";
    AnnotateTextResponse expectedResponse = AnnotateTextResponse.newBuilder().setLanguage(language).build();
    mockLanguageService.addResponse(expectedResponse);
    Document document = Document.newBuilder().build();
    AnnotateTextRequest.Features features = AnnotateTextRequest.Features.newBuilder().build();
    EncodingType encodingType = EncodingType.NONE;
    AnnotateTextResponse actualResponse = client.annotateText(document, features, encodingType);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockLanguageService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    AnnotateTextRequest actualRequest = (AnnotateTextRequest) actualRequests.get(0);
    Assert.assertEquals(document, actualRequest.getDocument());
    Assert.assertEquals(features, actualRequest.getFeatures());
    Assert.assertEquals(encodingType, actualRequest.getEncodingType());
}
Also used : AnnotateTextRequest(com.google.cloud.language.v1beta2.AnnotateTextRequest) EncodingType(com.google.cloud.language.v1beta2.EncodingType) AnnotateTextResponse(com.google.cloud.language.v1beta2.AnnotateTextResponse) Document(com.google.cloud.language.v1beta2.Document) Features(com.google.cloud.language.v1beta2.AnnotateTextRequest.Features) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 2 with AnnotateTextResponse

use of com.google.cloud.language.v1beta2.AnnotateTextResponse in project google-cloud-java by GoogleCloudPlatform.

the class LanguageServiceClientTest method annotateTextTest.

@Test
@SuppressWarnings("all")
public void annotateTextTest() {
    String language = "language-1613589672";
    AnnotateTextResponse expectedResponse = AnnotateTextResponse.newBuilder().setLanguage(language).build();
    mockLanguageService.addResponse(expectedResponse);
    Document document = Document.newBuilder().build();
    AnnotateTextRequest.Features features = AnnotateTextRequest.Features.newBuilder().build();
    EncodingType encodingType = EncodingType.NONE;
    AnnotateTextResponse actualResponse = client.annotateText(document, features, encodingType);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockLanguageService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    AnnotateTextRequest actualRequest = (AnnotateTextRequest) actualRequests.get(0);
    Assert.assertEquals(document, actualRequest.getDocument());
    Assert.assertEquals(features, actualRequest.getFeatures());
    Assert.assertEquals(encodingType, actualRequest.getEncodingType());
}
Also used : AnnotateTextRequest(com.google.cloud.language.v1.AnnotateTextRequest) EncodingType(com.google.cloud.language.v1.EncodingType) AnnotateTextResponse(com.google.cloud.language.v1.AnnotateTextResponse) Document(com.google.cloud.language.v1.Document) Features(com.google.cloud.language.v1.AnnotateTextRequest.Features) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 3 with AnnotateTextResponse

use of com.google.cloud.language.v1beta2.AnnotateTextResponse in project beam by apache.

the class AnnotateTextIT method analyzesLanguage.

@Test
public void analyzesLanguage() {
    Document doc = Document.newBuilder().setContent(TEST_STRING).setType(Document.Type.PLAIN_TEXT).build();
    AnnotateTextRequest.Features features = AnnotateTextRequest.Features.newBuilder().setExtractSyntax(true).build();
    PCollection<AnnotateTextResponse> responses = testPipeline.apply(Create.of(doc)).apply(AnnotateText.newBuilder().setFeatures(features).build());
    PAssert.that(responses).satisfies(new VerifyTextAnnotationResult());
    testPipeline.run().waitUntilFinish();
}
Also used : AnnotateTextRequest(com.google.cloud.language.v1.AnnotateTextRequest) Document(com.google.cloud.language.v1.Document) AnnotateTextResponse(com.google.cloud.language.v1.AnnotateTextResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 AnnotateTextRequest (com.google.cloud.language.v1.AnnotateTextRequest)2 AnnotateTextResponse (com.google.cloud.language.v1.AnnotateTextResponse)2 Document (com.google.cloud.language.v1.Document)2 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)2 Features (com.google.cloud.language.v1.AnnotateTextRequest.Features)1 EncodingType (com.google.cloud.language.v1.EncodingType)1 AnnotateTextRequest (com.google.cloud.language.v1beta2.AnnotateTextRequest)1 Features (com.google.cloud.language.v1beta2.AnnotateTextRequest.Features)1 AnnotateTextResponse (com.google.cloud.language.v1beta2.AnnotateTextResponse)1 Document (com.google.cloud.language.v1beta2.Document)1 EncodingType (com.google.cloud.language.v1beta2.EncodingType)1