Extract opinions from text

Notes

  • Sentiment analysis is performed at the phrase level, meaning a single sentence can have multiple opinions.
  • An entity value of "THIS" means an opinion did not explicitly name an entity so it is assumed to be about the overall subject of the content (e.g., the product being reviewed).
  • A feature value of "general" means an opinion was expressed about the entity but not about a specific feature of that entity.
  • Not all opinions will have the entity and/or feature identified. If an opinion is discovered but it does not contain an auto-discovered or manually supplied entity or feature, it will still be returned to further characterize the sentiment of the text.
  • The API key and format parameters can be passed in the query string, while the other parameters should be posted as JSON in the message body (see example below).
$obj = array(
	"text" => "I love natural language processing!  NLP is lots of fun.",
	"entities" => array(array("nlp", "natural language processing"))
);

$options = array(
  'http' => array(
    'method'  => 'POST',
    'content' => json_encode($obj),
    'header'=>  "Content-Type: application/json\r\n" .
                "Accept: application/json\r\n"
    )
);

$context  = stream_context_create($options);
$result = file_get_contents("http://api.addstructure.com/v1/analysis/sentiment?key=APIKEY", false, $context);
echo($result);
Language