Sentiment analysis api/tool, for Java
Asked Answered
S

4

7

I'm writing a Java program and need to analyze small chunks of text (3-4 sentences, news articles paraphrased) for their sentiment. I just need to know whether the article is generally positive, negative or neutral.

For example, the following would ideally be classed as positive:

Kindle e-book sales soar for Amazon. Amazon.com says it is selling more e-books for its Kindle electronic reading device than paperback and hardback print editions combined

All I need is a very simple and quick to implement third party solution, that I can use in my program. It does not have to be totally accurate all the time. Licenses etc. are not an issue, so long as it is possible to trail the solution.

So far I have found a potential good solution, AlchemyAPI, but am struggling to actually use it.


If anyone has encountered this problem before and knows of a particularly good/easy solution, or of a really good tutorial, I would be very grateful :-)


(Also I apologize for the lack of code in this question.)

Spur answered 20/5, 2011 at 14:5 Comment(1)
"I apologize for the lack of code in this question." Any comment about the lack of a question? ;)Gecko
S
15

i just tested AlchemyAPI. it's not 100% accurate but i guess this sort of technology is still in its infancy.

you will need to register (free) to get an api key.

here's a sample usage: http://access.alchemyapi.com/calls/text/TextGetTextSentiment?apikey=<insert your api key>&sentiment=1&showSourceText=1&text=Kindle%20e-book%20sales%20soar%20for%20Amazon.%20Amazon.com%20says%20it%20is%20selling%20more%20e-books%20for%20its%20Kindle%20electronic%20reading%20device%20than%20paperback%20and%20hardback%20print%20editions%20combined

the inputs are:

  1. sentiment=1
  2. showSourceText=1
  3. text (i used your sample text, uri encoded)

i got the following output (neutral sentiment, instead of the expected positive sentiment):

<?xml version="1.0" encoding="UTF-8"?>
<results>    
    <status>OK</status>    
    <usage>By accessing AlchemyAPI or using information generated by AlchemyAPI, you are agreeing to be bound by the AlchemyAPI Terms of Use: http://www.alchemyapi.com/company/terms.html</usage>    
    <url></url>    
    <language>english</language>    
    <text>Kindle e-book sales soar for Amazon. Amazon.com says it is selling more e-books for its Kindle electronic reading device than paperback and hardback print editions combined</text>    
    <docSentiment>    
        <type>neutral</type>    
    </docSentiment>    
</results>


another sample usage: http://access.alchemyapi.com/calls/text/TextGetTextSentiment?apikey=<insert your api key>&sentiment=1&showSourceText=1&text=kindle%20is%20amazing

and the output:

<?xml version="1.0" encoding="UTF-8"?>    
<results>    
    <status>OK</status>    
    <usage>By accessing AlchemyAPI or using information generated by AlchemyAPI, you are agreeing to be bound by the AlchemyAPI Terms of Use: http://www.alchemyapi.com/company/terms.html</usage>    
    <url></url>    
    <language>english</language>    
    <text>kindle is amazing</text>    
    <docSentiment>    
        <type>positive</type>    
        <score>0.283568</score>    
    </docSentiment>    
</results>
Seymour answered 20/5, 2011 at 14:58 Comment(2)
how can i use alchemyAPI in java?Aureus
I am also looking for the same. Can you please tell me how to write it in java?Cabezon
A
0

So many more Sentiment Analysis APIs in 2018! :-) Depending on the features you need or language of the text, you may use one of those:

  • LexSent by hyindao at Algorithmia
  • Sentiment Analysis by mtman at Algorithmia
  • Sentiment Analysis by nlu at Algorithmia
  • Social Sentiment Analysis by nlu at Algorithmia
  • Amazon Web Services Comprehend
  • Aylien Text Analysis
  • Boson NLP Sentiment Analysis
  • Google Cloud Natural Language
  • IBM Watson NLU
  • Meaning Cloud Sentiment Analysis
  • Microsoft Cognitive Services Text Analytics
  • Repustate Text Analytics
  • Salesforce Einstein Language
  • Twinword Sentiment Analysis
  • TheSay PreCeive

For language support, feature and price comparison I would refer to this article.

Aether answered 26/4, 2018 at 3:37 Comment(0)
A
-1

If you need better sentiment analysis accuracy you can train your model yourself e.g. https://text2data.com/Sentiment-Model-Training

Amoral answered 28/11, 2018 at 13:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.