Coder Social home page Coder Social logo

sentimental's Introduction

sentimental

Simple sentiment analysis with Ruby

How it works

Sentences are tokenized and tokens are assigned a numerical score for their average sentiment. The total score is then used to determine the overall sentiment in relation to the threshold.

For example, the default threshold is 0.0. If a sentence has a score of 0, it is deemed "neutral". Higher than the thresold is "positive", lower is "negative".

If you set the threshold to a non-zero amount, e.g. 0.25:

  • Positive scores are > 0.25
  • Neutral scores are -0.25 - 0.25
  • Negative scores are < -0.25

Usage

# Create an instance for usage
analyzer = Sentimental.new

# Load the default sentiment dictionaries
analyzer.load_defaults

# And/or load your own dictionaries
analyzer.load_senti_file('path/to/your/file.txt')

# Set a global threshold
analyzer.threshold = 0.1

# Use your analyzer
analyzer.sentiment 'I love ruby'
#=> :positive

analyzer.sentiment 'I like ruby'
#=> :neutral

analyzer.sentiment 'I really like ruby'
#=> :positive

# You can make new analyzers with individual thresholds:
analyzer = Sentimental.new(threshold: 0.9)
analyzer.sentiment 'I love ruby'
#=> :positive

analyzer.sentiment 'I like ruby'
#=> :neutral

analyzer.sentiment 'I really like ruby'
#=> :neutral

# Get the numerical score of a string:
analyzer.score 'I love ruby'
#=> 0.925

Sentiment dictionaries

These are currently plain-text files containing whitespace-separated scores and tokens, e.g.:

1.0 Awesome
0.0 Meh
-1.0 Horrible

N-grams

You can parse n-grams of words by specifying their max size in the initializer:

  Sentimental.new(ngrams: 4)

The dictionary must have this format:

1.0 very happy
-2.0 no
0.0 meh

Installation

gem install sentimental

License

MIT License

Credits

Based largely on Christopher MacLellan's script: https://github.com/cmaclell/Basic-Tweet-Sentiment-Analyzer

Changes

  • 2013-10-13 Adding :-) to slang

sentimental's People

Contributors

alebian avatar baxter2 avatar bechirsegni avatar charlieegan3 avatar colstrom avatar davidrichey avatar jemminger avatar jmccartie avatar nicollet avatar seanslerner avatar theverything avatar zaratan 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.