Search code examples
alchemyapi

Explain how to use TextGetTargetedSentiment of AlechmyAPI


1) Please explain what is the functionality of TextGetTargetedSentiment.

2) Please provide Java code snippet calling TextGetTargetedSentiment.

EDIT

API info is at http://www.alchemyapi.com/api/sentiment/textc.html#targetedsentiment

As answered by Zach below, code snippet given by AlchemyAPI is

        AlchemyAPI_TargetedSentimentParams sentimentParams = new AlchemyAPI_TargetedSentimentParams();
        sentimentParams.setShowSourceText(true);
        doc = alchemyObj.TextGetTargetedSentiment("This car is terrible.", "car", sentimentParams);
        System.out.print(getStringFromDocument(doc));

Result is

    :
 <totalTransactions>1</totalTransactions>
<language>english</language>
<text>This car is terrible.</text>
<docSentiment>
    <score>-0.776261</score>
    <type>negative</type>
</docSentiment>

If we change a statement to

"This car is superb." Then result is

:
<totalTransactions>1</totalTransactions>
<language>english</language>
<text>This car is superb.</text>
<docSentiment>
    <score>0.695491</score>
    <type>positive</type>
</docSentiment>

All files


Solution

  • TextGetTargetedSentiment finds the sentiment for a specific keyword within a text. This can be contrasted with document level sentiment (the endpoint TextGetTextSentiment), which looks at the whole text to determine sentiment.

    The AlchemyAPI Java SDK can help you get up and running quickly with the targeted sentiment call.