Examples

Here are some examples of sentiment analysis using MeaningCloud API:

Analyze the sentiment of a text using custom sentiment models.

We will analyze a sentence of the specific domain of restaurant reviews to show how to use our Restaurants example sentiment model:

"Main dishes were quite good, but desserts were too sweet for me."

  • Use thetxt parameter to submit the text.
  • Choose withlang the language in which the text is going to be analyzed, in this case English, en.
  • Define the specific sentiment behaviors of terms and contexts in the domain using the user sentiment models console. When you are done defining your sentiment model, simply use its name in the model parameter to analyze the text with it.
  • When you define your sentiment model, yo have to set its language. Use this value in the lang parameter.
Example usingcurl:
curl 'https://api.meaningcloud.com/sentiment-2.1' \
  -F 'key=YOUR API KEY' \
  -F 'lang=en' \
  -F 'model=Restaurants' \
  -F 'txt=Main dishes were quite good, but desserts were too sweet for me.'
MeaningCloud API output:
{
"status":{
"code":
"0"
"msg":
"OK"
"credits":
"1"
}
"model":
"Restaurants_en"
"score_tag":
"P"
"agreement":
"DISAGREEMENT"
"subjectivity":
"SUBJECTIVE"
"confidence":
"98"
"irony":
"NONIRONIC"
"sentence_list":[
0:{
"text":
"Main dishes were quite good, but desserts were too sweet for me."
"inip":
"0"
"endp":
"63"
"bop":
"y"
"confidence":
"98"
"score_tag":
"P"
"agreement":
"DISAGREEMENT"
"segment_list":[
...
]
"sentimented_entity_list":[
...
]
"sentimented_concept_list":[
]
}
]
"sentimented_entity_list":[
0:{
"form":
"dessert"
"id":
"0e15bbd941"
"type":
"Top>Product>Food"
"score_tag":
"N"
}
]
"sentimented_concept_list":[
]
}

Analyze the sentiment of a text using entities and concepts defined by the user.

To show how to obtain the sentiment analysis of a text using user-defined entities and concepts we will use the following text as an example:

"In the country of Sokovia, the Avengers – Tony Stark, Steve Rogers, Thor, Bruce Banner, Natasha Romanoff, and Clint Barton – raid a Hydra outpost led by Wolfgang von Strucker, who has been experimenting on humans using the scepter previously wielded by Loki. They encounter two of Strucker's experiments – twins Pietro, who has superhuman speed, and Wanda Maximoff, who can manipulate minds and project energy – and apprehend Strucker, while Stark retrieves Loki's scepter."

  • Use thetxt parameter to submit the text.
  • Selectgeneral as the value for themodel parameter to use a generic sentiment analysis.
  • Selecten as the value for thelang parameter to analyze the text in English.
  • Includeyour MeaningCloud license key as value forkey parameter.
  • Choose an output format, for instancejson as value forof.
  • Define the entities and concepts you want to detect using theuser dictionaries console and once you are done, use the name of the dictionary as the value for the parameterud. In this case we will use the example dictionary provided and we will call it 'the-avengers'.

The rest of the input parameters used will be the default ones.

Example usingcurl:
curl 'https://api.meaningcloud.com/sentiment-2.1' \
  -F 'key=YOUR API KEY' \
  -F 'lang=en' \
  -F 'model=general' \
  -F 'ud=the-avengers' \
  -F 'txt=In the country of Sokovia, the Avengers – Tony Stark, Steve Rogers, Thor, Bruce Banner, Natasha Romanoff, and Clint Barton – raid a Hydra outpost led by Wolfgang von Strucker, who has been experimenting on humans using the scepter previously wielded by Loki. They encounter two of Strucker\'s experiments – twins Pietro, who has superhuman speed, and Wanda Maximoff, who can manipulate minds and project energy – and apprehend Strucker, while Stark retrieves Loki\'s scepter.'
MeaningCloud API output:
{
"status":{
"code":
"0"
"msg":
"OK"
"credits":
"1"
}
"model":
"general_en"
"score_tag":
"N+"
"agreement":
"AGREEMENT"
"subjectivity":
"OBJECTIVE"
"confidence":
"100"
"irony":
"NONIRONIC"
"sentence_list":[
0:{
"text":
"In the country of Sokovia, the Avengers – Tony Stark, Steve Rogers, Thor, Bruce Banner, Natasha Romanoff, and Clint Barton – raid a Hydra outpost led by Wolfgang von Strucker, who has been experimenting on humans using the scepter previously wielded by Loki."
"inip":
"0"
"endp":
"257"
"bop":
"y"
"confidence":
"100"
"score_tag":
"N+"
"agreement":
"AGREEMENT"
"segment_list":[
...
]
"sentimented_entity_list":[
...
]
"sentimented_concept_list":[
...
]
}
1:{
"text":
"They encounter two of Strucker's experiments – twins Pietro, who has superhuman speed, and Wanda Maximoff, who can manipulate minds and project energy – and apprehend Strucker, while Stark retrieves Loki's scepter."
"inip":
"259"
"endp":
"472"
"bop":
"n"
"confidence":
"100"
"score_tag":
"N"
"agreement":
"AGREEMENT"
"segment_list":[
...
]
"sentimented_entity_list":[
...
]
"sentimented_concept_list":[
...
]
}
]
"sentimented_entity_list":[
0:{
"form":
"Steve Rogers"
"id":
"2418af20d6"
"type":
"Top>Person>FullName"
"score_tag":
"N+"
}
1:{
"form":
"Thor"
"id":
"5f8b6e87d6"
"type":
"Top>Location>GeoPoliticalEntity"
"score_tag":
"N+"
}
2:{
"form":
"Wolfgang"
"id":
"6aecb2b781"
"type":
"Top>Person>FirstName"
"score_tag":
"NONE"
}
3:{
"form":
"Thor"
"id":
"8f9502a801"
"type":
"Top>Person>FirstName"
"score_tag":
"N+"
}
4:{
"form":
"Loki"
"id":
"__1296309029595943509"
"type":
"Top"
"score_tag":
"NONE"
}
5:{
"form":
"Bruce Banner"
"id":
"__13726859781023558032"
"type":
"Top"
"score_tag":
"N+"
}
6:{
"form":
"Pietro"
"id":
"__13802492502779249448"
"type":
"Top>Person"
"score_tag":
"NONE"
}
7:{
"form":
"Natasha Romanoff"
"id":
"__13891153709863729564"
"type":
"Top>Person>FullName"
"score_tag":
"N+"
}
8:{
"form":
"Sokovia"
"id":
"__14592390818495647481"
"type":
"Top"
"score_tag":
"NONE"
}
9:{
"form":
"Wanda Maximoff"
"id":
"__16858144557084070716"
"type":
"Top>Person>FullName"
"score_tag":
"N"
}
10:{
"form":
"von Strucker"
"id":
"__3133061113578888878"
"type":
"Top>Person>FullName"
"score_tag":
"NONE"
}
11:{
"form":
"Tony Stark"
"id":
"__6713084364163173541"
"type":
"Top>Person>FullName"
"score_tag":
"N+"
}
12:{
"form":
"Clint Barton"
"id":
"__754254597092124379"
"type":
"Top>Person>FullName"
"score_tag":
"N+"
}
13:{
"form":
"Strucker"
"id":
"d2624f89ad"
"type":
"Top>Person>LastName"
"score_tag":
"N"
}
]
"sentimented_concept_list":[
0:{
"form":
"twin"
"id":
"0e35ad0409"
"type":
"Top>Person"
"score_tag":
"NONE"
}
1:{
"form":
"country"
"id":
"35229605d1"
"type":
"Top>Location>GeoPoliticalEntity>Country"
"score_tag":
"N+"
}
2:{
"form":
"avenger"
"id":
"65fdadcbff"
"type":
"Top>Person"
"score_tag":
"N+"
}
3:{
"form":
"twin"
"id":
"93f89a8a84"
"type":
"Top>Person"
"score_tag":
"NONE"
}
4:{
"form":
"energy"
"id":
"b606e89e91"
"type":
"Top"
"score_tag":
"NONE"
}
5:{
"form":
"project"
"id":
"bde52a085f"
"type":
"Top"
"score_tag":
"NONE"
}
6:{
"form":
"speed"
"id":
"e50498110e"
"type":
"Top>Unit>SpeedUnit"
"score_tag":
"NONE"
}
]
}