-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Address changes for analyzeSyntax. #376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
b40c291
5a98a32
6fdc772
0f24b1b
bf91b07
eb52858
80764fd
e3bb44a
3b1490f
0c22226
70a6401
fa6c581
d88a673
880b7e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,19 +22,21 @@ | |
| import com.google.api.client.http.HttpRequestInitializer; | ||
| import com.google.api.client.json.JsonFactory; | ||
| import com.google.api.client.json.jackson2.JacksonFactory; | ||
| import com.google.api.services.language.v1beta1.CloudNaturalLanguageAPI; | ||
| import com.google.api.services.language.v1beta1.CloudNaturalLanguageAPIScopes; | ||
| import com.google.api.services.language.v1beta1.model.AnalyzeEntitiesRequest; | ||
| import com.google.api.services.language.v1beta1.model.AnalyzeEntitiesResponse; | ||
| import com.google.api.services.language.v1beta1.model.AnalyzeSentimentRequest; | ||
| import com.google.api.services.language.v1beta1.model.AnalyzeSentimentResponse; | ||
| import com.google.api.services.language.v1beta1.model.AnnotateTextRequest; | ||
| import com.google.api.services.language.v1beta1.model.AnnotateTextResponse; | ||
| import com.google.api.services.language.v1beta1.model.Document; | ||
| import com.google.api.services.language.v1beta1.model.Entity; | ||
| import com.google.api.services.language.v1beta1.model.Features; | ||
| import com.google.api.services.language.v1beta1.model.Sentiment; | ||
| import com.google.api.services.language.v1beta1.model.Token; | ||
| import com.google.api.services.language.v1.CloudNaturalLanguageAPI; | ||
| import com.google.api.services.language.v1.CloudNaturalLanguageAPIScopes; | ||
| import com.google.api.services.language.v1.model.AnalyzeEntitiesRequest; | ||
| import com.google.api.services.language.v1.model.AnalyzeEntitiesResponse; | ||
| import com.google.api.services.language.v1.model.AnalyzeSentimentRequest; | ||
| import com.google.api.services.language.v1.model.AnalyzeSentimentResponse; | ||
| import com.google.api.services.language.v1.model.AnalyzeSyntaxRequest; | ||
| import com.google.api.services.language.v1.model.AnalyzeSyntaxResponse; | ||
| import com.google.api.services.language.v1.model.AnnotateTextRequest; | ||
| import com.google.api.services.language.v1.model.AnnotateTextResponse; | ||
| import com.google.api.services.language.v1.model.Document; | ||
| import com.google.api.services.language.v1.model.Entity; | ||
| import com.google.api.services.language.v1.model.Features; | ||
| import com.google.api.services.language.v1.model.Sentiment; | ||
| import com.google.api.services.language.v1.model.Token; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.PrintStream; | ||
|
|
@@ -136,7 +138,7 @@ public static void printSyntax(PrintStream out, List<Token> tokens) { | |
| /** | ||
| * Connects to the Natural Language API using Application Default Credentials. | ||
| */ | ||
| public static CloudNaturalLanguageAPI getLanguageService() | ||
| public static CloudNaturalLanguageAPI getLanguageService() | ||
| throws IOException, GeneralSecurityException { | ||
| GoogleCredential credential = | ||
| GoogleCredential.getApplicationDefault().createScoped(CloudNaturalLanguageAPIScopes.all()); | ||
|
||
|
|
@@ -195,15 +197,13 @@ public Sentiment analyzeSentiment(String text) throws IOException { | |
| * Gets {@link Token}s from the string {@code text}. | ||
| */ | ||
| public List<Token> analyzeSyntax(String text) throws IOException { | ||
| AnnotateTextRequest request = | ||
| new AnnotateTextRequest() | ||
| AnalyzeSyntaxRequest request = | ||
| new AnalyzeSyntaxRequest() | ||
| .setDocument(new Document().setContent(text).setType("PLAIN_TEXT")) | ||
| .setFeatures(new Features().setExtractSyntax(true)) | ||
| .setEncodingType("UTF16"); | ||
| CloudNaturalLanguageAPI.Documents.AnnotateText analyze = | ||
| languageApi.documents().annotateText(request); | ||
|
|
||
| AnnotateTextResponse response = analyze.execute(); | ||
| CloudNaturalLanguageAPI.Documents.AnalyzeSyntax analyze = | ||
| languageApi.documents().analyzeSyntax(request); | ||
| AnalyzeSyntaxResponse response = analyze.execute(); | ||
| return response.getTokens(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,9 +18,9 @@ | |
|
|
||
| import static com.google.common.truth.Truth.assertThat; | ||
|
|
||
| import com.google.api.services.language.v1beta1.model.Entity; | ||
| import com.google.api.services.language.v1beta1.model.Sentiment; | ||
| import com.google.api.services.language.v1beta1.model.Token; | ||
| import com.google.api.services.language.v1.model.Entity; | ||
| import com.google.api.services.language.v1.model.Sentiment; | ||
| import com.google.api.services.language.v1.model.Token; | ||
|
|
||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
@@ -59,10 +59,10 @@ public class AnalyzeIT { | |
|
|
||
| @Test public void analyzeSentiment_returnPositive() throws Exception { | ||
| // Act | ||
| Sentiment sentiment = | ||
| Sentiment sentiment = | ||
| analyzeApp.analyzeSentiment( | ||
| "Tom Cruise is one of the finest actors in hollywood and a great star!"); | ||
|
|
||
| // Assert | ||
| assertThat((double)sentiment.getMagnitude()).isGreaterThan(0.0); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gguuss v1 has score now and no polarity so the test will need to change. The polarity is there for now but will be removed soon.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, changed to Score. |
||
| assertThat((double)sentiment.getPolarity()).isGreaterThan(0.0); | ||
|
|
@@ -89,7 +89,7 @@ public class AnalyzeIT { | |
| .collect(Collectors.toList()); | ||
|
|
||
| // Assert | ||
| assertThat(got).containsExactly("NOUN", "NOUN", "VERB", | ||
| assertThat(got).containsExactly("NOUN", "NOUN", "VERB", | ||
| "VERB", "ADP", "DET", "ADJ", "NOUN").inOrder(); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gguuss The analyzeSentiment is still returning Mag and Polarity. It should return score and mag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, showing score and hiding polarity.