Télécharger le JAR https://github.com/watson-developer-cloud/java-sdk Téléchargez à partir de "Téléchargez le fichier jar avec les dépendances ici."
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 = "Président américain Trump...Il a critiqué l'entreprise pour s'être rendue dans une guerre commerciale.";
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());
}
}
Voici les résultats. (Une partie de la partie du texte d'actualité est "... (omis) ...")
{
"language": "ja",
"usage": {
"features": 5,
"text_characters": 94,
"text_units": 1
},
"entities": [
{
"type": "Person",
"text": "Atout",
"relevance": 0.954265,
"count": 1
},
{
"type": "Organization",
"text": "Harley Davidson",
"relevance": 0.860373,
"count": 1
},
{
"type": "Organization",
"text": "Union européenne",
"relevance": 0.79402,
"count": 1
},
{
"type": "Location",
"text": "Riz",
"relevance": 0.636659,
"count": 1
},
{
"type": "Location",
"text": "EU",
"relevance": 0.115173,
"count": 1
}
],
"keywords": [
{
"relevance": 0.809941,
"text": "Guerre commerciale"
},
{
"relevance": 0.733196,
"text": "En dehors des États-Unis"
},
{
"relevance": 0.710815,
"text": "Entre l'UE"
},
{
"relevance": 0.582804,
"text": "L'entreprise"
},
{
"relevance": 0.569772,
"text": "Union européenne(EU"
},
{
"relevance": 0.557057,
"text": "EU"
},
{
"relevance": 0.498835,
"text": "guerre"
},
{
"relevance": 0.498399,
"text": "Commerce"
},
{
"relevance": 0.472507,
"text": "production"
},
{
"relevance": 0.462888,
"text": "Étranger"
},
{
"relevance": 0.461109,
"text": "Union européenne(EU)Droits de douane de représailles par"
},
{
"relevance": 0.445569,
"text": "Président américain Trump"
},
{
"relevance": 0.430877,
"text": "Droit de douane"
},
{
"relevance": 0.418106,
"text": "Représailles"
},
{
"relevance": 0.417108,
"text": "tandis que"
},
{
"relevance": 0.395505,
"text": "Riz"
},
{
"relevance": 0.384407,
"text": "Union européenne"
},
{
"relevance": 0.370795,
"text": "Harley Davidson"
},
{
"relevance": 0.35972,
"text": "Le président américain"
},
{
"relevance": 0.350696,
"text": "Atout"
}
],
"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": "Président américain Trump...(Abréviation)...J'ai critiqué l'entreprise.",
"action": {
"text": "Faire",
"normalized": "Faire",
"verb": {
"text": "Faire"
}
},
"object": {
"text": "Production"
}
},
{
"sentence": "Président américain Trump...(Abréviation)...J'ai critiqué l'entreprise.",
"subject": {
"text": "Harley Davidson"
},
"action": {
"text": "fait",
"normalized": "fait",
"verb": {
"text": "fait"
}
}
},
{
"sentence": "Président américain Trump...(Abréviation)...J'ai critiqué l'entreprise.",
"action": {
"text": "fait",
"normalized": "fait",
"verb": {
"text": "fait"
}
},
"object": {
"text": "L'entreprise"
}
}
],
"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