Laden Sie JAR herunter https://github.com/watson-developer-cloud/java-sdk Download von "Laden Sie das Glas mit den Abhängigkeiten hier herunter."
Code
String versionDate = "2018-03-19";
String username = "xxx";
String password = "xxx";
NaturalLanguageUnderstanding service = new NaturalLanguageUnderstanding(versionDate, username, password);
SentimentOptions sentiment = new SentimentOptions.Builder().build();
EmotionOptions emotion = new EmotionOptions.Builder().build();
KeywordsOptions keywords = new KeywordsOptions.Builder().build();
EntitiesOptions entities = new EntitiesOptions.Builder().build();
CategoriesOptions categories = new CategoriesOptions();
SemanticRolesOptions semanticRoles = new SemanticRolesOptions.Builder().build();
Features features = new Features.Builder() //
.sentiment(sentiment) //
.emotion(emotion) // "emotion: unsupported text language: ja"
.keywords(keywords) //
.entities(entities) //
.categories(categories) //
.semanticRoles(semanticRoles) //
.build();
String language = "ja";
String text = "US-Präsident Trump...Er kritisierte die Firma für die Kapitulation in einem Handelskrieg.";
AnalyzeOptions analyzeOptions = new AnalyzeOptions.Builder().features(features).language(language).text(text)
.build();
AnalysisResults results = service.analyze(analyzeOptions).execute();
System.err.println(results); // Print JSON
if (results.getCategories() != null) {
for (CategoriesResult result : results.getCategories()) {
System.err.println(result.getLabel() + " : " + result.getScore());
}
}
Unten sind die Ergebnisse. (Ein Teil des Nachrichtentextteils ist "... (weggelassen) ...")
{
"language": "ja",
"usage": {
"features": 5,
"text_characters": 94,
"text_units": 1
},
"entities": [
{
"type": "Person",
"text": "Trumpf",
"relevance": 0.954265,
"count": 1
},
{
"type": "Organization",
"text": "Harley Davidson",
"relevance": 0.860373,
"count": 1
},
{
"type": "Organization",
"text": "Europäische Union",
"relevance": 0.79402,
"count": 1
},
{
"type": "Location",
"text": "Reis",
"relevance": 0.636659,
"count": 1
},
{
"type": "Location",
"text": "EU",
"relevance": 0.115173,
"count": 1
}
],
"keywords": [
{
"relevance": 0.809941,
"text": "Handelskrieg"
},
{
"relevance": 0.733196,
"text": "Außerhalb der USA"
},
{
"relevance": 0.710815,
"text": "Zwischen der EU"
},
{
"relevance": 0.582804,
"text": "Die Firma"
},
{
"relevance": 0.569772,
"text": "Europäische Union(EU"
},
{
"relevance": 0.557057,
"text": "EU"
},
{
"relevance": 0.498835,
"text": "Krieg"
},
{
"relevance": 0.498399,
"text": "Handel"
},
{
"relevance": 0.472507,
"text": "Produktion"
},
{
"relevance": 0.462888,
"text": "Übersee"
},
{
"relevance": 0.461109,
"text": "Europäische Union(EU)Vergeltungszoll von"
},
{
"relevance": 0.445569,
"text": "US-Präsident Trump"
},
{
"relevance": 0.430877,
"text": "Zoll"
},
{
"relevance": 0.418106,
"text": "Vergeltung"
},
{
"relevance": 0.417108,
"text": "während"
},
{
"relevance": 0.395505,
"text": "Reis"
},
{
"relevance": 0.384407,
"text": "Europäische Union"
},
{
"relevance": 0.370795,
"text": "Harley Davidson"
},
{
"relevance": 0.35972,
"text": "Amerikanischer Präsident"
},
{
"relevance": 0.350696,
"text": "Trumpf"
}
],
"categories": [
{
"label": "/society/unrest and war",
"score": 0.288369
},
{
"label": "/law, govt and politics/government",
"score": 0.197268
},
{
"label": "/law, govt and politics",
"score": 0.155733
}
],
"semantic_roles": [
{
"sentence": "US-Präsident Trump...(Abkürzung)...Ich habe die Firma kritisiert.",
"action": {
"text": "Machen",
"normalized": "Machen",
"verb": {
"text": "Machen"
}
},
"object": {
"text": "Produktion"
}
},
{
"sentence": "US-Präsident Trump...(Abkürzung)...Ich habe die Firma kritisiert.",
"subject": {
"text": "Harley Davidson"
},
"action": {
"text": "tat",
"normalized": "tat",
"verb": {
"text": "tat"
}
}
},
{
"sentence": "US-Präsident Trump...(Abkürzung)...Ich habe die Firma kritisiert.",
"action": {
"text": "tat",
"normalized": "tat",
"verb": {
"text": "tat"
}
},
"object": {
"text": "Die Firma"
}
}
],
"sentiment": {
"document": {
"label": "neutral",
"score": 0.0
}
}
}
null /society/unrest and war : 0.288369 /law, govt and politics/government : 0.197268 /law, govt and politics : 0.155733
Recommended Posts