Skip to content

Commit

Permalink
samples: Language samples (#845)
Browse files Browse the repository at this point in the history
* Language samples

* Updates to recently published libraries.

* Updates to latest client library version.

* Moves new production features to v1, updates tests, updates docs.
  • Loading branch information
jabubake authored and Shabirmean committed Nov 17, 2022
1 parent affabbd commit 8e693b5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,19 @@
public class QuickstartSample {
public static void main(String... args) throws Exception {
// Instantiates a client
LanguageServiceClient language = LanguageServiceClient.create();
try (LanguageServiceClient language = LanguageServiceClient.create()) {

// The text to analyze
String text = "Hello, world!";
Document doc = Document.newBuilder()
.setContent(text).setType(Type.PLAIN_TEXT).build();
// 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();
// 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());
System.out.printf("Text: %s%n", text);
System.out.printf("Sentiment: %s, %s%n", sentiment.getScore(), sentiment.getMagnitude());
}
}
}
// [END language_quickstart]
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

import static com.google.common.truth.Truth.assertThat;


import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

/**
* Tests for quickstart sample.
*/
Expand Down

0 comments on commit 8e693b5

Please sign in to comment.