Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
35 changes: 24 additions & 11 deletions language/analysis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ java -cp target/language-entities-1.0-jar-with-dependencies.jar \
<text | GCS path>
```

### Usage Examples
### Usage Examples (stable)

Analyze entities
```
java -cp target/language-entities-1.0-jar-with-dependencies.jar \
Expand All @@ -68,16 +69,6 @@ java -cp target/language-entities-1.0-jar-with-dependencies.jar \
"The quick brown fox jumped over the lazy dog."
```

Analyze sentiment with Beta Languages such as German
```
java -cp target/language-entities-1.0-jar-with-dependencies.jar \
com.google.cloud.language.samples.AnalyzeBeta sentiment "Ich habe eine wundervolle Zeit." "DE"
```
Analyze entity sentiment - Beta
```
java -cp target/language-entities-1.0-jar-with-dependencies.jar com.google.cloud.language.samples.AnalyzeBeta entities-sentiment "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.

Expand All @@ -90,3 +81,25 @@ Run demo from Windows
```
demo
```

### Usage Examples (beta)

Analyze sentiment beta
```
java -cp target/language-entities-1.0-jar-with-dependencies.jar \
com.google.cloud.language.samples.AnalyzeBeta \
sentiment \
"Der schnelle braune Fuchs sprang über den faulen Hund."
```

Analyze entity sentiment Beta
```
java -cp target/language-entities-1.0-jar-with-dependencies.jar \
com.google.cloud.language.samples.AnalyzeBeta entities-sentiment \
"There's nothing better than searching for ice cream on Google."
```

Run beta demo from *nix or OSX
```
demo-beta.sh
```
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,19 @@ public static void printEntities(PrintStream out, List<Entity> entities) {
* Gets {@link Sentiment} from the string {@code text}.
*/
public Sentiment analyzeSentimentText(String text, String lang) throws IOException {
// NL autodetects the language

// Note: This does not work on App Engine standard.
Document doc = Document.newBuilder()
.setLanguage(lang)
.setContent(text).setType(Type.PLAIN_TEXT).build();
// NL autodetects the language
Document doc;
if (lang != null) {
doc = Document.newBuilder()
.setLanguage(lang)
.setContent(text).setType(Type.PLAIN_TEXT)
.build();
} else {
doc = Document.newBuilder()
.setContent(text).setType(Type.PLAIN_TEXT)
.build();
}
AnalyzeSentimentResponse response = languageApi.analyzeSentiment(doc);
return response.getDocumentSentiment();
}
Expand Down
15 changes: 7 additions & 8 deletions language/cloud-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ Install [Maven](http://maven.apache.org/).

Build your project with:

mvn clean package -DskipTests

You can then run a given `ClassName` via:

mvn exec:java -Dexec.mainClass=com.example.language.ClassName \
-DpropertyName=propertyValue \
-Dexec.args="arg1 'arg 2' arg3"
```bash
mvn clean compile assembly:single
```

### Analyze a string for sentiment (using the quickstart sample)

mvn exec:java -Dexec.mainClass=com.example.language.QuickstartSample
```
java -cp target/language-google-cloud-samples-1.0.0-jar-with-dependencies.jar \
com.example.language.QuickstartSample
```
18 changes: 18 additions & 0 deletions language/cloud-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,22 @@
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.example.language.QuickstartSample</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>