/** * Analyzes the syntax of the text and provides sentence boundaries and tokenization along with * part of speech tags, dependency trees, and other properties. * * <p>Sample code: * * <pre><code> * try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) { * Document document = Document.newBuilder().build(); * EncodingType encodingType = EncodingType.NONE; * AnalyzeSyntaxResponse response = languageServiceClient.analyzeSyntax(document, encodingType); * } * </code></pre> * * @param document Input document. * @param encodingType The encoding type used by the API to calculate offsets. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final AnalyzeSyntaxResponse analyzeSyntax(Document document, EncodingType encodingType) { AnalyzeSyntaxRequest request = AnalyzeSyntaxRequest.newBuilder() .setDocument(document) .setEncodingType(encodingType) .build(); return analyzeSyntax(request); }
@Test @SuppressWarnings("all") public void analyzeSyntaxExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockLanguageService.addException(exception); try { Document document = Document.newBuilder().build(); EncodingType encodingType = EncodingType.NONE; client.analyzeSyntax(document, encodingType); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } }
@Test @SuppressWarnings("all") public void analyzeSyntaxTest() { String language = "language-1613589672"; AnalyzeSyntaxResponse expectedResponse = AnalyzeSyntaxResponse.newBuilder().setLanguage(language).build(); mockLanguageService.addResponse(expectedResponse); Document document = Document.newBuilder().build(); EncodingType encodingType = EncodingType.NONE; AnalyzeSyntaxResponse actualResponse = client.analyzeSyntax(document, encodingType); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockLanguageService.getRequests(); Assert.assertEquals(1, actualRequests.size()); AnalyzeSyntaxRequest actualRequest = (AnalyzeSyntaxRequest) actualRequests.get(0); Assert.assertEquals(document, actualRequest.getDocument()); Assert.assertEquals(encodingType, actualRequest.getEncodingType()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
.build(); AnalyzeSyntaxResponse response = language.analyzeSyntax(request);
.build(); AnalyzeSyntaxResponse response = language.analyzeSyntax(request);
/** * Analyzes the syntax of the text and provides sentence boundaries and tokenization along with * part of speech tags, dependency trees, and other properties. * * <p>Sample code: * * <pre><code> * try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) { * Document document = Document.newBuilder().build(); * EncodingType encodingType = EncodingType.NONE; * AnalyzeSyntaxResponse response = languageServiceClient.analyzeSyntax(document, encodingType); * } * </code></pre> * * @param document Input document. * @param encodingType The encoding type used by the API to calculate offsets. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final AnalyzeSyntaxResponse analyzeSyntax(Document document, EncodingType encodingType) { AnalyzeSyntaxRequest request = AnalyzeSyntaxRequest.newBuilder() .setDocument(document) .setEncodingType(encodingType) .build(); return analyzeSyntax(request); }