0.0
The project is in a healthy, maintained state
A gem that use Generative AI for data sentiment analysis
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 4.2
~> 1.14
~> 3.3
 Project Readme

Sentiment-aI

✨ A gem that use Generative AI for data sentiment analysis ✨

The styling is to look like Sentimental, a tribute to the song Shunkan Sentimental by SCANDAL

Installation

Install the gem and add to the application's Gemfile by executing:

$ bundle add sentiment-ai

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install sentiment-ai

Compatibility

This gem is compatible with Ruby 3.1 or greater.

Usage

Require it in you code:

require "sentiment_ai"

Then use it like this:

sentiment = SentimentAI.new(YOUR_MODEL,YOUR_API_KEY)

For example:

sentiment = SentimentAI.new(:open_ai, OPEN_AI_KEY)

For the current version, the gem supports only OpenAI and Google Gemini.

After calling the model, use:

sentiment.analyze_sentence("I Love Ruby")
# => { :sentence => "I Love Ruby", :sentiment => "positive" }

For analyzing an array of sentence, use:

array = ["I Love Ruby", "I use Ruby"]
sentiment.analyze_array(array)
# => [{ :sentence => "I Love Ruby", :sentiment => "positive" }, { :sentence => "I use Ruby", :sentiment => "neutral" }]

For analyzing a CSV file, use:

sentiment.analyze_csv(csv_path, sentence_column, output_directory)

Assume that the CSV file is

comment
I love Ruby
I use Ruby

Analyze the file by calling: sentiment.analyze_csv("path/to/example.csv", "comment", "output/directory"). The output is:

comment,sentiment
I love Ruby, positive
I use Ruby, neutral

By default, the language used for the gem is English. If you want to use the other languages, Japanese for example, use:

sentiment = SentimentAI.new(:open_ai, OPEN_AI_KEY, :ja)
sentiment.analyze_sentence("Rubyは世界一プログラミング言語")
# => { :sentence => "Rubyは世界一プログラミング言語", :sentiment => "肯定的" }

Supported GenAI models

Language Code
OpenAI(GPT) :open_ai
Google Gemini :gemini_ai_pro

Supported languages

Language Code
English :en
Vietnamese :vi
Japanese :ja

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.