code
stringlengths
1
1.73M
language
stringclasses
1 value
# = UnitTest : ActiveRecord # This file is part of the unit tests for the ETL package # # == Description # The tests in this file verify the correct definition of the ActiveRecord relationships # # == Author # Riccardo Govoni [battlehorse@gmail.com] # # == Copyright # Copyright(c) 2007 - bayes-swarm project. # Licensed...
Ruby
# = UnitTest : JSON # This file is part of the unit tests for the ETL package # # == Description # The tests in this file verify the correct functioning of JSON mapping for # special types such as Time and BigDecimal # # == Author # Riccardo Govoni [battlehorse@gmail.com] # # == Copyright # Copyright(c) 2007 - bayes-sw...
Ruby
# = UnitTest : Multiplex DTOs # This file is part of the unit tests for the ETL package # # == Description # The tests in this file verify the correct functioning of multiplex dtos, both # lazy and not. # # == Author # Riccardo Govoni [battlehorse@gmail.com] # # == Copyright # Copyright(c) 2007 - bayes-swarm project....
Ruby
require 'net/http' require 'rss/1.0' require 'rss/2.0' require 'open-uri' require 'time' class HttpExtractor def extract(page) response = extract_with_redirect(page.url) response.body end def extract_with_redirect(url, limit=10, try=1) fail "#{self.class.name}: http redirect too deep" if limit.zero? ...
Ruby
require 'rubygems' require 'ferret' require 'swarm_normalization' include Customlists class FerretStemmer def initialize @langs = Customlists.bayesfor_stopwords end def stem(content, lang) analyzer = StopAndStemAnalyzer.new stream = analyzer.token_stream(nil, content, @langs[lang]) token ...
Ruby
class HtmlTidy def clean(content) strip_tags_and_entities(tidy(content)) end def tidy(content) File.open("tidy.tmp","w") do |file| file.puts content end clean_content = %x{ tidy tidy.tmp } File.delete("tidy.tmp") return clean_content end def strip_tags...
Ruby
#!/usr/bin/env ruby require 'rubygems' require 'swarm_init' require 'swarm_support' require 'swarm_ar_support' notidy = true pages = Page.find(:all) for page in pages begin interesting_stems = Intword.get_intwords_hash(page.language_id) counted_intstems, pop_stems = swarm_extract(page, notidy, interesting_...
Ruby
#!/usr/bin/env ruby require 'rubygems' require 'swarm_init' require 'swarm_support' require 'swarm_ar_support' notidy = true pages = Page.find(:all) for page in pages begin interesting_stems = Intword.get_intwords_hash(page.language_id) counted_intstems, pop_stems = swarm_extract(page, notidy, interesting_...
Ruby
#!/usr/bin/env ruby require 'time' # Option parsing require 'optparse' require 'ostruct' # bayes-swarm specific require 'swarm_support' class Page attr_accessor :id, :url, :language_name, :kind_name, :last_scantime def initialize(id, url, language_name, kind_name, last_scantime) @id = id @url = url ...
Ruby
# Copyright 2007 Associazione Bayesfor. # Created by Riccardo Govoni (riccardo.govoni@bayesfor.eu) require 'digest/md5' require 'tmpdir' require 'pathname' # A module which contains storage-related utils module Storage # A mixin for extractors that need file-saving capabilities module FileSaver # Canary...
Ruby
require 'yaml' # Load global options configFile = "swarm_shoal_options.yml" $opts = YAML.load(File.open(configFile)) # Enables file storage if required storage_opts = $opts['storage'] if storage_opts && storage_opts[:filesaver] == 'active' require 'extractor' require 'swarm_storage' # enrich extractors cla...
Ruby
require 'extractor' require 'html_tidy' require 'stemmer' class Stem attr_accessor :stem , :count, :id def initialize(stem, count, id) @id = id @stem = stem @count = count end end def swarm_extract(page, notidy=true, interesting_stems=nil, pop_stems_threshold=5) # Components setup if (page....
Ruby
require 'active_record' require 'swarm_init.rb' db_opts = $opts['database'] @db_host = db_opts[:host] @db_user = db_opts[:user] @db_pass = db_opts[:pass] @db_name = db_opts[:db] ActiveRecord::Base.establish_connection( :adapter => "mysql", :host => @db_host, :username => @db_user, :password => @db_pass, ...
Ruby
# Copyright 2007 Associazione Bayesfor. # Created by Matteo Zandi (matteo.zandi@bayesfor.eu) require 'rubygems' require 'ferret' require 'yaml' # A module which removes stopwords from ferret lists for the purpose # of normalization module Customlists @langs = [:it, :en] # ferret standard stopwords lists for ita...
Ruby
require 'rss/1.0' require 'rss/2.0' require 'open-uri' require 'mysql' dbh = Mysql.real_connect("localhost", "testuser", "test", "bayesfortest") sou = dbh.prepare "INSERT INTO sources ( name, language ) values ( ? , ?)" get = dbh.prepare "SELECT id FROM sources WHERE name = ? " pag = dbh.prepare "INSERT INTO pages ( s...
Ruby
#!/usr/bin/env ruby require 'time' # Option parsing require 'optparse' require 'ostruct' # bayes-swarm specific require 'swarm_support' class Page attr_accessor :id, :url, :language_name, :kind_name, :last_scantime def initialize(id, url, language_name, kind_name, last_scantime) @id = id @url = url ...
Ruby
require 'rsruby' require 'rsruby/dataframe' module R_Config R = RSRuby.instance end
Ruby
class Array def sum inject( nil ) { |sum,x| sum ? sum+x : x } end def mean sum=0 self.each {|v| sum += v} sum/self.size.to_f end def variance m = self.mean sum = 0.0 self.each {|v| sum += (v-m)**2 } sum/self.size end def stdev Math.sqrt(self.variance) end def c...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # The production environment is meant for finished, "live" apps. # Code is not reloaded between requests config.cache_classes = true # Use a different logger for distributed setups # config.logger = SyslogLogger.new # Full error repor...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the webserver when you make code changes. config.ca...
Ruby
# Add date string parser class method to Date class. # class Date # Parse date string with one of the following formats: # # * -n[units]: Date from self: examples: '1d', '2d', '1m', '2y' # # The string argument is first converted to a string with #to_s. # Returns nil if passed nil or an empty string. # Ra...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between...
Ruby
# Be sure to restart your web server when you modify this file. # Uncomment below to force Rails into production mode when # you don't control web/app server and can't set it the proper way # ENV['RAILS_ENV'] ||= 'production' # Specifies gem version of Rails to use when vendor/rails is not present RAILS_GEM_VERSION =...
Ruby
# Don't change this file. Configuration is done in config/environment.rb and config/environments/*.rb RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT) unless defined?(Rails::Initializer) if File.directory?("#{RAILS_ROOT}/vendor/rails") require "#{RAILS_ROOT}/vendor/rails/railties/lib/init...
Ruby
ActionController::Routing::Routes.draw do |map| # The priority is based upon order of creation: first created -> highest priority. # Sample of regular route: # map.connect 'products/:id', :controller => 'catalog', :action => 'view' # Keep in mind you can assign values other than :controller and :action # ...
Ruby
module Admin::HomeHelper end
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper def font_size_for_tag_cloud_new( weight, lowest_w, highest_w, steps=5, size_max=26) return nil if weight.nil? or lowest_w.nil? or highest_w.nil? # work out the font size size_min =...
Ruby
module WikiHelper end
Ruby
module SourceHelper end
Ruby
module IgHelper end
Ruby
module OfcHelper end
Ruby
module IntwordHelper end
Ruby
module HomeHelper end
Ruby
module FeaturedHelper end
Ruby
module PageHelper end
Ruby
module PagestoreHelper end
Ruby
module LoginHelper end
Ruby
class Page < ActiveRecord::Base belongs_to :source belongs_to :kind belongs_to :language has_many :word, :dependent => :destroy validates_presence_of :url def before_create self.created_at = Time.now() end end
Ruby
class Intword < ActiveRecord::Base belongs_to :language has_many :words attr_accessor :corr validates_presence_of :name, :language_id validates_uniqueness_of :name, :scope => :language_id def self.find_popular(l_id, interval='1m', n=999999, order_column="imp", visible=1, like=nil) first_date = Date.to...
Ruby
class PageStore attr_reader :counts, :words, :pages, :total def initialize @counts = {} @words = {} @total = 0 end def add(intword,page_id,count) @words[intword] ||= intword.id page ||= Page.find(page_id) @counts[page] ||= {} @counts[page][intword.name] ||= 0 @count...
Ruby
require "digest/sha1" class User < ActiveRecord::Base attr_accessor :password attr_accessible :name, :password, :fullname, :email def before_create self.hashed_password = User.hash_password(self.password) end def after_create @password = nil end def self.hash_password(password) Diges...
Ruby
class Kind < ActiveRecord::Base end
Ruby
class Word < ActiveRecord::Base belongs_to :intword belongs_to :page end
Ruby
class Source < ActiveRecord::Base has_many :pages, :dependent => :destroy has_many :words, :through => :pages validates_presence_of :name def before_create self.created_at = Time.now() end end
Ruby
class HomeController < ApplicationController layout "standard" def index @n_intwords = Intword.count(:conditions => "visible=1") @n_languages = LOCALES.length @n_sources = Source.count() @attr = 'imp' @action = 'show' @intwords = Intword.find_popular(Locale.language.id, '7d', 50, @attr, 1)...
Ruby
class IntwordController < ApplicationController layout "standard" # FIXME: add delete before_filter :authorize, :only => [:edit, :notvisible_cloud, :csv] def index # cloud @attr = 'imp' @action = 'show' @intwords = Intword.find_popular(Locale.language.id, '1m', 999999, @attr, 1) end ...
Ruby
class SourceController < ApplicationController layout "standard" before_filter :authorize, :only => [:edit, :new, :destroy, :csv] def index list render :action => 'list' end def list sources_with_pages_in_cur_locale = Page.find(:all, :conditions...
Ruby
class AdminController < ApplicationController #layout "admin" layout "standard" before_filter :authorize def index end def translate_new #@view_translations = ViewTranslation.find(:all, :conditions => [ 'built_in = 1 AND language_id = ?', Locale.language.id ], :order => 'text') # untranslated ...
Ruby
class OfcController < ApplicationController DEFAULT_OPTIONS = { :kind => :default, :graph_colors => [ '#fffc23' , '#616BDB' , '#65AB45' , '#BE4F3C' , '#824D7D' ], :bg_color => '#000000', :pie_bg_color => '#222222', :inner_background => ["#000000", "#444444"], :x_axis => '#ffffff', :x_axis...
Ruby
require 'hpricot' require 'open-uri' class WikiController < ApplicationController layout "standard" BASE_URL = "http://www.bayesfor.eu" def view url = ([] << params[:path]).flatten.join("/") doc = Hpricot(open(BASE_URL + "/wiki/" + url)) # Some smart image resizing to comply with the limi...
Ruby
class PageController < ApplicationController layout "standard" before_filter :authorize, :only => [:edit, :new, :destroy, :csv] def index list render :action => 'list' end def list @page_pages, @pages = paginate(:page, :per_page => 20, ...
Ruby
class LoginController < ApplicationController #layout "admin" layout "standard" before_filter :authorize, :except => :login def login if request.get? session[:user_id] = nil @user = User.new else @user = User.new(params[:user]) logged_in_user = @user.try_to_login if logg...
Ruby
require 'pagestore' class PagestoreController < ApplicationController layout "standard" , :only => "disclaimer" def show intword_ids = params[:id].split("-") @date = Date.strptime(params[:date]) @store = PageStore.new #FIXME(battlehorse): warning! this performs N+1 queries intword_...
Ruby
# Filters added to this controller apply to all controllers in the application. # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base # Pick a unique cookie name to distinguish our session data from others' session :session_key => '_website_se...
Ruby
class IgController < ApplicationController def elections # def interesting words for usprimary2008 @candidate={"all" => "330-331-333-321-332", "rep" => "333-335-340-341-331", "dem" => "321-330-332-348-338", "ita" => "98-115-118-3370" } if ( params[:id] == nil ) ...
Ruby
class FeaturedController < ApplicationController layout "standard" def index end def usprimary2008 # def interesting words for usprimary2008 @candidate={"all" => "330-331-333-321-332", "rep" => "333-335-340-341-331", "dem" => "321-330-332-348-338" } if ( params[:id] ==...
Ruby
# Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require(File.join(File.dirname(__FILE__), 'config', 'boot')) require 'rake' require 'rake/testtask' require 'rake/rdoctask' require 'tasks/rails'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/breakpointer'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/console'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/runner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/benchmarker'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/benchmarker'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/profiler'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/profiler'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/plugin'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/destroy'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/about'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/runner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/breakpointer'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/server'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/generate'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/console'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/reaper'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/inspector'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/inspector'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/spawner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/reaper'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/spawner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/destroy'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/generate'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/server'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/about'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/plugin'
Ruby
class CreatePages < ActiveRecord::Migration def self.up create_table :pages do |t| end end def self.down drop_table :pages end end
Ruby
class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| end end def self.down drop_table :users end end
Ruby
class CreateIntwords < ActiveRecord::Migration def self.up create_table :intwords do |t| end end def self.down drop_table :intwords end end
Ruby
class CreateWords < ActiveRecord::Migration def self.up create_table :words do |t| end end def self.down drop_table :words end end
Ruby
class CreateKinds < ActiveRecord::Migration def self.up create_table :kinds do |t| end end def self.down drop_table :kinds end end
Ruby
class CreateSources < ActiveRecord::Migration def self.up create_table :sources do |t| end end def self.down drop_table :sources end end
Ruby
#!/usr/bin/ruby1.8 require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired...
Ruby
#!/usr/bin/ruby1.8 # # You may specify the path to the FastCGI crash log (a log of unhandled # exceptions which forced the FastCGI instance to exit, great for debugging) # and the number of requests to process before running garbage collection. # # By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.log #...
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'test_help' class Test::Unit::TestCase # Transactional fixtures accelerate your tests by wrapping each test method # in a transaction that's rolled back on completion. This ensures that the # test datab...
Ruby
#!/usr/bin/env ruby # == Synopsis # Generates records for the bayes-swarm database containing statistics about words according to the bayes-swarm definition. # This tool can be used for testing purposes to load the bayes-swarm database with fictional data # which can be statistically analyzed and tested. # # For examp...
Ruby
# Provides common functionalities reused across scripts module Common # Given an array of command-line parameters returns the part of them # which is before or after the +opt+ parameter, which acts as separator def split_params(params,opt, after) reject = after res = params.collect do |p| reject ...
Ruby
class Functions def linear const_val = 3 return function { |x| const_val } end def smooth_sin damping = 0.1 cycle = Math::PI / 10 return function { |x| Math.sin( cycle * x) / ( damping * x ) } end ## DO NOT MODIFY BELOW THIS LINE def method_missing(methId, *args) puts "...
Ruby
# statistics2.rb # # distributions of statistics # by Shin-ichiro HARA # # 2003.09.25 # # Ref: # [1] http://www.matsusaka-u.ac.jp/~okumura/algo/ # [2] http://www5.airnet.ne.jp/tomy/cpro/sslib11.htm module Statistics2 SQ2PI = Math.sqrt(2 * Math::PI) # Newton approxima...
Ruby
#!/usr/bin/env ruby # == Synopsis # Generates records for the bayes-swarm database containing statistics about words according to the bayes-swarm definition. # This tool can be used for testing purposes to load the bayes-swarm database with fictional data # which can be statistically analyzed and tested. # # For examp...
Ruby
# = ETL Runner # This file is part of the ETL package. # See the documentation for ETLRunner as a starting point. # # == Author # Riccardo Govoni [battlehorse@gmail.com] # # == Copyright # Copyright(c) 2007 - bayes-swarm project. # Licensed under the Apache2 License. # require 'json' require 'yaml' require 'etl/util/lo...
Ruby
# = Standard ETL blocks # This file is part of the ETL package. # This file contains the standard ETL blocks part of the bayes-swarm ETL package. Such blocks # are general purpose ones, which may be usually reused in any chain, independently of its type. # # == Author # Riccardo Govoni [battlehorse@gmail.com] # # == Co...
Ruby
# = Conditional ETL blocks # This file is part of the ETL package. # This file contains ETL blocks that apply conditional rules on the ETL processing sequence. # # == Author # Riccardo Govoni [battlehorse@gmail.com] # # == Copyright # Copyright(c) 2007 - bayes-swarm project. # Licensed under the Apache2 License. requi...
Ruby