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.
elm package install ggb/elm-sentiment
Usage is straightforward:
import Sentiment
tweet = """
#StarWars fans are the best kind of people.
I'm so, so lucky & honored to get to hang
out with you at Celebration. Thank you for
being you.
"""
Sentiment.analyse tweet
-- Result:
--
-- { tokens = ["starwars","fans","are","the","best", ... ,"for","being","you"]
-- , score = 12
-- , words = ["best","kind","lucky","honored","thank"]
-- , positive = [3,2,3,2,2]
-- , negative = []
-- , comparative = 0.42857142857142855
-- }
For more advanced usage please take a look at the function-level documentation and especially at the analyseWith-function.
There are lots of possibilities to improve the current module. Some ideas:
- handling of negations
- more and different word lists
- compression of word lists
- possibility to train a model (word list as fallback or support)