use of com.google.cloud.language.v1.Sentiment in project java-docs-samples by GoogleCloudPlatform.
the class AnalyzeIT method analyzeSentimentText_returnNegative.
@Test
public void analyzeSentimentText_returnNegative() throws Exception {
Sentiment sentiment = Analyze.analyzeSentimentText("That was the worst performance I've seen in a while.");
assertThat(sentiment.getMagnitude()).isGreaterThan(0.0F);
assertThat(sentiment.getScore()).isLessThan(0.0F);
}
use of com.google.cloud.language.v1.Sentiment in project java-docs-samples by GoogleCloudPlatform.
the class QuickstartSample method main.
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());
}
}
use of com.google.cloud.language.v1.Sentiment in project google-cloud-java by GoogleCloudPlatform.
the class AnalyzeSentiment method main.
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());
}
}
Aggregations