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

Improves style for shell examples #435

Merged
merged 2 commits into from
Dec 7, 2016
Merged
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
64 changes: 48 additions & 16 deletions language/analysis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,56 @@ 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:

```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add bash after the "`"'s

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add a .BAT / .SH script in a separate PR and will update README after.

MAIN_CLASS=com.google.cloud.language.samples.Analyze
JAR_FILE=target/language-entities-1.0-jar-with-dependencies.jar
java -cp $JAR_FILE $MAIN_CLASS <sentiment|entities|syntax> <text|path>
#######################################
# 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."
```

Example usage:

Additional examples:
```
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."

java -cp $JAR_FILE $MAIN_CLASS entities "$QUOTE"
java -cp $JAR_FILE $MAIN_CLASS entities "gs://bucket/file.txt"
java -cp $JAR_FILE $MAIN_CLASS sentiment "$QUOTE"
java -cp $JAR_FILE $MAIN_CLASS sentiment "gs://bucket/file.txt"
java -cp $JAR_FILE $MAIN_CLASS syntax "$QUOTE"
java -cp $JAR_FILE $MAIN_CLASS syntax "gs://bucket/file.txt"
#######################################
# 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
```