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."

The main change we will observe with respect to previous versions is the fact that now we will be able to use user sentiment models.

These are the parameters we need to send:

  • Use the txt parameter to submit the text.
  • Include your MeaningCloud license key as value for key parameter.
  • Choose an output format, for instance json as value for of.
  • Define the specific sentiment behaviors of terms and contexts in the domain using the user sentiment models console. When you're 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.

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

This is how the call would be made using curl:
curl -XPOST "https://api.meaningcloud.com/sentiment-2.1?key=<<YOUR OWN KEY>>&of=json&txt=Main%20dishes%20were%20quite%20good%2C%20but%20desserts%20were%20too%20sweet%20for%20me.&model=Restaurants&lang=en"
      
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": [
    {
      "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": [
        {
          "text": "Main dishes were quite good",
          "segment_type": "main",
          "inip": "0",
          "endp": "26",
          "confidence": "98",
          "score_tag": "P+",
          "agreement": "AGREEMENT",
          "polarity_term_list": [
            {
              "text": "(quite) good",
              "inip": "23",
              "endp": "26",
              "confidence": "98",
              "score_tag": "P+"
            }
          ]
        },
        {
          "text": "desserts were too sweet for me",
          "segment_type": "main",
          "inip": "33",
          "endp": "62",
          "confidence": "100",
          "score_tag": "N",
          "agreement": "AGREEMENT",
          "polarity_term_list": [
            {
              "text": "too sweet",
              "inip": "47",
              "endp": "55",
              "confidence": "100",
              "score_tag": "N",
              "sentimented_entity_list": [
                {
                  "form": "dessert",
                  "id": "0e15bbd941",
                  "variant": "desserts",
                  "inip": "33",
                  "endp": "40",
                  "type": "Top>Product>Food",
                  "score_tag": "N"
                }
              ]
            }
          ]
        }
      ],
      "sentimented_entity_list": [
        {
          "form": "dessert",
          "id": "0e15bbd941",
          "type": "Top>Product>Food",
          "score_tag": "N"
        }
      ],
      "sentimented_concept_list": []
    }
  ],
  "sentimented_entity_list": [
    {
      "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 the txt parameter to submit the text.
  • Select general as the value for the model parameter to use a generic sentiment analysis.
  • Select en as the value for the lang parameter to analyze the text in English.
  • Include your MeaningCloud license key as value for key parameter.
  • Choose an output format, for instance json as value for of.
  • Define the entities and concepts you want to detect using the user dictionaries console and once you are done, use the name of the dictionary as the value for the parameter ud. 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.

This is how the call would be made using curl:
curl -XPOST "https://api.meaningcloud.com/sentiment-2.1?key=<<YOUR OWN KEY>>&of=json&txt=In%20the%20country%20of%20Sokovia%2C%20the%20Avengers%20%E2%80%93%20Tony%20Stark%2C%20Steve%20Rogers%2C%20Thor%2C%20Bruce%20Banner%2C%20Natasha%20Romanoff%2C%20and%20Clint%20Barton%20%E2%80%93%20raid%20a%20Hydra%20outpost%20led%20by%20Wolfgang%20von%20Strucker%2C%20who%20has%20been%20experimenting%20on%20humans%20using%20the%20scepter%20previously%20wielded%20by%20Loki.%20They%20encounter%20two%20of%20Strucker%27s%20experiments%20%E2%80%93%20twins%20Pietro%2C%20who%20has%20superhuman%20speed%2C%20and%20Wanda%20Maximoff%2C%20who%20can%20manipulate%20minds%20and%20project%20energy%20%E2%80%93%20and%20apprehend%20Strucker%2C%20while%20Stark%20retrieves%20Loki%27s%20scepter.&model=general&lang=en&ud=the-avengers"
      
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": [
    {
      "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": [
        {
          "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.",
          "segment_type": "main",
          "inip": "0",
          "endp": "257",
          "confidence": "100",
          "score_tag": "N+",
          "agreement": "AGREEMENT",
          "polarity_term_list": [
            {
              "text": "raid",
              "inip": "125",
              "endp": "128",
              "confidence": "100",
              "score_tag": "N+",
              "sentimented_entity_list": [
                {
                  "form": "Tony Stark",
                  "id": "__6713084364163173541",
                  "variant": "Tony Stark",
                  "inip": "42",
                  "endp": "51",
                  "type": "Top>Person>FullName",
                  "score_tag": "N+"
                },
                {
                  "form": "Steve Rogers",
                  "id": "2418af20d6",
                  "variant": "Steve Rogers",
                  "inip": "54",
                  "endp": "65",
                  "type": "Top>Person>FullName",
                  "score_tag": "N+"
                },
                {
                  "form": "Thor",
                  "id": "5f8b6e87d6",
                  "variant": "Thor",
                  "inip": "68",
                  "endp": "71",
                  "type": "Top>Location>GeoPoliticalEntity",
                  "score_tag": "N+"
                },
                {
                  "form": "Thor",
                  "id": "8f9502a801",
                  "variant": "Thor",
                  "inip": "68",
                  "endp": "71",
                  "type": "Top>Person>FirstName",
                  "score_tag": "N+"
                },
                {
                  "form": "Bruce Banner",
                  "id": "__13726859781023558032",
                  "variant": "Bruce Banner",
                  "inip": "74",
                  "endp": "85",
                  "type": "Top",
                  "score_tag": "N+"
                },
                {
                  "form": "Natasha Romanoff",
                  "id": "__13891153709863729564",
                  "variant": "Natasha Romanoff",
                  "inip": "88",
                  "endp": "103",
                  "type": "Top>Person>FullName",
                  "score_tag": "N+"
                },
                {
                  "form": "Clint Barton",
                  "id": "__754254597092124379",
                  "variant": "Clint Barton",
                  "inip": "110",
                  "endp": "121",
                  "type": "Top>Person>FullName",
                  "score_tag": "N+"
                }
              ],
              "sentimented_concept_list": [
                {
                  "form": "country",
                  "id": "35229605d1",
                  "variant": "country",
                  "inip": "7",
                  "endp": "13",
                  "type": "Top>Location>GeoPoliticalEntity>Country",
                  "score_tag": "N+"
                },
                {
                  "form": "avenger",
                  "id": "65fdadcbff",
                  "variant": "Avengers",
                  "inip": "31",
                  "endp": "38",
                  "type": "Top>Person",
                  "score_tag": "N+"
                }
              ]
            }
          ],
          "sentimented_entity_list": [
            {
              "form": "Wolfgang",
              "id": "6aecb2b781",
              "variant": "Wolfgang",
              "inip": "153",
              "endp": "160",
              "type": "Top>Person>FirstName",
              "score_tag": "NONE"
            },
            {
              "form": "Loki",
              "id": "__1296309029595943509",
              "variant": "Loki",
              "inip": "253",
              "endp": "256",
              "type": "Top",
              "score_tag": "NONE"
            },
            {
              "form": "Sokovia",
              "id": "__14592390818495647481",
              "variant": "Sokovia",
              "inip": "18",
              "endp": "24",
              "type": "Top",
              "score_tag": "NONE"
            },
            {
              "form": "von Strucker",
              "id": "__3133061113578888878",
              "variant": "von Strucker",
              "inip": "162",
              "endp": "173",
              "type": "Top>Person>FullName",
              "score_tag": "NONE"
            }
          ],
          "segment_list": [
            {
              "text": "the Avengers",
              "segment_type": "main",
              "inip": "27",
              "endp": "38",
              "confidence": "100",
              "score_tag": "N",
              "agreement": "AGREEMENT",
              "polarity_term_list": [
                {
                  "text": "avenger",
                  "inip": "31",
                  "endp": "38",
                  "confidence": "100",
                  "score_tag": "N",
                  "sentimented_concept_list": [
                    {
                      "form": "avenger",
                      "id": "65fdadcbff",
                      "variant": "Avengers",
                      "inip": "31",
                      "endp": "38",
                      "type": "Top>Person",
                      "score_tag": "N"
                    }
                  ]
                }
              ]
            },
            {
              "text": "a Hydra outpost led by Wolfgang von Strucker",
              "segment_type": "main",
              "inip": "130",
              "endp": "173",
              "confidence": "100",
              "score_tag": "P",
              "agreement": "AGREEMENT",
              "polarity_term_list": [
                {
                  "text": "lead@V",
                  "inip": "146",
                  "endp": "148",
                  "confidence": "100",
                  "score_tag": "P"
                }
              ],
              "sentimented_entity_list": [
                {
                  "form": "Wolfgang",
                  "id": "6aecb2b781",
                  "variant": "Wolfgang",
                  "inip": "153",
                  "endp": "160",
                  "type": "Top>Person>FirstName",
                  "score_tag": "NONE"
                },
                {
                  "form": "von Strucker",
                  "id": "__3133061113578888878",
                  "variant": "von Strucker",
                  "inip": "162",
                  "endp": "173",
                  "type": "Top>Person>FullName",
                  "score_tag": "NONE"
                }
              ]
            }
          ]
        }
      ],
      "sentimented_entity_list": [
        {
          "form": "Steve Rogers",
          "id": "2418af20d6",
          "type": "Top>Person>FullName",
          "score_tag": "N+"
        },
        {
          "form": "Thor",
          "id": "5f8b6e87d6",
          "type": "Top>Location>GeoPoliticalEntity",
          "score_tag": "N+"
        },
        {
          "form": "Wolfgang",
          "id": "6aecb2b781",
          "type": "Top>Person>FirstName",
          "score_tag": "NONE"
        },
        {
          "form": "Thor",
          "id": "8f9502a801",
          "type": "Top>Person>FirstName",
          "score_tag": "N+"
        },
        {
          "form": "Loki",
          "id": "__1296309029595943509",
          "type": "Top",
          "score_tag": "NONE"
        },
        {
          "form": "Bruce Banner",
          "id": "__13726859781023558032",
          "type": "Top",
          "score_tag": "N+"
        },
        {
          "form": "Natasha Romanoff",
          "id": "__13891153709863729564",
          "type": "Top>Person>FullName",
          "score_tag": "N+"
        },
        {
          "form": "Sokovia",
          "id": "__14592390818495647481",
          "type": "Top",
          "score_tag": "NONE"
        },
        {
          "form": "von Strucker",
          "id": "__3133061113578888878",
          "type": "Top>Person>FullName",
          "score_tag": "NONE"
        },
        {
          "form": "Tony Stark",
          "id": "__6713084364163173541",
          "type": "Top>Person>FullName",
          "score_tag": "N+"
        },
        {
          "form": "Clint Barton",
          "id": "__754254597092124379",
          "type": "Top>Person>FullName",
          "score_tag": "N+"
        }
      ],
      "sentimented_concept_list": [
        {
          "form": "country",
          "id": "35229605d1",
          "type": "Top>Location>GeoPoliticalEntity>Country",
          "score_tag": "N+"
        },
        {
          "form": "avenger",
          "id": "65fdadcbff",
          "type": "Top>Person",
          "score_tag": "N+"
        }
      ]
    },
    {
      "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": [
        {
          "text": "They encounter two of Strucker's experiments – twins Pietro, who has superhuman speed",
          "segment_type": "secondary",
          "inip": "259",
          "endp": "343",
          "confidence": "100",
          "score_tag": "NONE",
          "agreement": "AGREEMENT",
          "polarity_term_list": [],
          "sentimented_entity_list": [
            {
              "form": "Pietro",
              "id": "__13802492502779249448",
              "variant": "Pietro",
              "inip": "312",
              "endp": "317",
              "type": "Top>Person",
              "score_tag": "NONE"
            },
            {
              "form": "Strucker",
              "id": "d2624f89ad",
              "variant": "Strucker",
              "inip": "281",
              "endp": "288",
              "type": "Top>Person>LastName",
              "score_tag": "NONE"
            }
          ],
          "sentimented_concept_list": [
            {
              "form": "twin",
              "id": "0e35ad0409",
              "variant": "twins",
              "inip": "306",
              "endp": "310",
              "type": "Top>Person",
              "score_tag": "NONE"
            },
            {
              "form": "twin",
              "id": "93f89a8a84",
              "variant": "twins",
              "inip": "306",
              "endp": "310",
              "type": "Top>Person",
              "score_tag": "NONE"
            },
            {
              "form": "speed",
              "id": "e50498110e",
              "variant": "speed",
              "inip": "339",
              "endp": "343",
              "type": "Top>Unit>SpeedUnit",
              "score_tag": "NONE"
            }
          ]
        },
        {
          "text": "Wanda Maximoff, who can manipulate minds and project energy – and apprehend Strucker",
          "segment_type": "main",
          "inip": "350",
          "endp": "433",
          "confidence": "100",
          "score_tag": "N",
          "agreement": "AGREEMENT",
          "polarity_term_list": [
            {
              "text": "manipulate",
              "inip": "370",
              "endp": "383",
              "confidence": "100",
              "score_tag": "N",
              "sentimented_entity_list": [
                {
                  "form": "Wanda Maximoff",
                  "id": "__16858144557084070716",
                  "variant": "Wanda Maximoff",
                  "inip": "350",
                  "endp": "363",
                  "type": "Top>Person>FullName",
                  "score_tag": "N"
                },
                {
                  "form": "Strucker",
                  "id": "d2624f89ad",
                  "variant": "Strucker",
                  "inip": "426",
                  "endp": "433",
                  "type": "Top>Person>LastName",
                  "score_tag": "N"
                }
              ]
            }
          ],
          "sentimented_concept_list": [
            {
              "form": "energy",
              "id": "b606e89e91",
              "variant": "energy",
              "inip": "403",
              "endp": "408",
              "type": "Top",
              "score_tag": "NONE"
            },
            {
              "form": "project",
              "id": "bde52a085f",
              "variant": "project",
              "inip": "395",
              "endp": "401",
              "type": "Top",
              "score_tag": "NONE"
            }
          ]
        },
        {
          "text": "while Stark retrieves Loki's scepter",
          "segment_type": "secondary",
          "inip": "436",
          "endp": "471",
          "confidence": "100",
          "score_tag": "NONE",
          "agreement": "AGREEMENT",
          "polarity_term_list": [],
          "sentimented_entity_list": [
            {
              "form": "Loki",
              "id": "__1296309029595943509",
              "variant": "Loki",
              "inip": "458",
              "endp": "461",
              "type": "Top",
              "score_tag": "NONE"
            },
            {
              "form": "Tony Stark",
              "id": "__6713084364163173541",
              "variant": "Stark",
              "inip": "442",
              "endp": "446",
              "type": "Top>Person>FullName",
              "score_tag": "NONE"
            }
          ]
        }
      ],
      "sentimented_entity_list": [
        {
          "form": "Loki",
          "id": "__1296309029595943509",
          "type": "Top",
          "score_tag": "NONE"
        },
        {
          "form": "Pietro",
          "id": "__13802492502779249448",
          "type": "Top>Person",
          "score_tag": "NONE"
        },
        {
          "form": "Wanda Maximoff",
          "id": "__16858144557084070716",
          "type": "Top>Person>FullName",
          "score_tag": "N"
        },
        {
          "form": "Tony Stark",
          "id": "__6713084364163173541",
          "type": "Top>Person>FullName",
          "score_tag": "NONE"
        },
        {
          "form": "Strucker",
          "id": "d2624f89ad",
          "type": "Top>Person>LastName",
          "score_tag": "N"
        }
      ],
      "sentimented_concept_list": [
        {
          "form": "twin",
          "id": "0e35ad0409",
          "type": "Top>Person",
          "score_tag": "NONE"
        },
        {
          "form": "twin",
          "id": "93f89a8a84",
          "type": "Top>Person",
          "score_tag": "NONE"
        },
        {
          "form": "energy",
          "id": "b606e89e91",
          "type": "Top",
          "score_tag": "NONE"
        },
        {
          "form": "project",
          "id": "bde52a085f",
          "type": "Top",
          "score_tag": "NONE"
        },
        {
          "form": "speed",
          "id": "e50498110e",
          "type": "Top>Unit>SpeedUnit",
          "score_tag": "NONE"
        }
      ]
    }
  ],
  "sentimented_entity_list": [
    {
      "form": "Steve Rogers",
      "id": "2418af20d6",
      "type": "Top>Person>FullName",
      "score_tag": "N+"
    },
    {
      "form": "Thor",
      "id": "5f8b6e87d6",
      "type": "Top>Location>GeoPoliticalEntity",
      "score_tag": "N+"
    },
    {
      "form": "Wolfgang",
      "id": "6aecb2b781",
      "type": "Top>Person>FirstName",
      "score_tag": "NONE"
    },
    {
      "form": "Thor",
      "id": "8f9502a801",
      "type": "Top>Person>FirstName",
      "score_tag": "N+"
    },
    {
      "form": "Loki",
      "id": "__1296309029595943509",
      "type": "Top",
      "score_tag": "NONE"
    },
    {
      "form": "Bruce Banner",
      "id": "__13726859781023558032",
      "type": "Top",
      "score_tag": "N+"
    },
    {
      "form": "Pietro",
      "id": "__13802492502779249448",
      "type": "Top>Person",
      "score_tag": "NONE"
    },
    {
      "form": "Natasha Romanoff",
      "id": "__13891153709863729564",
      "type": "Top>Person>FullName",
      "score_tag": "N+"
    },
    {
      "form": "Sokovia",
      "id": "__14592390818495647481",
      "type": "Top",
      "score_tag": "NONE"
    },
    {
      "form": "Wanda Maximoff",
      "id": "__16858144557084070716",
      "type": "Top>Person>FullName",
      "score_tag": "N"
    },
    {
      "form": "von Strucker",
      "id": "__3133061113578888878",
      "type": "Top>Person>FullName",
      "score_tag": "NONE"
    },
    {
      "form": "Tony Stark",
      "id": "__6713084364163173541",
      "type": "Top>Person>FullName",
      "score_tag": "N+"
    },
    {
      "form": "Clint Barton",
      "id": "__754254597092124379",
      "type": "Top>Person>FullName",
      "score_tag": "N+"
    },
    {
      "form": "Strucker",
      "id": "d2624f89ad",
      "type": "Top>Person>LastName",
      "score_tag": "N"
    }
  ],
  "sentimented_concept_list": [
    {
      "form": "twin",
      "id": "0e35ad0409",
      "type": "Top>Person",
      "score_tag": "NONE"
    },
    {
      "form": "country",
      "id": "35229605d1",
      "type": "Top>Location>GeoPoliticalEntity>Country",
      "score_tag": "N+"
    },
    {
      "form": "avenger",
      "id": "65fdadcbff",
      "type": "Top>Person",
      "score_tag": "N+"
    },
    {
      "form": "twin",
      "id": "93f89a8a84",
      "type": "Top>Person",
      "score_tag": "NONE"
    },
    {
      "form": "energy",
      "id": "b606e89e91",
      "type": "Top",
      "score_tag": "NONE"
    },
    {
      "form": "project",
      "id": "bde52a085f",
      "type": "Top",
      "score_tag": "NONE"
    },
    {
      "form": "speed",
      "id": "e50498110e",
      "type": "Top>Unit>SpeedUnit",
      "score_tag": "NONE"
    }
  ]
}