Skip to content

Commit e8214b1

Browse files
committed
Isolates variables locally to functions in example script code
1 parent e1e851d commit e8214b1

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

language/analysis/README.md

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,37 @@ 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:
36+
3537
```
36-
MAIN_CLASS=com.google.cloud.language.samples.Analyze
37-
JAR_FILE=target/language-entities-1.0-jar-with-dependencies.jar
38-
java -cp $JAR_FILE $MAIN_CLASS <sentiment|entities|syntax> <text|path>
38+
function run_nl {
39+
local MAIN_CLASS=com.google.cloud.language.samples.Analyze
40+
local JAR_FILE=target/language-entities-1.0-jar-with-dependencies.jar
41+
java -cp ${JAR_FILE} ${MAIN_CLASS} $1 "$2"
42+
}
43+
run_nl entities "The quick fox jumped over the lazy dog."
44+
run_nl sentiment "The quick fox jumped over the lazy dog."
45+
run_nl syntax "The quick fox jumped over the lazy dog."
3946
```
4047

41-
Example usage:
42-
48+
Additional examples:
4349
```
44-
QUOTE="Larry Page, Google's co-founder, once described the 'perfect search
45-
engine' as something that 'understands exactly what you mean and gives you
46-
back exactly what you want.' Since he spoke those words Google has grown to
47-
offer products beyond search, but the spirit of what he said remains."
48-
49-
java -cp $JAR_FILE $MAIN_CLASS entities "$QUOTE"
50-
java -cp $JAR_FILE $MAIN_CLASS entities "gs://bucket/file.txt"
51-
java -cp $JAR_FILE $MAIN_CLASS sentiment "$QUOTE"
52-
java -cp $JAR_FILE $MAIN_CLASS sentiment "gs://bucket/file.txt"
53-
java -cp $JAR_FILE $MAIN_CLASS syntax "$QUOTE"
54-
java -cp $JAR_FILE $MAIN_CLASS syntax "gs://bucket/file.txt"
50+
function run_nl_all {
51+
local MAIN_CLASS=com.google.cloud.language.samples.Analyze
52+
local JAR_FILE=target/language-entities-1.0-jar-with-dependencies.jar
53+
local QUOTE="Larry Page, Google's co-founder, once described the 'perfect search
54+
engine' as something that 'understands exactly what you mean and gives you
55+
back exactly what you want.' Since he spoke those words Google has grown to
56+
offer products beyond search, but the spirit of what he said remains."
57+
local GS_PATH="gs://bucket/file"
58+
59+
java -cp ${JAR_FILE} ${MAIN_CLASS} entities "${QUOTE}"
60+
java -cp ${JAR_FILE} ${MAIN_CLASS} entities "${GS_PATH}"
61+
java -cp ${JAR_FILE} ${MAIN_CLASS} sentiment "${QUOTE}"
62+
java -cp ${JAR_FILE} ${MAIN_CLASS} sentiment "${GS_PATH}"
63+
java -cp ${JAR_FILE} ${MAIN_CLASS} syntax "${QUOTE}"
64+
java -cp ${JAR_FILE} ${MAIN_CLASS} syntax "${GS_PATH}"
65+
}
66+
67+
run_nl_all
5568
```

0 commit comments

Comments
 (0)