8000 Merge pull request #637 from GoogleCloudPlatform/nl-readme · loosebazooka/java-docs-samples@1146bf1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1146bf1

Browse files
authored
Merge pull request GoogleCloudPlatform#637 from GoogleCloudPlatform/nl-readme
Updates readme instructions / changes execution for Quickstart
2 parents 9570885 + ac34472 commit 1146bf1

File tree

5 files changed

+61
-33
lines changed

5 files changed

+61
-33
lines changed

language/analysis/README.md

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ java -cp target/language-entities-1.0-jar-with-dependencies.jar \
4343
<text | GCS path>
4444
```
4545

46-
### Usage Examples
46+
### Usage Examples (stable)
47+
4748
Analyze entities
4849
```
4950
java -cp target/language-entities-1.0-jar-with-dependencies.jar \
@@ -68,16 +69,6 @@ java -cp target/language-entities-1.0-jar-with-dependencies.jar \
6869
"The quick brown fox jumped over the lazy dog."
6970
```
7071

71-
Analyze sentiment with Beta Languages such as German
72-
```
73-
java -cp target/language-entities-1.0-jar-with-dependencies.jar \
74-
com.google.cloud.language.samples.AnalyzeBeta sentiment "Ich habe eine wundervolle Zeit." "DE"
75-
```
76-
Analyze entity sentiment - Beta
77-
```
78-
java -cp target/language-entities-1.0-jar-with-dependencies.jar com.google.cloud.language.samples.AnalyzeBeta entities-sentiment "The quick brown fox jumped over the lazy dog."
79-
```
80-
8172
Included with the sample are `demo.sh` and `demo.bat` which show additional
8273
examples of usage.
8374

@@ -90,3 +81,25 @@ Run demo from Windows
9081
```
9182
demo
9283
```
84+
85+
### Usage Examples (beta)
86+
87+
Analyze sentiment beta
88+
```
89+
java -cp target/language-entities-1.0-jar-with-dependencies.jar \
90+
com.google.cloud.language.samples.AnalyzeBeta \
91+
sentiment \
92+
"Der schnelle braune Fuchs sprang über den faulen Hund."
93+
```
94+
95+
Analyze entity sentiment Beta
96+
```
97+
java -cp target/language-entities-1.0-jar-with-dependencies.jar \
98+
com.google.cloud.language.samples.AnalyzeBeta entities-sentiment \
99+
"There's nothing better than searching for ice cream on Google."
100+
```
101+
102+
Run beta demo from *nix or OSX
103+
```
104+
demo-beta.sh
105+
```

language/analysis/src/main/java/com/google/cloud/language/samples/Analyze.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ public Analyze(LanguageServiceClient languageApi) {
169169
* Gets {@link Entity}s from the string {@code text}.
170170
*/
171171
public List<Entity> analyzeEntitiesText(String text) throws IOException {
172-
// Note: This does not work on App Engine standard.
173172
Document doc = Document.newBuilder()
174173
.setContent(text).setType(Type.PLAIN_TEXT).build();
175174
AnalyzeEntitiesRequest request = AnalyzeEntitiesRequest.newBuilder()
@@ -183,7 +182,6 @@ public List<Entity> analyzeEntitiesText(String text) throws IOException {
183182
* Gets {@link Entity}s from the contents of the object at the given GCS {@code path}.
184183
*/
185184
public List<Entity> analyzeEntitiesFile(String path) throws IOException {
186-
// Note: This does not work on App Engine standard.
187185
Document doc = Document.newBuilder()
188186
.setGcsContentUri(path).setType(Type.PLAIN_TEXT).build();
189187
AnalyzeEntitiesRequest request = AnalyzeEntitiesRequest.newBuilder()
@@ -197,7 +195,6 @@ public List<Entity> analyzeEntitiesFile(String path) throws IOException {
197195
* Gets {@link Sentiment} from the string {@code text}.
198196
*/
199197
public Sentiment analyzeSentimentText(String text) throws IOException {
200-
// Note: This does not work on App Engine standard.
201198
Document doc = Document.newBuilder()
202199
.setContent(text).setType(Type.PLAIN_TEXT).build();
203200
AnalyzeSentimentResponse response = languageApi.analyzeSentiment(doc);
@@ -208,7 +205,6 @@ public Sentiment analyzeSentimentText(String text) throws IOException {
208205
* Gets {@link Sentiment} from the contents of the object at the given GCS {@code path}.
209206
*/
210207
public Sentiment analyzeSentimentFile(String path) throws IOException {
211-
// Note: This does not work on App Engine standard.
212208
Document doc = Document.newBuilder()
213209
.setGcsContentUri(path).setType(Type.PLAIN_TEXT).build();
214210
AnalyzeSentimentResponse response = languageApi.analyzeSentiment(doc);
@@ -219,7 +215,6 @@ public Sentiment analyzeSentimentFile(String path) throws IOException {
219215
* Gets {@link Token}s from the string {@code text}.
220216
*/
221217
public List<Token> analyzeSyntaxText(String text) throws IOException {
222-
// Note: This does not work on App Engine standard.
223218
Document doc = Document.newBuilder()
224219
.setContent(text).setType(Type.PLAIN_TEXT).build();
225220
AnalyzeSyntaxRequest request = AnalyzeSyntaxRequest.newBuilder()
@@ -233,7 +228,6 @@ public List<Token> analyzeSyntaxText(String text) throws IOException {
233228
* Gets {@link Token}s from the contents of the object at the given GCS {@code path}.
234229
*/
235230
public List<Token> analyzeSyntaxFile(String path) throws IOException {
236-
// Note: This does not work on App Engine standard.
237231
Document doc = Document.newBuilder()
238232
.setGcsContentUri(path).setType(Type.PLAIN_TEXT).build();
239233
AnalyzeSyntaxRequest request = AnalyzeSyntaxRequest.newBuilder()

language/analysis/src/main/java/com/google/cloud/language/samples/AnalyzeBeta.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,18 @@ public static void printEntities(PrintStream out, List<Entity> entities) {
131131
* Gets {@link Sentiment} from the string {@code text}.
132132
*/
133133
public Sentiment analyzeSentimentText(String text, String lang) throws IOException {
134-
// NL autodetects the language
135-
136-
// Note: This does not work on App Engine standard.
137-
Document doc = Document.newBuilder()
138-
.setLanguage(lang)
139-
.setContent(text).setType(Type.PLAIN_TEXT).build();
134+
// NL autodetects the language
135+
Document doc;
136+
if (lang != null) {
137+
doc = Document.newBuilder()
138+
.setLanguage(lang)
139+
.setContent(text).setType(Type.PLAIN_TEXT)
140+
.build();
141+
} else {
142+
doc = Document.newBuilder()
143+
.setContent(text).setType(Type.PLAIN_TEXT)
144+
.build();
145+
}
140146
AnalyzeSentimentResponse response = languageApi.analyzeSentiment(doc);
141147
return response.getDocumentSentiment();
142148
}
@@ -145,7 +151,6 @@ public Sentiment analyzeSentimentText(String text, String lang) throws IOExcepti
145151
* Gets {@link Entity}s from the string {@code text} with sentiment.
146152
*/
147153
public List<Entity> entitySentimentText(String text) throws IOException {
148-
// Note: This does not work on App Engine standard.
149154
Document doc = Document.newBuilder()
150155
.setContent(text).setType(Type.PLAIN_TEXT).build();
151156
AnalyzeEntitySentimentRequest request = AnalyzeEntitySentimentRequest.newBuilder()
@@ -160,7 +165,6 @@ public List<Entity> entitySentimentText(String text) throws IOException {
160165
* with sentiment.
161166
*/
162167
public List<Entity> entitySentimentFile(String path) throws IOException {
163-
// Note: This does not work on App Engine standard.
164168
Document doc = Document.newBuilder()
165169
.setGcsContentUri(path).setType(Type.PLAIN_TEXT).build();
166170
AnalyzeEntitySentimentRequest request = AnalyzeEntitySentimentRequest.newBuilder()

language/cloud-client/README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ Install [Maven](http://maven.apache.org/).
1717

1818
Build your project with:
1919

20-
mvn clean package -DskipTests
21-
22-
You can then run a given `ClassName` via:
23-
24-
mvn exec:java -Dexec.mainClass=com.example.language.ClassName \
25-
-DpropertyName=propertyValue \
26-
-Dexec.args="arg1 'arg 2' arg3"
20+
```bash
21+
mvn clean compile assembly:single
22+
```
2723

2824
### Analyze a string for sentiment (using the quickstart sample)
2925

30-
mvn exec:java -Dexec.mainClass=com.example.language.QuickstartSample
26+
```
27+
java -cp target/language-google-cloud-samples-1.0.0-jar-with-dependencies.jar \
28+
com.example.language.QuickstartSample
29+
```

language/cloud-client/pom.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,22 @@
5454
<scope>test</scope>
5555
</dependency>
5656
</dependencies>
57+
58+
<build>
59+
<plugins>
60+
<plugin>
61+
<artifactId>maven-assembly-plugin</artifactId>
62+
<configuration>
63+
<archive>
64+
<manifest>
65+
<mainClass>com.example.language.QuickstartSample</mainClass>
66+
</manifest>
67+
</archive>
68+
<descriptorRefs>
69+
<descriptorRef>jar-with-dependencies</descriptorRef>
70+
</descriptorRefs>
71+
</configuration>
72+
</plugin>
73+
</plugins>
74+
</build>
5775
</project>

0 commit comments

Comments
 (0)
0