/** * Finds named entities (currently proper names and common nouns) in the text along with entity * types, salience, mentions for each entity, and other properties. * * <p>Sample code: * * <pre><code> * try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) { * Document document = Document.newBuilder().build(); * EncodingType encodingType = EncodingType.NONE; * AnalyzeEntitiesResponse response = languageServiceClient.analyzeEntities(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 AnalyzeEntitiesResponse analyzeEntities( Document document, EncodingType encodingType) { AnalyzeEntitiesRequest request = AnalyzeEntitiesRequest.newBuilder() .setDocument(document) .setEncodingType(encodingType) .build(); return analyzeEntities(request); }
@Test @SuppressWarnings("all") public void analyzeEntitiesExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockLanguageService.addException(exception); try { Document document = Document.newBuilder().build(); EncodingType encodingType = EncodingType.NONE; client.analyzeEntities(document, encodingType); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } }
@Test @SuppressWarnings("all") public void analyzeEntitiesTest() { String language = "language-1613589672"; AnalyzeEntitiesResponse expectedResponse = AnalyzeEntitiesResponse.newBuilder().setLanguage(language).build(); mockLanguageService.addResponse(expectedResponse); Document document = Document.newBuilder().build(); EncodingType encodingType = EncodingType.NONE; AnalyzeEntitiesResponse actualResponse = client.analyzeEntities(document, encodingType); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockLanguageService.getRequests(); Assert.assertEquals(1, actualRequests.size()); AnalyzeEntitiesRequest actualRequest = (AnalyzeEntitiesRequest) actualRequests.get(0); Assert.assertEquals(document, actualRequest.getDocument()); Assert.assertEquals(encodingType, actualRequest.getEncodingType()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
.build(); AnalyzeEntitiesResponse response = language.analyzeEntities(request);
.build(); AnalyzeEntitiesResponse response = language.analyzeEntities(request);
/** * Finds named entities (currently proper names and common nouns) in the text along with entity * types, salience, mentions for each entity, and other properties. * * <p>Sample code: * * <pre><code> * try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) { * Document document = Document.newBuilder().build(); * EncodingType encodingType = EncodingType.NONE; * AnalyzeEntitiesResponse response = languageServiceClient.analyzeEntities(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 AnalyzeEntitiesResponse analyzeEntities( Document document, EncodingType encodingType) { AnalyzeEntitiesRequest request = AnalyzeEntitiesRequest.newBuilder() .setDocument(document) .setEncodingType(encodingType) .build(); return analyzeEntities(request); }