@@ -32,24 +32,56 @@ mvn clean compile assembly:single
32
32
We can then run the assembled JAR file with the ` java ` command. The variable $COMMAND takes
33
33
three values ` entities ` , ` sentiment ` , or ` syntax ` .
34
34
35
+ Basic usage:
36
+
35
37
```
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
+ #######################################
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."
39
56
```
40
57
41
- Example usage:
42
-
58
+ Additional examples:
43
59
```
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"
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
55
87
```
0 commit comments