elm-sentiment is an Elm module that uses the AFINN-111 wordlist to perform sentiment analysis on arbitrary blocks of input text. Other wordlists are easy to integrate.
It is inspired by the the Sentiment-module for Node.js.
Please note that a wordlist-based approach for sentiment analysis might not be the best available approach for every (your) application. It is a simple and easy to use solution that does not need training like a Bayes classifier, that might perform better in classifying sentiments.
Trim a given input string.
import Sentiment
Sentiment.trim " --- Hello!, "
-- HelloSplit a string into words, turn all words into lowercase and remove everything that is not necessary (e. g. whitespace or special characters).
import Sentiment
Sentiment.tokenize " --- Hello, World! :) "
-- ["hello","world"]Analyse a string and return a struct of type Result. The function basically calls analyseWith, but with (good) defaults.
import Sentiment
result = Sentiment.analyse "Best movie ever!"
-- result.score == 3Analyse a given string and return a struct of type Result. This function expects a dictionary containing a word list, a dictionary with additional sentiment information and a tokenizer function.
import Sentiment
import WordList.Afinn as Afinn
import String
import Dict
result =
Sentiment.analyseWith
Afinn.get
(Dict.fromList [(":-)",3),(":-|", 0),(":-(", -3)])
(String.toLower >> String.words)
"Best movie ever! :-)"
-- result.score == 6
The Result-type describes the information returned by a call to analyse or analyseWith. The struct contains all tokens, the sum of positive and negative scores etc. The value comparative is the overall score divided by the number of words in the input string.