Skip to content

Commit 7410801

Browse files
authored
Merge pull request GoogleCloudPlatform#441 from GoogleCloudPlatform/language-script
Adds demo scripts and changes usage in README
2 parents c375d21 + f8829ae commit 7410801

File tree

3 files changed

+174
-47
lines changed

3 files changed

+174
-47
lines changed

language/analysis/README.md

+40-47
Original file line numberDiff line numberDiff line change
@@ -32,56 +32,49 @@ mvn clean compile assembly:single
3232
We can then run the assembled JAR file with the `java` command. The variable $COMMAND takes
3333
three values `entities`, `sentiment`, or `syntax`.
3434

35-
Basic usage:
35+
## Basic usage:
3636

3737
```
38-
#######################################
39-
# Performs a language operation on the given text or GCS object.
40-
# Globals:
41-
# None
42-
# Arguments:
43-
# $1 The operation to perform, either entities, sentiment, or syntax.
44-
# $2 The text or GCS object to operate on.
45-
# Returns:
46-
# None
47-
#######################################
48-
function run_nl() {
49-
local main_class=com.google.cloud.language.samples.Analyze
50-
local jar_file=target/language-entities-1.0-jar-with-dependencies.jar
51-
java -cp ${jar_file} ${main_class} $1 "$2"
52-
}
53-
run_nl entities "The quick brown fox jumped over the lazy dog."
54-
run_nl sentiment "The quick brown fox jumped over the lazy dog."
55-
run_nl syntax "The quick brown fox jumped over the lazy dog."
38+
java -cp target/language-entities-1.0-jar-with-dependencies.jar \
39+
com.google.cloud.language.samples.Analyze \
40+
<entities | sentiment | syntax> \
41+
<text | GCS path>
5642
```
5743

58-
Additional examples:
44+
### Usage Examples
45+
Analyze entities
5946
```
60-
#######################################
61-
# Exercises the sample code on various example text and GCS objects.
62-
# Globals:
63-
# None
64-
# Arguments:
65-
# None
66-
# Returns:
67-
# None
68-
#######################################
69-
function run_nl_all() {
70-
local main_class=com.google.cloud.language.samples.Analyze
71-
local jar_file=target/language-entities-1.0-jar-with-dependencies.jar
72-
local quote="Larry Page, Google's co-founder, once described the 'perfect search
73-
engine' as something that 'understands exactly what you mean and gives you
74-
back exactly what you want.' Since he spoke those words Google has grown to
75-
offer products beyond search, but the spirit of what he said remains."
76-
local gs_path="gs://bucket/file"
77-
78-
java -cp ${jar_file} ${main_class} entities "${quote}"
79-
java -cp ${jar_file} ${main_class} entities "${gs_path}"
80-
java -cp ${jar_file} ${main_class} sentiment "${quote}"
81-
java -cp ${jar_file} ${main_class} sentiment "${gs_path}"
82-
java -cp ${jar_file} ${main_class} syntax "${quote}"
83-
java -cp ${jar_file} ${main_class} syntax "${gs_path}"
84-
}
85-
86-
run_nl_all
47+
java -cp target/language-entities-1.0-jar-with-dependencies.jar \
48+
com.google.cloud.language.samples.Analyze \
49+
entities \
50+
"The quick brown fox jumped over the lazy dog."
51+
```
52+
53+
Analyze sentiment
54+
```
55+
java -cp target/language-entities-1.0-jar-with-dependencies.jar \
56+
com.google.cloud.language.samples.Analyze \
57+
sentiment \
58+
"The quick brown fox jumped over the lazy dog."
59+
```
60+
61+
Analyze syntax
62+
```
63+
java -cp target/language-entities-1.0-jar-with-dependencies.jar \
64+
com.google.cloud.language.samples.Analyze \
65+
syntax \
66+
"The quick brown fox jumped over the lazy dog."
67+
```
68+
69+
Included with the sample are `demo.sh` and `demo.bat` which show additional
70+
examples of usage.
71+
72+
Run demo from *nix or OSX
73+
```
74+
demo.sh
75+
```
76+
77+
Run demo from Windows
78+
```
79+
demo
8780
```

language/analysis/demo.cmd

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
:
2+
: Demonstrates how to run the Analyze sample.
3+
:#########################################################################
4+
5+
: Copyright 2016 Google Inc. All Rights Reserved.
6+
:
7+
: Licensed under the Apache License, Version 2.0 (the "License");
8+
: you may not use this file except in compliance with the License.
9+
: You may obtain a copy of the License at
10+
: http://www.apache.org/licenses/LICENSE-2.0
11+
:
12+
: Unless required by applicable law or agreed to in writing, software
13+
: distributed under the License is distributed on an "AS IS" BASIS,
14+
: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
: See the License for the specific language governing permissions and
16+
: limitations under the License.
17+
:#########################################################################
18+
19+
20+
:call:run_nl entities "The quick brown fox jumped over the lazy dog."
21+
:call:run_nl sentiment "The quick brown fox jumped over the lazy dog."
22+
:call:run_nl syntax "The quick brown fox jumped over the lazy dog."
23+
call:run_nl_all
24+
25+
:######################################
26+
: Performs a language operation on the given text or GCS object.
27+
: Globals:
28+
: None
29+
: Arguments:
30+
: $1 The operation to perform, either entities, sentiment, or syntax.
31+
: $2 The text or GCS object to operate on.
32+
: Returns:
33+
: None
34+
:######################################
35+
:run_nl
36+
set main_class=com.google.cloud.language.samples.Analyze
37+
set jar_file=target/language-entities-1.0-jar-with-dependencies.jar
38+
java -cp %jar_file% %main_class% %~1 "%~2"
39+
EXIT /B
40+
41+
:######################################
42+
: Exercises the sample code on various example text and GCS objects.
43+
: Globals:
44+
: None
45+
: Arguments:
46+
: None
47+
: Returns:
48+
: None
49+
:######################################
50+
:run_nl_all
51+
setlocal EnableDelayedExpansion
52+
set quote=Larry Page, Google's co-founder, once described the 'perfect ^
53+
search engine' as something that 'understands exactly what you mean and ^
54+
gives you back exactly what you want.' Since he spoke those words Google ^
55+
has grown to offer products beyond search, but the spirit of what he said ^
56+
remains.^
57+
58+
59+
echo "%quote%"
60+
set gs_path="gs://bucket/file.txt"
61+
call:run_nl entities "%quote%"
62+
call:run_nl entities %gs_path%
63+
call:run_nl sentiment "%quote%"
64+
call:run_nl sentiment %gs_path%
65+
call:run_nl syntax "%quote%"
66+
call:run_nl syntax %gs_path%
67+
EXIT /B
68+

language/analysis/demo.sh

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
#
3+
# Demonstrates how to run the Analyze sample.
4+
5+
##########################################################################
6+
# Copyright 2016 Google Inc. All Rights Reserved.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
##########################################################################
19+
20+
21+
#######################################
22+
# Performs a language operation on the given text or GCS object.
23+
# Globals:
24+
# None
25+
# Arguments:
26+
# $1 The operation to perform, either entities, sentiment, or syntax.
27+
# $2 The text or GCS object to operate on.
28+
# Returns:
29+
# None
30+
#######################################
31+
function run_nl() {
32+
local main_class=com.google.cloud.language.samples.Analyze
33+
local jar_file=target/language-entities-1.0-jar-with-dependencies.jar
34+
java -cp ${jar_file} ${main_class} "$1" "$2"
35+
}
36+
37+
#######################################
38+
# Exercises the sample code on various example text and GCS objects.
39+
# Globals:
40+
# None
41+
# Arguments:
42+
# None
43+
# Returns:
44+
# None
45+
#######################################
46+
function run_nl_all() {
47+
local quote="Larry Page, Google's co-founder, once described the 'perfect
48+
search engine' as something that 'understands exactly what you mean and
49+
gives you back exactly what you want.' Since he spoke those words Google
50+
has grown to offer products beyond search, but the spirit of what he said
51+
remains."
52+
local gs_path="gs://bucket/file.txt"
53+
54+
run_nl entities "${quote}"
55+
run_nl entities "${gs_path}"
56+
run_nl sentiment "${quote}"
57+
run_nl sentiment "${gs_path}"
58+
run_nl syntax "${quote}"
59+
run_nl syntax "${gs_path}"
60+
}
61+
62+
run_nl entities "The quick brown fox jumped over the lazy dog."
63+
run_nl sentiment "The quick brown fox jumped over the lazy dog."
64+
run_nl syntax "The quick brown fox jumped over the lazy dog."
65+
66+
run_nl_all

0 commit comments

Comments
 (0)