@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.google.cloud.language.v1.EntityMention)) { return super.equals(obj); } com.google.cloud.language.v1.EntityMention other = (com.google.cloud.language.v1.EntityMention) obj; boolean result = true; result = result && (hasText() == other.hasText()); if (hasText()) { result = result && getText().equals(other.getText()); } result = result && type_ == other.type_; result = result && (hasSentiment() == other.hasSentiment()); if (hasSentiment()) { result = result && getSentiment().equals(other.getSentiment()); } result = result && unknownFields.equals(other.unknownFields); return result; }
@java.lang.Override public com.google.cloud.language.v1.EntityMention buildPartial() { com.google.cloud.language.v1.EntityMention result = new com.google.cloud.language.v1.EntityMention(this); if (textBuilder_ == null) { result.text_ = text_; } else { result.text_ = textBuilder_.build(); } result.type_ = type_; if (sentimentBuilder_ == null) { result.sentiment_ = sentiment_; } else { result.sentiment_ = sentimentBuilder_.build(); } onBuilt(); return result; }
public Builder mergeFrom(com.google.cloud.language.v1.EntityMention other) { if (other == com.google.cloud.language.v1.EntityMention.getDefaultInstance()) return this; if (other.hasText()) { mergeText(other.getText()); } if (other.type_ != 0) { setTypeValue(other.getTypeValue()); } if (other.hasSentiment()) { mergeSentiment(other.getSentiment()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
@java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (text_ != null) { output.writeMessage(1, getText()); } if (type_ != com.google.cloud.language.v1.EntityMention.Type.TYPE_UNKNOWN.getNumber()) { output.writeEnum(2, type_); } if (sentiment_ != null) { output.writeMessage(3, getSentiment()); } unknownFields.writeTo(output); }
/** * 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] }
/** * * * <pre> * The mention text. * </pre> * * <code>.google.cloud.language.v1.TextSpan text = 1;</code> */ public com.google.cloud.language.v1.TextSpanOrBuilder getTextOrBuilder() { return getText(); }
/** * * * <pre> * For calls to [AnalyzeEntitySentiment][] or if * [AnnotateTextRequest.Features.extract_entity_sentiment][google.cloud.language.v1.AnnotateTextRequest.Features.extract_entity_sentiment] is set to * true, this field will contain the sentiment expressed for this mention of * the entity in the provided document. * </pre> * * <code>.google.cloud.language.v1.Sentiment sentiment = 3;</code> */ public com.google.cloud.language.v1.SentimentOrBuilder getSentimentOrBuilder() { return getSentiment(); }
@java.lang.Override public com.google.cloud.language.v1.EntityMention getDefaultInstanceForType() { return com.google.cloud.language.v1.EntityMention.getDefaultInstance(); }
@java.lang.Override public com.google.cloud.language.v1.EntityMention build() { com.google.cloud.language.v1.EntityMention result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); } return result; }
public static final com.google.protobuf.Descriptors.EnumDescriptor getDescriptor() { return com.google.cloud.language.v1.EntityMention.getDescriptor().getEnumTypes().get(0); }
@java.lang.Override public int getSerializedSize() { int size = memoizedSize; if (size != -1) return size; size = 0; if (text_ != null) { size += com.google.protobuf.CodedOutputStream.computeMessageSize(1, getText()); } if (type_ != com.google.cloud.language.v1.EntityMention.Type.TYPE_UNKNOWN.getNumber()) { size += com.google.protobuf.CodedOutputStream.computeEnumSize(2, type_); } if (sentiment_ != null) { size += com.google.protobuf.CodedOutputStream.computeMessageSize(3, getSentiment()); } size += unknownFields.getSerializedSize(); memoizedSize = size; return size; }
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());
/** * * * <pre> * The mention text. * </pre> * * <code>.google.cloud.language.v1.TextSpan text = 1;</code> */ public com.google.cloud.language.v1.TextSpanOrBuilder getTextOrBuilder() { return getText(); }
/** * * * <pre> * For calls to [AnalyzeEntitySentiment][] or if * [AnnotateTextRequest.Features.extract_entity_sentiment][google.cloud.language.v1.AnnotateTextRequest.Features.extract_entity_sentiment] is set to * true, this field will contain the sentiment expressed for this mention of * the entity in the provided document. * </pre> * * <code>.google.cloud.language.v1.Sentiment sentiment = 3;</code> */ public com.google.cloud.language.v1.SentimentOrBuilder getSentimentOrBuilder() { return getSentiment(); }
/** * * * <pre> * The mentions of this entity in the input document. The API currently * supports proper noun mentions. * </pre> * * <code>repeated .google.cloud.language.v1.EntityMention mentions = 5;</code> */ public com.google.cloud.language.v1.EntityMention.Builder addMentionsBuilder() { return getMentionsFieldBuilder() .addBuilder(com.google.cloud.language.v1.EntityMention.getDefaultInstance()); } /**
@java.lang.Override public com.google.cloud.language.v1.EntityMention build() { com.google.cloud.language.v1.EntityMention result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); } return result; }
public static final com.google.protobuf.Descriptors.EnumDescriptor getDescriptor() { return com.google.cloud.language.v1.EntityMention.getDescriptor().getEnumTypes().get(0); }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); if (hasText()) { hash = (37 * hash) + TEXT_FIELD_NUMBER; hash = (53 * hash) + getText().hashCode(); } hash = (37 * hash) + TYPE_FIELD_NUMBER; hash = (53 * hash) + type_; if (hasSentiment()) { hash = (37 * hash) + SENTIMENT_FIELD_NUMBER; hash = (53 * hash) + getSentiment().hashCode(); } hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }