日本語に対応したらしい Watson NLU を Java SDK から呼んでみる


JARのダウンロード
https://github.com/watson-developer-cloud/java-sdk
にある「Download the jar with dependencies here.」からダウンロード。

コード

```java
		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 = "トランプ米大統領は...貿易戦争で降伏したと同社を批判した。";

		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());
			}

		}



```

以下は結果。（ニューステキスト部分の一部を「...(略)...」としています）

```javascript
{
  "language": "ja",
  "usage": {
    "features": 5,
    "text_characters": 94,
    "text_units": 1
  },
  "entities": [
    {
      "type": "Person",
      "text": "トランプ",
      "relevance": 0.954265,
      "count": 1
    },
    {
      "type": "Organization",
      "text": "ハーレーダビッドソン",
      "relevance": 0.860373,
      "count": 1
    },
    {
      "type": "Organization",
      "text": "欧州連合",
      "relevance": 0.79402,
      "count": 1
    },
    {
      "type": "Location",
      "text": "米",
      "relevance": 0.636659,
      "count": 1
    },
    {
      "type": "Location",
      "text": "EU",
      "relevance": 0.115173,
      "count": 1
    }
  ],
  "keywords": [
    {
      "relevance": 0.809941,
      "text": "貿易戦争"
    },
    {
      "relevance": 0.733196,
      "text": "米国外"
    },
    {
      "relevance": 0.710815,
      "text": "EUとの間"
    },
    {
      "relevance": 0.582804,
      "text": "同社"
    },
    {
      "relevance": 0.569772,
      "text": "欧州連合(EU"
    },
    {
      "relevance": 0.557057,
      "text": "EU"
    },
    {
      "relevance": 0.498835,
      "text": "戦争"
    },
    {
      "relevance": 0.498399,
      "text": "貿易"
    },
    {
      "relevance": 0.472507,
      "text": "生産"
    },
    {
      "relevance": 0.462888,
      "text": "国外"
    },
    {
      "relevance": 0.461109,
      "text": "欧州連合(EU)による報復関税"
    },
    {
      "relevance": 0.445569,
      "text": "トランプ米大統領"
    },
    {
      "relevance": 0.430877,
      "text": "関税"
    },
    {
      "relevance": 0.418106,
      "text": "報復"
    },
    {
      "relevance": 0.417108,
      "text": "間"
    },
    {
      "relevance": 0.395505,
      "text": "米"
    },
    {
      "relevance": 0.384407,
      "text": "欧州連合"
    },
    {
      "relevance": 0.370795,
      "text": "ハーレーダビッドソン"
    },
    {
      "relevance": 0.35972,
      "text": "米大統領"
    },
    {
      "relevance": 0.350696,
      "text": "トランプ"
    }
  ],
  "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": "トランプ米大統領は...(略)...同社を批判した。",
      "action": {
        "text": "する",
        "normalized": "する",
        "verb": {
          "text": "する"
        }
      },
      "object": {
        "text": "生産を"
      }
    },
    {
      "sentence": "トランプ米大統領は...(略)...同社を批判した。",
      "subject": {
        "text": "ハーレーダビッドソンが"
      },
      "action": {
        "text": "した",
        "normalized": "した",
        "verb": {
          "text": "した"
        }
      }
    },
    {
      "sentence": "トランプ米大統領は...(略)...同社を批判した。",
      "action": {
        "text": "した",
        "normalized": "した",
        "verb": {
          "text": "した"
        }
      },
      "object": {
        "text": "同社を"
      }
    }
  ],
  "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