/** * * * <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.SentimentOrBuilder getDocumentSentimentOrBuilder() { return getDocumentSentiment(); }
@java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (documentSentiment_ != null) { output.writeMessage(1, getDocumentSentiment()); } if (!getLanguageBytes().isEmpty()) { com.google.protobuf.GeneratedMessageV3.writeString(output, 2, language_); } for (int i = 0; i < sentences_.size(); i++) { output.writeMessage(3, sentences_.get(i)); } unknownFields.writeTo(output); }
@java.lang.Override public int getSerializedSize() { int size = memoizedSize; if (size != -1) return size; size = 0; if (documentSentiment_ != null) { size += com.google.protobuf.CodedOutputStream.computeMessageSize(1, getDocumentSentiment()); } if (!getLanguageBytes().isEmpty()) { size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, language_); } for (int i = 0; i < sentences_.size(); i++) { size += com.google.protobuf.CodedOutputStream.computeMessageSize(3, sentences_.get(i)); } size += unknownFields.getSerializedSize(); memoizedSize = size; return size; }
@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(); if (hasDocumentSentiment()) { hash = (37 * hash) + DOCUMENT_SENTIMENT_FIELD_NUMBER; hash = (53 * hash) + getDocumentSentiment().hashCode(); } hash = (37 * hash) + LANGUAGE_FIELD_NUMBER; hash = (53 * hash) + getLanguage().hashCode(); if (getSentencesCount() > 0) { hash = (37 * hash) + SENTENCES_FIELD_NUMBER; hash = (53 * hash) + getSentencesList().hashCode(); } hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
return this; if (other.hasDocumentSentiment()) { mergeDocumentSentiment(other.getDocumentSentiment());
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 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()); } } }
/** * 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] }
/** * Identifies the sentiment in the string {@code text}. */ public static Sentiment analyzeSentimentText(String text) throws Exception { // [START language_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(); 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_text] }
/** * * * <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.SentimentOrBuilder getDocumentSentimentOrBuilder() { return getDocumentSentiment(); }
@java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (documentSentiment_ != null) { output.writeMessage(1, getDocumentSentiment()); } if (!getLanguageBytes().isEmpty()) { com.google.protobuf.GeneratedMessageV3.writeString(output, 2, language_); } for (int i = 0; i < sentences_.size(); i++) { output.writeMessage(3, sentences_.get(i)); } unknownFields.writeTo(output); }
@java.lang.Override public int getSerializedSize() { int size = memoizedSize; if (size != -1) return size; size = 0; if (documentSentiment_ != null) { size += com.google.protobuf.CodedOutputStream.computeMessageSize(1, getDocumentSentiment()); } if (!getLanguageBytes().isEmpty()) { size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, language_); } for (int i = 0; i < sentences_.size(); i++) { size += com.google.protobuf.CodedOutputStream.computeMessageSize(3, sentences_.get(i)); } size += unknownFields.getSerializedSize(); memoizedSize = size; return size; }
@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(); if (hasDocumentSentiment()) { hash = (37 * hash) + DOCUMENT_SENTIMENT_FIELD_NUMBER; hash = (53 * hash) + getDocumentSentiment().hashCode(); } hash = (37 * hash) + LANGUAGE_FIELD_NUMBER; hash = (53 * hash) + getLanguage().hashCode(); if (getSentencesCount() > 0) { hash = (37 * hash) + SENTENCES_FIELD_NUMBER; hash = (53 * hash) + getSentencesList().hashCode(); } hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
return this; if (other.hasDocumentSentiment()) { mergeDocumentSentiment(other.getDocumentSentiment());
Sentiment sentiment = result.get().getDocumentSentiment();