Skip to content
Browse files

add 'Blog' tab

  • Loading branch information...
1 parent abeed31 commit fe17d7abfd15a41c0cd6e423ca4bbf36454c7f70 @feedbackmine committed Apr 14, 2009
View
22 app/controllers/projects_controller.rb
@@ -37,25 +37,9 @@ def update
def show
@project = Project.find_by_name params[:id]
- @feedbacks = @project.feedbacks.paginate :page => params[:page], :per_page => 50, :order => 'created_at DESC'
- end
-
- def positive
- @project = Project.find_by_name params[:id]
- @feedbacks = @project.feedbacks.positive.paginate :page => params[:page], :per_page => 50, :order => 'created_at DESC'
- render :action => :show
- end
-
- def negative
- @project = Project.find_by_name params[:id]
- @feedbacks = @project.feedbacks.negative.paginate :page => params[:page], :per_page => 50, :order => 'created_at DESC'
- render :action => :show
- end
-
- def other
- @project = Project.find_by_name params[:id]
- @feedbacks = @project.feedbacks.other.paginate :page => params[:page], :per_page => 50, :order => 'created_at DESC'
- render :action => :show
+ @source = params[:source] ? params[:source] : 'twitter'
+ @polarity = params[:polarity] ? params[:polarity] : 'all'
+ @feedbacks = @project.feedbacks.sentiment(@source, @polarity).paginate :page => params[:page], :per_page => 50, :order => 'created_at DESC'
end
def destroy
View
32 app/models/feedback.rb
@@ -10,14 +10,14 @@ class Feedback < ActiveRecord::Base
belongs_to :project
serialize :description
- named_scope :positive, :conditions => {:polarity => POSITIVE}
- named_scope :negative, :conditions => {:polarity => NEGATIVE}
- named_scope :other, :conditions => {:polarity => OTHER}
+ named_scope :sentiment, lambda { |source, polarity|
+ {:conditions => { :source => source_name2int(source), :polarity => polarity_name2int(polarity) } }
+ }
def html_description
result = ''
description.each {|s|
- result << "<span class='#{int2name(s[0])}'>#{s[1]}</span>"
+ result << "<span class='#{polarity_int2name(s[0])}'>#{s[1]}</span>"
}
return result
end
@@ -38,7 +38,7 @@ def author_id
end
private
- def int2name i
+ def polarity_int2name i
case i
when NEGATIVE
'negative'
@@ -51,6 +51,28 @@ def int2name i
end
end
+ def self.source_name2int source
+ case source
+ when 'twitter'
+ TWITTER
+ else
+ BLOG
+ end
+ end
+
+ def self.polarity_name2int name
+ case name
+ when 'negative'
+ NEGATIVE
+ when 'mixed'
+ MIXED
+ when 'positive'
+ POSITIVE
+ else
+ OTHER
+ end
+ end
+
#'msaleem (Muhammad Saleem)' -> msaleem
def author_id
author_name.split(' ').first
View
30 app/views/projects/show.html.erb
@@ -15,16 +15,29 @@
What the Community is Saying about '<%= @project.name %>' :
</h3>
-<ul class='tabs'>
- <li><a href="#">Twitter (<%= @feedbacks.size %>)</a></li>
-</ul>
+<div id='tab-set'>
+ <ul class='tabs'>
+ <li>
+ <%= link_to "Twitter", feedback_url(:id => @project.name, :source => 'twitter', :polarity => 'all') %>
+ </li>
+ <li>
+ <%= link_to "Blog", feedback_url(:id => @project.name, :source => 'blog', :polarity => 'all') %>
+ </li>
+ </ul>
+</id>
<div class='filter'>
-Sentiment Filter:
-<%= link_to 'All', project_url(@project) %>,
-<span class='positive'><%= link_to 'Positive', positive_url(@project) %></span>,
-<span class='negative'><%= link_to 'Negative', negative_url(@project) %></span>,
-<span class='other'> <%= link_to 'Other', other_url(@project) %></span>
+ Sentiment Filter:
+ <%= link_to 'All', feedback_url(:id => @project.name, :source => @source, :polarity => 'all') %>,
+ <span class='positive'>
+ <%= link_to 'Positive', feedback_url(:id => @project.name, :source => @source, :polarity => 'positive') %>
+ </span>,
+ <span class='negative'>
+ <%= link_to 'Negative', feedback_url(:id => @project.name, :source => @source, :polarity => 'negative') %>
+ </span>,
+ <span class='other'>
+ <%= link_to 'Other', feedback_url(:id => @project.name, :source => @source, :polarity => 'other') %>
+ </span>
</div>
<hr/>
@@ -46,3 +59,4 @@ Sentiment Filter:
<% end %>
<%= will_paginate @feedbacks %>
+
View
4 config/routes.rb
@@ -47,9 +47,7 @@
map.resources :users
map.resource :user_session
- map.positive 'projects/:id/positive', :controller => 'projects', :action => 'positive'
- map.negative 'projects/:id/negative', :controller => 'projects', :action => 'negative'
- map.other 'projects/:id/other', :controller => 'projects', :action => 'other'
+ map.feedback 'projects/:id/:source/:polarity', :controller => 'projects', :action => 'show'
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
View
9 db/migrate/20090414044947_add_title_to_feedback.rb
@@ -0,0 +1,9 @@
+class AddTitleToFeedback < ActiveRecord::Migration
+ def self.up
+ add_column :feedbacks, :title, :string
+ end
+
+ def self.down
+ remove_column :feedbacks, :title
+ end
+end
View
3 db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20090412002526) do
+ActiveRecord::Schema.define(:version => 20090414044947) do
create_table "feedbacks", :force => true do |t|
t.string "url"
@@ -24,6 +24,7 @@
t.datetime "updated_at"
t.integer "source"
t.string "url_id"
+ t.string "title"
end
add_index "feedbacks", ["url_id"], :name => "index_feedbacks_on_url_id", :unique => true
View
11 jobs/crawler.rb
@@ -11,7 +11,7 @@
class Crawler
- COLUMNS = [:project_id, :created_at, :description, :url, :polarity, :author_image, :author_name, :author_url, :source, :url_id]
+ COLUMNS = [:project_id, :created_at, :title, :description, :url, :polarity, :author_image, :author_name, :author_url, :source, :url_id]
def initialize
@logger = Logger.new('log/crawler.log')
@@ -26,26 +26,27 @@ def crawl feedbacks, source, project_id, url, use_spam_filter
doc = Nokogiri::HTML(xml)
doc.xpath("//entry").each do |entry|
title = entry.at("./title").content
+ content = entry.at("./content").content
- language = @language_detector.detect(title)
+ language = @language_detector.detect(content)
if language != 'en'
puts "#{language}: #{title}"
next
end
- if use_spam_filter && @spam_filter.is_spam?(title)
+ if use_spam_filter && @spam_filter.is_spam?(content)
puts "spam: #{title}"
next
end
- polarity, content = @sentiment_classifier.process(title)
+ polarity, description = @sentiment_classifier.process(title)
published = Time.zone.parse(entry.at("./published").content)
link = entry.at("./link[@rel='alternate']")["href"]
author_image = entry.at("./link[@rel='image']")["href"] rescue nil
author_name = entry.at("./author/name").content
author_url = entry.at("./author/uri").content
- feedbacks << [project_id, published, content, link, polarity, author_image, author_name, author_url, source, project_id.to_s + link]
+ feedbacks << [project_id, published, title, description, link, polarity, author_image, author_name, author_url, source, project_id.to_s + link]
end
rescue Exception => e
puts e
View
2 public/stylesheets/blueprint/plugins/tabs/screen.css
@@ -13,7 +13,7 @@
.tabs {
border-bottom:1px solid #ccc;
height:1%; /* fixing IE 6 */
- margin:0 0 .25em 0;
+ margin:0 0 0 0;
min-height:auto;
overflow:auto;
}
View
5 public/stylesheets/sentimenthub.css
@@ -18,5 +18,8 @@ span.other {
}
.filter {
- background:#ddd;
+ background:#666;
+ color:#fff;
+ //font-weight:bold;
+ padding:.15em .33em .25em .33em;
}

0 comments on commit fe17d7a

Please sign in to comment.
Something went wrong with that request. Please try again.