@java.lang.Override public Builder newBuilderForType() { return newBuilder(); }
public Builder mergeFrom(com.google.cloud.language.v1.AnalyzeEntitySentimentRequest other) { if (other == com.google.cloud.language.v1.AnalyzeEntitySentimentRequest.getDefaultInstance()) return this; if (other.hasDocument()) { mergeDocument(other.getDocument()); } if (other.encodingType_ != 0) { setEncodingTypeValue(other.getEncodingTypeValue()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
@java.lang.Override public com.google.cloud.language.v1.AnalyzeEntitySentimentRequest buildPartial() { com.google.cloud.language.v1.AnalyzeEntitySentimentRequest result = new com.google.cloud.language.v1.AnalyzeEntitySentimentRequest(this); if (documentBuilder_ == null) { result.document_ = document_; } else { result.document_ = documentBuilder_.build(); } result.encodingType_ = encodingType_; onBuilt(); return result; }
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.google.cloud.language.v1.AnalyzeEntitySentimentRequest)) { return super.equals(obj); } com.google.cloud.language.v1.AnalyzeEntitySentimentRequest other = (com.google.cloud.language.v1.AnalyzeEntitySentimentRequest) obj; boolean result = true; result = result && (hasDocument() == other.hasDocument()); if (hasDocument()) { result = result && getDocument().equals(other.getDocument()); } result = result && encodingType_ == other.encodingType_; result = result && unknownFields.equals(other.unknownFields); return result; }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); if (hasDocument()) { hash = (37 * hash) + DOCUMENT_FIELD_NUMBER; hash = (53 * hash) + getDocument().hashCode(); } hash = (37 * hash) + ENCODING_TYPE_FIELD_NUMBER; hash = (53 * hash) + encodingType_; hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
/** * * * <pre> * Input document. * </pre> * * <code>.google.cloud.language.v1.Document document = 1;</code> */ public com.google.cloud.language.v1.DocumentOrBuilder getDocumentOrBuilder() { return getDocument(); }
@Test @SuppressWarnings("all") public void analyzeEntitySentimentTest() { String language = "language-1613589672"; AnalyzeEntitySentimentResponse expectedResponse = AnalyzeEntitySentimentResponse.newBuilder().setLanguage(language).build(); mockLanguageService.addResponse(expectedResponse); Document document = Document.newBuilder().build(); EncodingType encodingType = EncodingType.NONE; AnalyzeEntitySentimentResponse actualResponse = client.analyzeEntitySentiment(document, encodingType); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockLanguageService.getRequests(); Assert.assertEquals(1, actualRequests.size()); AnalyzeEntitySentimentRequest actualRequest = (AnalyzeEntitySentimentRequest) actualRequests.get(0); Assert.assertEquals(document, actualRequest.getDocument()); Assert.assertEquals(encodingType, actualRequest.getEncodingType()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
@java.lang.Override public com.google.cloud.language.v1.AnalyzeEntitySentimentRequest getDefaultInstanceForType() { return com.google.cloud.language.v1.AnalyzeEntitySentimentRequest.getDefaultInstance(); }
@java.lang.Override public com.google.cloud.language.v1.AnalyzeEntitySentimentRequest build() { com.google.cloud.language.v1.AnalyzeEntitySentimentRequest result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); } return result; }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); if (hasDocument()) { hash = (37 * hash) + DOCUMENT_FIELD_NUMBER; hash = (53 * hash) + getDocument().hashCode(); } hash = (37 * hash) + ENCODING_TYPE_FIELD_NUMBER; hash = (53 * hash) + encodingType_; hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
@java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (document_ != null) { output.writeMessage(1, getDocument()); } if (encodingType_ != com.google.cloud.language.v1.EncodingType.NONE.getNumber()) { output.writeEnum(2, encodingType_); } unknownFields.writeTo(output); }
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.google.cloud.language.v1.AnalyzeEntitySentimentRequest)) { return super.equals(obj); } com.google.cloud.language.v1.AnalyzeEntitySentimentRequest other = (com.google.cloud.language.v1.AnalyzeEntitySentimentRequest) obj; boolean result = true; result = result && (hasDocument() == other.hasDocument()); if (hasDocument()) { result = result && getDocument().equals(other.getDocument()); } result = result && encodingType_ == other.encodingType_; result = result && unknownFields.equals(other.unknownFields); return result; }
io.grpc.protobuf.ProtoUtils.marshaller( com.google.cloud.language.v1.AnalyzeEntitySentimentRequest .getDefaultInstance())) .setResponseMarshaller( io.grpc.protobuf.ProtoUtils.marshaller(
@java.lang.Override public com.google.cloud.language.v1.AnalyzeEntitySentimentRequest build() { com.google.cloud.language.v1.AnalyzeEntitySentimentRequest result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); } return result; }
public Builder mergeFrom(com.google.cloud.language.v1.AnalyzeEntitySentimentRequest other) { if (other == com.google.cloud.language.v1.AnalyzeEntitySentimentRequest.getDefaultInstance()) return this; if (other.hasDocument()) { mergeDocument(other.getDocument()); } if (other.encodingType_ != 0) { setEncodingTypeValue(other.getEncodingTypeValue()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
/** * Finds entities, similar to * [AnalyzeEntities][google.cloud.language.v1.LanguageService.AnalyzeEntities] in the text and * analyzes sentiment associated with each entity and its mentions. * * <p>Sample code: * * <pre><code> * try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) { * Document document = Document.newBuilder().build(); * EncodingType encodingType = EncodingType.NONE; * AnalyzeEntitySentimentResponse response = languageServiceClient.analyzeEntitySentiment(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 AnalyzeEntitySentimentResponse analyzeEntitySentiment( Document document, EncodingType encodingType) { AnalyzeEntitySentimentRequest request = AnalyzeEntitySentimentRequest.newBuilder() .setDocument(document) .setEncodingType(encodingType) .build(); return analyzeEntitySentiment(request); }
@java.lang.Override public int getSerializedSize() { int size = memoizedSize; if (size != -1) return size; size = 0; if (document_ != null) { size += com.google.protobuf.CodedOutputStream.computeMessageSize(1, getDocument()); } if (encodingType_ != com.google.cloud.language.v1.EncodingType.NONE.getNumber()) { size += com.google.protobuf.CodedOutputStream.computeEnumSize(2, encodingType_); } size += unknownFields.getSerializedSize(); memoizedSize = size; return size; }
@java.lang.Override public com.google.cloud.language.v1.AnalyzeEntitySentimentRequest getDefaultInstanceForType() { return com.google.cloud.language.v1.AnalyzeEntitySentimentRequest.getDefaultInstance(); }
@java.lang.Override public com.google.cloud.language.v1.AnalyzeEntitySentimentRequest buildPartial() { com.google.cloud.language.v1.AnalyzeEntitySentimentRequest result = new com.google.cloud.language.v1.AnalyzeEntitySentimentRequest(this); if (documentBuilder_ == null) { result.document_ = document_; } else { result.document_ = documentBuilder_.build(); } result.encodingType_ = encodingType_; onBuilt(); return result; }
/** * Detects the entity sentiments in the string {@code text} using the Language Beta API. */ public static void entitySentimentText(String text) throws Exception { // [START language_entity_sentiment_text] // Instantiate the Language client com.google.cloud.language.v1.LanguageServiceClient try (LanguageServiceClient language = LanguageServiceClient.create()) { Document doc = Document.newBuilder() .setContent(text).setType(Type.PLAIN_TEXT).build(); AnalyzeEntitySentimentRequest request = AnalyzeEntitySentimentRequest.newBuilder() .setDocument(doc) .setEncodingType(EncodingType.UTF16).build(); // detect entity sentiments in the given string AnalyzeEntitySentimentResponse response = language.analyzeEntitySentiment(request); // Print the response for (Entity entity : response.getEntitiesList()) { System.out.printf("Entity: %s\n", entity.getName()); System.out.printf("Salience: %.3f\n", entity.getSalience()); System.out.printf("Sentiment : %s\n", entity.getSentiment()); for (EntityMention mention : entity.getMentionsList()) { System.out.printf("Begin offset: %d\n", mention.getText().getBeginOffset()); System.out.printf("Content: %s\n", mention.getText().getContent()); System.out.printf("Magnitude: %.3f\n", mention.getSentiment().getMagnitude()); System.out.printf("Sentiment score : %.3f\n", mention.getSentiment().getScore()); System.out.printf("Type: %s\n\n", mention.getType()); } } } // [END language_entity_sentiment_text] }