Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup controller for sentiment prediction example
- Loading branch information
Showing
18 changed files
with
145 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1 +1,2 @@ | |||
rvm use jruby-1.6.6 | rvm use jruby-1.6.7 | ||
export JRUBY_OPTS=--1.9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
module SentimentPredictorHelper | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
<h1>Sentiment Predictor</h1> | |||
|
|||
<%= form_for %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
require 'test_helper' | |||
|
|||
class SentimentPredictorControllerTest < ActionController::TestCase | |||
# test "the truth" do | |||
# assert true | |||
# end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
require 'test_helper' | |||
|
|||
class SentimentPredictorHelperTest < ActionView::TestCase | |||
end |