/** * * * <pre> * Input document. * </pre> * * <code>.google.cloud.language.v1.Document document = 1;</code> */ private com.google.protobuf.SingleFieldBuilderV3< com.google.cloud.language.v1.Document, com.google.cloud.language.v1.Document.Builder, com.google.cloud.language.v1.DocumentOrBuilder> getDocumentFieldBuilder() { if (documentBuilder_ == null) { documentBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< com.google.cloud.language.v1.Document, com.google.cloud.language.v1.Document.Builder, com.google.cloud.language.v1.DocumentOrBuilder>( getDocument(), getParentForChildren(), isClean()); document_ = null; } return documentBuilder_; }
/** * * * <pre> * Input document. * </pre> * * <code>.google.cloud.language.v1.Document document = 1;</code> */ public com.google.cloud.language.v1.Document.Builder getDocumentBuilder() { onChanged(); return getDocumentFieldBuilder().getBuilder(); } /**
/** * 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); }
/** * * * <pre> * Input document. * </pre> * * <code>.google.cloud.language.v1.Document document = 1;</code> */ private com.google.protobuf.SingleFieldBuilderV3< com.google.cloud.language.v1.Document, com.google.cloud.language.v1.Document.Builder, com.google.cloud.language.v1.DocumentOrBuilder> getDocumentFieldBuilder() { if (documentBuilder_ == null) { documentBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< com.google.cloud.language.v1.Document, com.google.cloud.language.v1.Document.Builder, com.google.cloud.language.v1.DocumentOrBuilder>( getDocument(), getParentForChildren(), isClean()); document_ = null; } return documentBuilder_; }
/** * * * <pre> * Input document. * </pre> * * <code>.google.cloud.language.v1.Document document = 1;</code> */ public com.google.cloud.language.v1.Document.Builder getDocumentBuilder() { onChanged(); return getDocumentFieldBuilder().getBuilder(); } /**
private Builder() { maybeForceBuilderInitialization(); }
private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); }
@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 protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } /**
.build(); AnalyzeEntitySentimentRequest request = AnalyzeEntitySentimentRequest.newBuilder() .setDocument(doc) .setEncodingType(EncodingType.UTF16) .build();
/** * 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] }
/** * 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); }
private Builder() { maybeForceBuilderInitialization(); }
private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); }
@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 protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } /**