Permalink
Browse files

Setup controller for sentiment prediction example

  • Loading branch information...
1 parent b9000e5 commit d13224ff35ed1021bd6dca62ed79545888176027 @ryanstout committed Apr 11, 2012
View
3 .rvmrc
@@ -1 +1,2 @@
-rvm use jruby-1.6.6
+rvm use jruby-1.6.7
+export JRUBY_OPTS=--1.9
View
@@ -1,11 +1,12 @@
source 'https://rubygems.org'
-gem 'rails', '3.2.1'
+gem 'rails', '3.2.0'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
-gem 'sqlite3'
+# gem 'sqlite3'
+# gem 'mysql2'
# Gems used only for assets and not required
View
@@ -1,31 +1,31 @@
GEM
remote: https://rubygems.org/
specs:
- actionmailer (3.2.1)
- actionpack (= 3.2.1)
+ actionmailer (3.2.0)
+ actionpack (= 3.2.0)
mail (~> 2.4.0)
- actionpack (3.2.1)
- activemodel (= 3.2.1)
- activesupport (= 3.2.1)
+ actionpack (3.2.0)
+ activemodel (= 3.2.0)
+ activesupport (= 3.2.0)
builder (~> 3.0.0)
erubis (~> 2.7.0)
- journey (~> 1.0.1)
+ journey (~> 1.0.0)
rack (~> 1.4.0)
rack-cache (~> 1.1)
rack-test (~> 0.6.1)
sprockets (~> 2.1.2)
- activemodel (3.2.1)
- activesupport (= 3.2.1)
+ activemodel (3.2.0)
+ activesupport (= 3.2.0)
builder (~> 3.0.0)
- activerecord (3.2.1)
- activemodel (= 3.2.1)
- activesupport (= 3.2.1)
+ activerecord (3.2.0)
+ activemodel (= 3.2.0)
+ activesupport (= 3.2.0)
arel (~> 3.0.0)
tzinfo (~> 0.3.29)
- activeresource (3.2.1)
- activemodel (= 3.2.1)
- activesupport (= 3.2.1)
- activesupport (3.2.1)
+ activeresource (3.2.0)
+ activemodel (= 3.2.0)
+ activesupport (= 3.2.0)
+ activesupport (3.2.0)
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
@@ -36,7 +36,7 @@ GEM
coffee-script (2.2.0)
coffee-script-source
execjs
- coffee-script-source (1.2.0)
+ coffee-script-source (1.3.1)
erubis (2.7.0)
execjs (1.3.0)
multi_json (~> 1.0)
@@ -47,6 +47,7 @@ GEM
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
json (1.6.6)
+ json (1.6.6-java)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
@@ -61,17 +62,17 @@ GEM
rack
rack-test (0.6.1)
rack (>= 1.0)
- rails (3.2.1)
- actionmailer (= 3.2.1)
- actionpack (= 3.2.1)
- activerecord (= 3.2.1)
- activeresource (= 3.2.1)
- activesupport (= 3.2.1)
+ rails (3.2.0)
+ actionmailer (= 3.2.0)
+ actionpack (= 3.2.0)
+ activerecord (= 3.2.0)
+ activeresource (= 3.2.0)
+ activesupport (= 3.2.0)
bundler (~> 1.0)
- railties (= 3.2.1)
- railties (3.2.1)
- actionpack (= 3.2.1)
- activesupport (= 3.2.1)
+ railties (= 3.2.0)
+ railties (3.2.0)
+ actionpack (= 3.2.0)
+ activesupport (= 3.2.0)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
@@ -88,7 +89,6 @@ GEM
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
- sqlite3 (1.3.5)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
@@ -100,12 +100,12 @@ GEM
multi_json (>= 1.0.2)
PLATFORMS
+ java
ruby
DEPENDENCIES
coffee-rails (~> 3.2.1)
jquery-rails
- rails (= 3.2.1)
+ rails (= 3.2.0)
sass-rails (~> 3.2.3)
- sqlite3
uglifier (>= 1.0.3)
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -0,0 +1,3 @@
+// Place all the styles related to the SentimentPredictor controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,46 @@
+require 'java'
+
+# Set the weka home
+ENV['WEKA_HOME'] = File.join(Rails.root, '/lib/weka-3-7-5/packages')
+require Rails.root + 'lib/weka-3-7-5/packages/packages/LibSVM/LibSVM.jar'
+require Rails.root + 'lib/weka-3-7-5/packages/packages/LibSVM/lib/libsvm.jar'
+require Rails.root + 'lib/weka-3-7-5/packages/packages/LibLINEAR/LibLINEAR.jar'
+require Rails.root + 'lib/weka-3-7-5/packages/packages/LibSVM/lib/libsvm.jar'
+require Rails.root + 'lib/weka-3-7-5/packages/packages/LibLINEAR/lib/liblinear-1.8.jar'
+require Rails.root + 'lib/weka-3-7-5/weka.jar'
+
+include_class "weka.core.Instances"
+include_class "weka.core.Instance"
+include_class "java.io.FileReader"
+include_class "weka.core.Utils"
+include_class "weka.core.SerializationHelper"
+include_class "weka.core.DenseInstance"
+include_class "weka.core.SparseInstance"
+
+
+
+
+class SentimentPredictorController < ApplicationController
+ def index
+
+ @arff ||= FileReader.new(Rails.root.join("data/sentiment.arff").to_s)
+ @classifier ||= SerializationHelper.read(Rails.root.join("models/sentiment.model").to_s)
+
+ @data ||= begin
+ Instances.new(@arff,1).tap do |data|
+ data.setClassIndex data.num_attributes - 1 if data.class_index == -1
+ end
+ end
+
+ instance = SparseInstance.new(@data.num_attributes)
+ instance.set_dataset(@data)
+ instance.set_value(@data.attribute(0), params[:text])
+
+ result = @classifier.distribution_for_instance(instance).first
+
+ render :text => result
+ end
+
+ def create
+ end
+end
@@ -0,0 +1,2 @@
+module SentimentPredictorHelper
+end
@@ -0,0 +1,3 @@
+<h1>Sentiment Predictor</h1>
+
+<%= form_for %>
View
@@ -1,6 +1,12 @@
require File.expand_path('../boot', __FILE__)
-require 'rails/all'
+# Pick the frameworks you want:
+# require "active_record/railtie"
+require "action_controller/railtie"
+require "action_mailer/railtie"
+require "active_resource/railtie"
+require "sprockets/railtie"
+require "rails/test_unit/railtie"
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
View
@@ -1,25 +0,0 @@
-# SQLite version 3.x
-# gem install sqlite3
-#
-# Ensure the SQLite 3 gem is defined in your Gemfile
-# gem 'sqlite3'
-development:
- adapter: sqlite3
- database: db/development.sqlite3
- pool: 5
- timeout: 5000
-
-# Warning: The database defined as "test" will be erased and
-# re-generated from your development database when you run "rake".
-# Do not set this db to the same as development or production.
-test:
- adapter: sqlite3
- database: db/test.sqlite3
- pool: 5
- timeout: 5000
-
-production:
- adapter: sqlite3
- database: db/production.sqlite3
- pool: 5
- timeout: 5000
@@ -22,12 +22,6 @@
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
- # Raise exception on mass assignment protection for Active Record models
- config.active_record.mass_assignment_sanitizer = :strict
-
- # Log the query plan for queries taking more than this (works
- # with SQLite, MySQL, and PostgreSQL)
- config.active_record.auto_explain_threshold_in_seconds = 0.5
# Do not compress assets
config.assets.compress = false
@@ -61,7 +61,4 @@
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
- # Log the query plan for queries taking more than this (works
- # with SQLite, MySQL, and PostgreSQL)
- # config.active_record.auto_explain_threshold_in_seconds = 0.5
end
View
@@ -1,4 +1,6 @@
Mlexample::Application.routes.draw do
+ resources :sentiment_predictor
+
# The priority is based upon order of creation:
# first created -> highest priority.
View
@@ -26,8 +26,8 @@
arff_file = File.dirname(__FILE__) + "/../../data/sentiment.arff"
-# options = "weka.classifiers.meta.FilteredClassifier -F \"weka.filters.unsupervised.attribute.StringToWordVector -R first-last -P wv- -W 50000 -prune-rate -1.0 -T -N 0 -L -stemmer weka.core.stemmers.NullStemmer -M 1 -tokenizer \\\"weka.core.tokenizers.NGramTokenizer -delimiters \\\\\\\" \\\\\\\\\\r\\\\\\\\\\n\\\\\\\\\\t.,;:\\\\\\\\\\'\\\\\\\\\\\\\\\"()?!\\\\\\\" -max 2 -min 1\\\"\" -W weka.classifiers.functions.LibLINEAR -- -S 0 -C 1.0 -E 0.01 -B 1.0 -P"
-options = "weka.classifiers.meta.FilteredClassifier -F \"weka.filters.unsupervised.attribute.StringToWordVector -R first-last -P wv- -W 1000 -prune-rate -1.0 -T -N 0 -L -stemmer weka.core.stemmers.NullStemmer -M 1 \" -W weka.classifiers.functions.LibLINEAR -- -S 0 -C 1.0 -E 0.01 -B 1.0 -P"
+options = "weka.classifiers.meta.FilteredClassifier -F \"weka.filters.unsupervised.attribute.StringToWordVector -R first-last -P wv- -W 50000 -prune-rate -1.0 -T -N 0 -L -stemmer weka.core.stemmers.NullStemmer -M 1 -tokenizer \\\"weka.core.tokenizers.NGramTokenizer -delimiters \\\\\\\" \\\\\\\\\\r\\\\\\\\\\n\\\\\\\\\\t.,;:\\\\\\\\\\'\\\\\\\\\\\\\\\"()?!\\\\\\\" -max 2 -min 1\\\"\" -W weka.classifiers.functions.LibLINEAR -- -S 0 -C 1.0 -E 0.01 -B 1.0 -P"
+# options = "weka.classifiers.meta.FilteredClassifier -F \"weka.filters.unsupervised.attribute.StringToWordVector -R first-last -P wv- -W 1000 -prune-rate -1.0 -T -N 0 -L -stemmer weka.core.stemmers.NullStemmer -M 1 \" -W weka.classifiers.functions.LibLINEAR -- -S 0 -C 1.0 -E 0.01 -B 1.0 -P"
arff = FileReader.new(arff_file)
data = Instances.new(arff)
@@ -1,4 +1,4 @@
-2012-04-05 14:07:26 weka.gui.GUIChooser main
+2012-04-10 14:44:22 weka.gui.GUIChooser main
INFO: Logging started
Refreshing GOE props...
---Registering Weka Editors---
@@ -9,35 +9,47 @@ Trying to add database driver (JDBC): com.mckoi.JDBCDriver - Warning, not in CLA
Trying to add database driver (JDBC): org.hsqldb.jdbcDriver - Warning, not in CLASSPATH?
[KnowledgeFlow] Loading properties and plugins...
[KnowledgeFlow] Initializing KF...
-2012-04-05 14:07:29 weka.gui.explorer.Explorer <init>
+2012-04-10 14:44:26 weka.gui.explorer.Explorer <init>
INFO: Weka Explorer
-2012-04-05 14:07:29 weka.gui.explorer.Explorer <init>
+2012-04-10 14:44:26 weka.gui.explorer.Explorer <init>
INFO: (c) 1999-2011 The University of Waikato, Hamilton, New Zealand
-2012-04-05 14:07:29 weka.gui.explorer.Explorer <init>
+2012-04-10 14:44:26 weka.gui.explorer.Explorer <init>
INFO: web: http://www.cs.waikato.ac.nz/~ml/weka/
-2012-04-05 14:07:29 weka.gui.explorer.Explorer <init>
-INFO: Started on Thursday, 5 April 2012
-2012-04-05 14:07:49 weka.gui.explorer.PreprocessPanel$14 run
-INFO: Base relation is now Relationships (15570 instances)
-2012-04-05 14:07:59 weka.gui.explorer.AttributeSelectionPanel$10 run
+2012-04-10 14:44:26 weka.gui.explorer.Explorer <init>
+INFO: Started on Tuesday, 10 April 2012
+2012-04-10 14:44:37 weka.gui.explorer.PreprocessPanel$14 run
+INFO: Base relation is now Tweets (19999 instances)
+2012-04-10 14:44:54 weka.gui.explorer.PreprocessPanel$15 run
+INFO: Command: weka.filters.unsupervised.attribute.StringToWordVector -R first-last -P w- -W 1000 -prune-rate -1.0 -N 0 -L -stemmer weka.core.stemmers.NullStemmer -M 1 -tokenizer "weka.core.tokenizers.WordTokenizer -delimiters \" \\r\\n\\t.,;:\\\'\\\"()?!\""
+2012-04-10 14:44:55 weka.gui.explorer.PreprocessPanel$14 run
+INFO: Base relation is now Tweets-weka.filters.unsupervised.attribute.StringToWordVector-R1-Pw--W1000-prune-rate-1.0-N0-L-stemmerweka.core.stemmers.NullStemmer-M1-tokenizerweka.core.tokenizers.WordTokenizer -delimiters " \r\n\t.,;:\'\"()?!" (19999 instances)
+2012-04-10 14:45:07 weka.gui.explorer.AttributeSelectionPanel$10 run
INFO: Started weka.attributeSelection.CfsSubsetEval
-2012-04-05 14:07:59 weka.gui.explorer.AttributeSelectionPanel$10 run
+2012-04-10 14:45:07 weka.gui.explorer.AttributeSelectionPanel$10 run
INFO: Command: weka.attributeSelection.CfsSubsetEval -s "weka.attributeSelection.BestFirst -D 1 -N 5"
-2012-04-05 14:07:59 weka.gui.explorer.AttributeSelectionPanel$10 run
+2012-04-10 14:45:07 weka.gui.explorer.AttributeSelectionPanel$10 run
INFO: Filter command: weka.filters.supervised.attribute.AttributeSelection -E "weka.attributeSelection.CfsSubsetEval " -S "weka.attributeSelection.BestFirst -D 1 -N 5"
-2012-04-05 14:07:59 weka.gui.explorer.AttributeSelectionPanel$10 run
+2012-04-10 14:45:07 weka.gui.explorer.AttributeSelectionPanel$10 run
INFO: Meta-classifier command: weka.classifiers.meta.AttributeSelectedClassifier -E "weka.attributeSelection.CfsSubsetEval " -S "weka.attributeSelection.BestFirst -D 1 -N 5" -W weka.classifiers.trees.J48 -- -C 0.25 -M 2
-2012-04-05 14:08:58 weka.gui.explorer.AttributeSelectionPanel$10 run
+2012-04-10 14:46:45 weka.gui.explorer.AttributeSelectionPanel$10 run
INFO: Finished weka.attributeSelection.CfsSubsetEval weka.attributeSelection.BestFirst
-2012-04-05 14:10:16 weka.gui.explorer.PreprocessPanel$14 run
-INFO: Base relation is now Relationships (15579 instances)
-2012-04-05 14:10:28 weka.gui.explorer.AttributeSelectionPanel$10 run
+2012-04-10 14:47:13 weka.gui.explorer.AttributeSelectionPanel$10 run
INFO: Started weka.attributeSelection.InfoGainAttributeEval
-2012-04-05 14:10:28 weka.gui.explorer.AttributeSelectionPanel$10 run
+2012-04-10 14:47:13 weka.gui.explorer.AttributeSelectionPanel$10 run
INFO: Command: weka.attributeSelection.InfoGainAttributeEval -s "weka.attributeSelection.Ranker -T -1.7976931348623157E308 -N -1"
-2012-04-05 14:10:28 weka.gui.explorer.AttributeSelectionPanel$10 run
+2012-04-10 14:47:13 weka.gui.explorer.AttributeSelectionPanel$10 run
INFO: Filter command: weka.filters.supervised.attribute.AttributeSelection -E "weka.attributeSelection.InfoGainAttributeEval " -S "weka.attributeSelection.Ranker -T -1.7976931348623157E308 -N -1"
-2012-04-05 14:10:28 weka.gui.explorer.AttributeSelectionPanel$10 run
+2012-04-10 14:47:13 weka.gui.explorer.AttributeSelectionPanel$10 run
INFO: Meta-classifier command: weka.classifiers.meta.AttributeSelectedClassifier -E "weka.attributeSelection.InfoGainAttributeEval " -S "weka.attributeSelection.Ranker -T -1.7976931348623157E308 -N -1" -W weka.classifiers.trees.J48 -- -C 0.25 -M 2
-2012-04-05 14:10:35 weka.gui.explorer.AttributeSelectionPanel$10 run
+2012-04-10 14:47:57 weka.gui.explorer.AttributeSelectionPanel$10 run
+INFO: Finished weka.attributeSelection.InfoGainAttributeEval weka.attributeSelection.Ranker
+2012-04-10 15:07:31 weka.gui.explorer.AttributeSelectionPanel$10 run
+INFO: Started weka.attributeSelection.InfoGainAttributeEval
+2012-04-10 15:07:31 weka.gui.explorer.AttributeSelectionPanel$10 run
+INFO: Command: weka.attributeSelection.InfoGainAttributeEval -s "weka.attributeSelection.Ranker -T -1.7976931348623157E308 -N -1"
+2012-04-10 15:07:31 weka.gui.explorer.AttributeSelectionPanel$10 run
+INFO: Filter command: weka.filters.supervised.attribute.AttributeSelection -E "weka.attributeSelection.InfoGainAttributeEval " -S "weka.attributeSelection.Ranker -T -1.7976931348623157E308 -N -1"
+2012-04-10 15:07:31 weka.gui.explorer.AttributeSelectionPanel$10 run
+INFO: Meta-classifier command: weka.classifiers.meta.AttributeSelectedClassifier -E "weka.attributeSelection.InfoGainAttributeEval " -S "weka.attributeSelection.Ranker -T -1.7976931348623157E308 -N -1" -W weka.classifiers.trees.J48 -- -C 0.25 -M 2
+2012-04-10 15:12:51 weka.gui.explorer.AttributeSelectionPanel$10 run
INFO: Finished weka.attributeSelection.InfoGainAttributeEval weka.attributeSelection.Ranker
View
Binary file not shown.
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class SentimentPredictorControllerTest < ActionController::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class SentimentPredictorHelperTest < ActionView::TestCase
+end

0 comments on commit d13224f

Please sign in to comment.