sentiment analysis with NLP
April 30 2017
Simple Sentiment Analysis with Clojure and the Standford’s NLP library.
The original java libraries and models of the standford-corenlp project can be found in:
[edu.stanford.nlp/stanford-corenlp "3.5.2"]
[edu.stanford.nlp/stanford-corenlp "3.5.2" :classifier "models"]
But using a Clojure wrapper make things slightly easier, and so the damionjunk/nlp dependency should be in your build file (Leiningen or Boot):
[damionjunk/nlp "0.3.0"]
You can use the function sentiment-maps. When call, the sentiment-maps function returns a map of :sentiment :text where the sentiment key is assigned a value between 1 and 4, where 1 is very negative and 4 is very positive.. Let’s try it with a simple positive sentence.:
(require '[damionjunk.nlp.stanford :refer :all])
(sentiment-maps
"I am really having a wonderful day.")
; ({:sentiment 4, :text "I am really having a wonderful day."})
A neutral sentence works pretty nicely as well.
(sentiment-maps
"The French elections are on Television today")
; ({:sentiment 2, :text "The French elections are on Television today"})
The last one should be rather neutral, but for because of the double use of don’t and really the analysis gets a bit confused and gets this as a negative sentiment:
(sentiment-maps
"I really don't want to think Marine will win the election")
; ({:sentiment 1, :text "I really don't want to think Marine will win the election"})