@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.google.cloud.language.v1.Sentiment)) { return super.equals(obj); } com.google.cloud.language.v1.Sentiment other = (com.google.cloud.language.v1.Sentiment) obj; boolean result = true; result = result && (java.lang.Float.floatToIntBits(getMagnitude()) == java.lang.Float.floatToIntBits(other.getMagnitude())); result = result && (java.lang.Float.floatToIntBits(getScore()) == java.lang.Float.floatToIntBits(other.getScore())); result = result && unknownFields.equals(other.unknownFields); return result; }
@java.lang.Override public com.google.cloud.language.v1.Sentiment buildPartial() { com.google.cloud.language.v1.Sentiment result = new com.google.cloud.language.v1.Sentiment(this); result.magnitude_ = magnitude_; result.score_ = score_; onBuilt(); return result; }
public Builder mergeFrom(com.google.cloud.language.v1.Sentiment other) { if (other == com.google.cloud.language.v1.Sentiment.getDefaultInstance()) return this; if (other.getMagnitude() != 0F) { setMagnitude(other.getMagnitude()); } if (other.getScore() != 0F) { setScore(other.getScore()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); hash = (37 * hash) + MAGNITUDE_FIELD_NUMBER; hash = (53 * hash) + java.lang.Float.floatToIntBits(getMagnitude()); hash = (37 * hash) + SCORE_FIELD_NUMBER; hash = (53 * hash) + java.lang.Float.floatToIntBits(getScore()); hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
@java.lang.Override public com.google.cloud.language.v1.Sentiment getDefaultInstanceForType() { return com.google.cloud.language.v1.Sentiment.getDefaultInstance(); }
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.google.cloud.language.v1.AnalyzeSentimentResponse)) { return super.equals(obj); } com.google.cloud.language.v1.AnalyzeSentimentResponse other = (com.google.cloud.language.v1.AnalyzeSentimentResponse) obj; boolean result = true; result = result && (hasDocumentSentiment() == other.hasDocumentSentiment()); if (hasDocumentSentiment()) { result = result && getDocumentSentiment().equals(other.getDocumentSentiment()); } result = result && getLanguage().equals(other.getLanguage()); result = result && getSentencesList().equals(other.getSentencesList()); 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(); hash = (37 * hash) + MAGNITUDE_FIELD_NUMBER; hash = (53 * hash) + java.lang.Float.floatToIntBits(getMagnitude()); hash = (37 * hash) + SCORE_FIELD_NUMBER; hash = (53 * hash) + java.lang.Float.floatToIntBits(getScore()); hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
/** * * * <pre> * The overall sentiment of the input document. * </pre> * * <code>.google.cloud.language.v1.Sentiment document_sentiment = 1;</code> */ public com.google.cloud.language.v1.Sentiment getDocumentSentiment() { return documentSentiment_ == null ? com.google.cloud.language.v1.Sentiment.getDefaultInstance() : documentSentiment_; } /**
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.google.cloud.language.v1.AnnotateTextResponse)) { return super.equals(obj); } com.google.cloud.language.v1.AnnotateTextResponse other = (com.google.cloud.language.v1.AnnotateTextResponse) obj; boolean result = true; result = result && getSentencesList().equals(other.getSentencesList()); result = result && getTokensList().equals(other.getTokensList()); result = result && getEntitiesList().equals(other.getEntitiesList()); result = result && (hasDocumentSentiment() == other.hasDocumentSentiment()); if (hasDocumentSentiment()) { result = result && getDocumentSentiment().equals(other.getDocumentSentiment()); } result = result && getLanguage().equals(other.getLanguage()); result = result && getCategoriesList().equals(other.getCategoriesList()); result = result && unknownFields.equals(other.unknownFields); return result; }
public static void main(String... args) throws Exception { // Instantiates a client LanguageServiceClient language = LanguageServiceClient.create(); // The text to analyze String[] texts = {"I love this!", "I hate this!"}; for (String text : texts) { Document doc = Document.newBuilder().setContent(text).setType(Type.PLAIN_TEXT).build(); // Detects the sentiment of the text Sentiment sentiment = language.analyzeSentiment(doc).getDocumentSentiment(); System.out.printf("Text: \"%s\"%n", text); System.out.printf( "Sentiment: score = %s, magnitude = %s%n", sentiment.getScore(), sentiment.getMagnitude()); } } }
public Builder mergeFrom(com.google.cloud.language.v1.Sentiment other) { if (other == com.google.cloud.language.v1.Sentiment.getDefaultInstance()) return this; if (other.getMagnitude() != 0F) { setMagnitude(other.getMagnitude()); } if (other.getScore() != 0F) { setScore(other.getScore()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
/** * * * <pre> * The overall sentiment for the document. Populated if the user enables * [AnnotateTextRequest.Features.extract_document_sentiment][google.cloud.language.v1.AnnotateTextRequest.Features.extract_document_sentiment]. * </pre> * * <code>.google.cloud.language.v1.Sentiment document_sentiment = 4;</code> */ public com.google.cloud.language.v1.Sentiment getDocumentSentiment() { return documentSentiment_ == null ? com.google.cloud.language.v1.Sentiment.getDefaultInstance() : documentSentiment_; } /**
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.google.cloud.language.v1.Entity)) { return super.equals(obj); } com.google.cloud.language.v1.Entity other = (com.google.cloud.language.v1.Entity) obj; boolean result = true; result = result && getName().equals(other.getName()); result = result && type_ == other.type_; result = result && internalGetMetadata().equals(other.internalGetMetadata()); result = result && (java.lang.Float.floatToIntBits(getSalience()) == java.lang.Float.floatToIntBits(other.getSalience())); result = result && getMentionsList().equals(other.getMentionsList()); 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.Sentiment buildPartial() { com.google.cloud.language.v1.Sentiment result = new com.google.cloud.language.v1.Sentiment(this); result.magnitude_ = magnitude_; result.score_ = score_; onBuilt(); return result; }
public static void main(String... args) throws Exception { // Instantiates a client try (LanguageServiceClient language = LanguageServiceClient.create()) { // The text to analyze String text = "Hello, world!"; Document doc = Document.newBuilder() .setContent(text).setType(Type.PLAIN_TEXT).build(); // Detects the sentiment of the text Sentiment sentiment = language.analyzeSentiment(doc).getDocumentSentiment(); System.out.printf("Text: %s%n", text); System.out.printf("Sentiment: %s, %s%n", sentiment.getScore(), sentiment.getMagnitude()); } } }
/** * * * <pre> * For calls to [AnalyzeSentiment][] or if * [AnnotateTextRequest.Features.extract_document_sentiment][google.cloud.language.v1.AnnotateTextRequest.Features.extract_document_sentiment] is set to * true, this field will contain the sentiment for the sentence. * </pre> * * <code>.google.cloud.language.v1.Sentiment sentiment = 2;</code> */ public com.google.cloud.language.v1.Sentiment getSentiment() { return sentiment_ == null ? com.google.cloud.language.v1.Sentiment.getDefaultInstance() : sentiment_; } /**
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.google.cloud.language.v1.Sentence)) { return super.equals(obj); } com.google.cloud.language.v1.Sentence other = (com.google.cloud.language.v1.Sentence) obj; boolean result = true; result = result && (hasText() == other.hasText()); if (hasText()) { result = result && getText().equals(other.getText()); } result = result && (hasSentiment() == other.hasSentiment()); if (hasSentiment()) { result = result && getSentiment().equals(other.getSentiment()); } result = result && unknownFields.equals(other.unknownFields); return result; }
/** * Gets {@link Sentiment} from the contents of the GCS hosted file. */ public static Sentiment analyzeSentimentFile(String gcsUri) throws Exception { // [START language_sentiment_gcs] // Instantiate the Language client com.google.cloud.language.v1.LanguageServiceClient try (LanguageServiceClient language = LanguageServiceClient.create()) { Document doc = Document.newBuilder() .setGcsContentUri(gcsUri) .setType(Type.PLAIN_TEXT) .build(); AnalyzeSentimentResponse response = language.analyzeSentiment(doc); Sentiment sentiment = response.getDocumentSentiment(); if (sentiment == null) { System.out.println("No sentiment found"); } else { System.out.printf("Sentiment magnitude : %.3f\n", sentiment.getMagnitude()); System.out.printf("Sentiment score : %.3f\n", sentiment.getScore()); } return sentiment; } // [END language_sentiment_gcs] }
/** * * * <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.Sentiment getSentiment() { return sentiment_ == null ? com.google.cloud.language.v1.Sentiment.getDefaultInstance() : sentiment_; } /**
@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; }