Skip to content
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

Adds demo scripts and changes usage in README #441

Merged
merged 3 commits into from
Dec 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 40 additions & 47 deletions language/analysis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,56 +32,49 @@ mvn clean compile assembly:single
We can then run the assembled JAR file with the `java` command. The variable $COMMAND takes
three values `entities`, `sentiment`, or `syntax`.

Basic usage:
## Basic usage:

```
#######################################
# Performs a language operation on the given text or GCS object.
# Globals:
# None
# Arguments:
# $1 The operation to perform, either entities, sentiment, or syntax.
# $2 The text or GCS object to operate on.
# Returns:
# None
#######################################
function run_nl() {
local main_class=com.google.cloud.language.samples.Analyze
local jar_file=target/language-entities-1.0-jar-with-dependencies.jar
java -cp ${jar_file} ${main_class} $1 "$2"
}
run_nl entities "The quick brown fox jumped over the lazy dog."
run_nl sentiment "The quick brown fox jumped over the lazy dog."
run_nl syntax "The quick brown fox jumped over the lazy dog."
java -cp target/language-entities-1.0-jar-with-dependencies.jar \
com.google.cloud.language.samples.Analyze \
<entities | sentiment | syntax> \
<text | GCS path>
```

Additional examples:
### Usage Examples
Analyze entities
```
#######################################
# Exercises the sample code on various example text and GCS objects.
# Globals:
# None
# Arguments:
# None
# Returns:
# None
#######################################
function run_nl_all() {
local main_class=com.google.cloud.language.samples.Analyze
local jar_file=target/language-entities-1.0-jar-with-dependencies.jar
local quote="Larry Page, Google's co-founder, once described the 'perfect search
engine' as something that 'understands exactly what you mean and gives you
back exactly what you want.' Since he spoke those words Google has grown to
offer products beyond search, but the spirit of what he said remains."
local gs_path="gs://bucket/file"

java -cp ${jar_file} ${main_class} entities "${quote}"
java -cp ${jar_file} ${main_class} entities "${gs_path}"
java -cp ${jar_file} ${main_class} sentiment "${quote}"
java -cp ${jar_file} ${main_class} sentiment "${gs_path}"
java -cp ${jar_file} ${main_class} syntax "${quote}"
java -cp ${jar_file} ${main_class} syntax "${gs_path}"
}

run_nl_all
java -cp target/language-entities-1.0-jar-with-dependencies.jar \
com.google.cloud.language.samples.Analyze \
entities \
"The quick brown fox jumped over the lazy dog."
```

Analyze sentiment
```
java -cp target/language-entities-1.0-jar-with-dependencies.jar \
com.google.cloud.language.samples.Analyze \
sentiment \
"The quick brown fox jumped over the lazy dog."
```

Analyze syntax
```
java -cp target/language-entities-1.0-jar-with-dependencies.jar \
com.google.cloud.language.samples.Analyze \
syntax \
"The quick brown fox jumped over the lazy dog."
```

Included with the sample are `demo.sh` and `demo.bat` which show additional
examples of usage.

Run demo from *nix or OSX
```
demo.sh
```

Run demo from Windows
```
demo
```
68 changes: 68 additions & 0 deletions language/analysis/demo.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
:
: Demonstrates how to run the Analyze sample.
:#########################################################################

: Copyright 2016 Google Inc. All Rights Reserved.
:
: Licensed under the Apache License, Version 2.0 (the "License");
: you may not use this file except in compliance with the License.
: You may obtain a copy of the License at
: http://www.apache.org/licenses/LICENSE-2.0
:
: Unless required by applicable law or agreed to in writing, software
: distributed under the License is distributed on an "AS IS" BASIS,
: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
: See the License for the specific language governing permissions and
: limitations under the License.
:#########################################################################


:call:run_nl entities "The quick brown fox jumped over the lazy dog."
:call:run_nl sentiment "The quick brown fox jumped over the lazy dog."
:call:run_nl syntax "The quick brown fox jumped over the lazy dog."
call:run_nl_all

:######################################
: Performs a language operation on the given text or GCS object.
: Globals:
: None
: Arguments:
: $1 The operation to perform, either entities, sentiment, or syntax.
: $2 The text or GCS object to operate on.
: Returns:
: None
:######################################
:run_nl
set main_class=com.google.cloud.language.samples.Analyze
set jar_file=target/language-entities-1.0-jar-with-dependencies.jar
java -cp %jar_file% %main_class% %~1 "%~2"
EXIT /B

:######################################
: Exercises the sample code on various example text and GCS objects.
: Globals:
: None
: Arguments:
: None
: Returns:
: None
:######################################
:run_nl_all
setlocal EnableDelayedExpansion
set quote=Larry Page, Google's co-founder, once described the 'perfect ^
search engine' as something that 'understands exactly what you mean and ^
gives you back exactly what you want.' Since he spoke those words Google ^
has grown to offer products beyond search, but the spirit of what he said ^
remains.^


echo "%quote%"
set gs_path="gs://bucket/file.txt"
call:run_nl entities "%quote%"
call:run_nl entities %gs_path%
call:run_nl sentiment "%quote%"
call:run_nl sentiment %gs_path%
call:run_nl syntax "%quote%"
call:run_nl syntax %gs_path%
EXIT /B

Expand Down
66 changes: 66 additions & 0 deletions language/analysis/demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash
#
# Demonstrates how to run the Analyze sample.

##########################################################################
# Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##########################################################################


#######################################
# Performs a language operation on the given text or GCS object.
# Globals:
# None
# Arguments:
# $1 The operation to perform, either entities, sentiment, or syntax.
# $2 The text or GCS object to operate on.
# Returns:
# None
#######################################
function run_nl() {
local main_class=com.google.cloud.language.samples.Analyze
local jar_file=target/language-entities-1.0-jar-with-dependencies.jar
java -cp ${jar_file} ${main_class} "$1" "$2"
}

#######################################
# Exercises the sample code on various example text and GCS objects.
# Globals:
# None
# Arguments:
# None
# Returns:
# None
#######################################
function run_nl_all() {
local quote="Larry Page, Google's co-founder, once described the 'perfect
search engine' as something that 'understands exactly what you mean and
gives you back exactly what you want.' Since he spoke those words Google
has grown to offer products beyond search, but the spirit of what he said
remains."
local gs_path="gs://bucket/file.txt"

run_nl entities "${quote}"
run_nl entities "${gs_path}"
run_nl sentiment "${quote}"
run_nl sentiment "${gs_path}"
run_nl syntax "${quote}"
run_nl syntax "${gs_path}"
}

run_nl entities "The quick brown fox jumped over the lazy dog."
run_nl sentiment "The quick brown fox jumped over the lazy dog."
run_nl syntax "The quick brown fox jumped over the lazy dog."

run_nl_all