Giter Site home page Giter Site logo

sentimental's Introduction

Sentimental

A simple Clojure library designed to perform sentiment analysis using the ANEW: Affective norms for English words anew. This data has been augmented to include (and make use of) Spanish and Portuguese translations of the ANEW English terms.

Reference

Bradley, M. M., & Lang, P. J. (1999). Affective norms for English words (ANEW): Instruction manual and affective ratings. University of Florida: the Center for Research in Psychophysiology.

Usage

Add the following to your Leiningen configuration

;; yet to be released to clojars ...
[sentimental "0.1.0-SNAPSHOT"]

Once you've obtained the ANEW data file containing the words to scores map, usage is straightforward. Due to license issues of the ANEW lexicon, the data file is not distributed with this code.

(ns sentimental.example
  (:require [sentimental.anew :as anew]))

Load the lexicon:

(count @(:english anew/scores))
;; => 0
;; Remember to load the lexicon before trying to score any data.
(anew/load-lexicon "/path/to/sentiment/lexicon/original-anew-la.csv")

Counts of sentiment data:

;; The words are stored in a map. Word -> score
(count @(:english anew/scores))
;; => 1030

(count @(:spanish anew/scores))
(count @(:portuguese anew/scores))

Generate the ANEW score for a phrase:

;; Compute the EN ANEW for the provided phrase
(anew/score-phrase "I really love my dog." :english)
;; => {:words ["love" "dog"],
;;     :score {:v 8.145000219345093, :d 6.680000066757202, :a 6.1000001430511475}}

Find a specific word in the initialized map.

;; Grab a value 
(get @(:english anew/scores) "love")
;; => {:a 6.44, :d 7.11, :v 8.72}

Generate the ANEW score for a Spanish phrase:

;; Compute the ES ANEW for the provided phrase
(anew/score-phrase "Odio mi pájaro, amo a mi perro. amor." :spanish)
;; ==> {:words ["odio" "pájaro" "perro" "amor"],
;;      :score {:v 6.385000109672546, :d 5.520000100135803, :a 5.507500052452087}}

Compute the "Best of Three" match for a phrase where we're only interested in scoring for one language.

(anew/score-phrase-langs
 "Odio mi pájaro, amo a mi perro. amor. I really love my dog.")
;; => {:v 6.385000109672546, :d 5.520000100135803, :a 5.507500052452087,
;;     :anew-es {:words ["odio" "pájaro" "perro" "amor"],
;;              :score {:v 6.385000109672546,
;;                      :d 5.520000100135803,
;;                      :a 5.507500052452087}}}

License

Copyright © 2012 Damion Junk

Distributed under the Eclipse Public License, the same as Clojure.

sentimental's People

Contributors

damionjunk avatar adoyleatcaci avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.