code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
# 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 |
#!/usr/bin/ruby
require 'stopstem_helpers'
iws = Intword.find(:all, :conditions => {:language_id => 2600})
puts "id, name, word count"
iws.each do |iw|
if (is_stop_word?(iw.name))
puts "#{iw.id}, #{iw.name}, #{Word.count(:all, :conditions=>{:intword_id=>iw.id})}"
end
end
| Ruby |
#!/usr/bin/ruby
require 'stopstem_helpers'
iws = Intword.find(:all, :conditions => {:language_id => 2600})
#roots = {}
puts "id, name, is_stop, is_root, root, word count"
iws.each do |iw|
iwroot = root(iw.name)
iwcount = Word.count(:all, :conditions=>{:intword_id=>iw.id})
puts "#{iw.id}, #{iw.name}, #{is_s... | Ruby |
#!/usr/bin/ruby
require 'stopstem_helpers'
iws = Intword.find(:all, :conditions => {:language_id => 2600})
#roots = {}
puts "id, name, is_stop, is_root, root, word count"
iws.each do |iw|
iwroot = root(iw.name)
iwcount = Word.count(:all, :conditions=>{:intword_id=>iw.id})
puts "#{iw.id}, #{iw.name}, #{is_s... | Ruby |
#!/usr/bin/ruby
require 'stopstem_helpers'
iws = Intword.find(:all, :conditions => {:language_id => 2600})
puts "id, name, word count"
iws.each do |iw|
if (is_stop_word?(iw.name))
puts "#{iw.id}, #{iw.name}, #{Word.count(:all, :conditions=>{:intword_id=>iw.id})}"
end
end
| Ruby |
require 'rubygems'
Dir.chdir('../../prototype1/ruby/')
require 'swarm_ar_support.rb'
require 'ferret'
class StopAndStemAnalyzer < Ferret::Analysis::Analyzer
include Ferret::Analysis
def token_stream(field, str, lang)
stop_langs = {:it => Ferret::Analysis::FULL_ITALIAN_STOP_WORDS,
:en => Fe... | Ruby |
# = Bayes : StoreIterator
# Use a StoreIterator to navigate the contents of a Pagestore, or a portion
# of it. It takes care of all the boilerplate code involved, and handles
# the details of PageStore structure ( as described in
# http://code.google.com/p/bayes-swarm/wiki/FileStorage ), abstracting them to
# the call... | Ruby |
# = Bayes : Blender
# Contains the bulk logic that transforms a plain text content
# into a set of data-structures suitable for storage in the
# bayes database.
#
# Given a text content that belongs to a given portion of a page, it
# performs the following operations:
# * stopwords and other language artifacts are ... | Ruby |
# = Bayes
# The 'bayes' folder contains the specific bindings for the bayes-swarm
# entities, such as the active-record model. It is separated from the 'util'
# folder to preserve separation between generic code and code specialized for
# the current setup of the bayes-swarm model.
#
# == Copyright
# Copyright(c) 2008... | Ruby |
# = Bayes : PageStore extension
# Extends the default PageStore to provide additional information in the +META+
# file pertaining to the +Page+ the stored entry belongs to (such as id, kind
# and language code).
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# == Copyright
# Copyright(c) 2008 - bayes-swarm... | Ruby |
# = Bayes : ActiveRecord bindings
# Contains the ActiveRecord declaration of the bayes-swarm model.
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# == Copyright
# Copyright(c) 2008 - bayes-swarm project.
# Licensed under the Apache2 License.
require 'active_record'
class Intword < ActiveRecord::Base
bel... | Ruby |
# = Pulsar Runner
# This is responsible for kickstarting all the
# scripts and execution steps. It is invoked from the command line
# with this syntax :
#
# ruby runner.rb -c configuration_file.yml -f component
#
# such as:
#
# ruby runner.rb -c swarm_shoal_options.yml -f test/noop
#
# == Author
# Riccardo Govoni [... | Ruby |
# = Bayes : Group-Intwords
# Group-Intwords is a simple tool whose purpose is to consolidate and
# clean up the Intwords table in the database.
#
# It scans the Intwords table and looks for duplicates and words to are
# recorded in both the stemmed and not-stemmed form ( bugs in the past have
# resulted in non-stemme... | Ruby |
# = Bayes : Swarm-Shoal
# Shoal is the second component in the bayes-swarm execution chain.
# It is responsible for loading the web pages and feeds as saved by
# Swarm-Wave, analyzing their contents, normalizing them and saving
# the parsed data in a relational database, suitable for access by
# the web application... | Ruby |
# = Bayes : Swarm-Cube
# Cube is the third component in the bayes-swarm execution chain.
# It creates denormalized aggregations on the MySql database, in order to speed
# up data access for given queries, such as word aggregations on the entire
# time scale stored in the database.
#
# To be executed it requires access... | Ruby |
# = Bayes : Mean-Machine : Xapian Indexer
# The Indexer populates a Xapian instance with the informations extracted
# from a page store. Its purpose is equivalent to swarm_shoal, the
# difference being the type of backend filled with the extracted
# informations.
#
# This indexer is a ruby porting of mean-machine/bs-xa... | Ruby |
# = Bayes : Swarm-Wave
# Wave is the first component in the bayes-swarm execution chain. It is
# responsible for downloading and saving to the local filesystem all the
# web pages and rss feeds declared in the database.
#
# It is also responsible for updating the +last_scantime+ information
# on the database.
#
# == Au... | Ruby |
# = Component
# The 'component' folder contains all the components for the bayes-swarm
# execution chain. New components for such chain should be added here. This includes,
# for example, web scrapers, script to consolidate data into databases, indexing
# algorithms and so forth.
#
# == Copyright
# Copyright(c) 2008 ... | Ruby |
# = Bayes : Swarm-MoreMeta
# MoreMeta is just a quick utility script that updates the META
# informations stored in the pagestore, to enrich them with additional
# info (as the page_id, kind, language and other infos).
#
# It also fixes a bug in some META files that contain spurious newlines
# for some URL entries.
#... | Ruby |
# = Pulsar
# This is the base folder for the Pulsar prototype.
# "Pulsar" is the codename for prototype3, the third iteration
# of the bayes-swarm extraction engine.
#
# The concept behind the Pulsar prototype is to divide the execution
# chain into 'components'. Each component is responsible to handle
# a particula... | Ruby |
# = Utilities : Extractors
# Contains the available web extractors.
#
# All the extractors should conform to the following interface: they should
# provide an +extract()+ method, which takes a +page+ and returns
# an +ExtractedPage+, a wrapper that binds together a page and its content,
# or +nil+ in case of error.
#
... | Ruby |
# = Utilities : File lister
# Contains filesystem search utilities
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# == Copyright
# Copyright(c) 2008 - bayes-swarm project.
# Licensed under the Apache2 License.
require 'util/log'
module Pulsar
# Recursively searches for matches within a directory.
cl... | Ruby |
# = Utilities : Stemmer
# The Stemmer is responsible for cleaning up textual data. It performs three
# basic operations:
# * stemming the words found within a block of text.
# * removing stopwords ( very popular words such as conjunctions) from the sample
# * removing special characters such as quotation marks, questio... | Ruby |
# = Utilities : Logging
# General purpose utilities related to logging
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# == Copyright
# Copyright(c) 2008 - bayes-swarm project.
# Licensed under the Apache2 License.
module Pulsar
# A module that can be included in classes to enrich them with logging meth... | Ruby |
# = Utilities : Html
# Contains utilities to parse and analyze html contents.
# It uses Hpricot as the backend library to perform the heavy work.
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# == Copyright
# Copyright(c) 2008 - bayes-swarm project.
# Licensed under the Apache2 License.
require 'hpricot'
... | Ruby |
# = Utilities : RssPage
# Contains the definition of a simple wrapper class that represents
# an RSS item.
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# == Copyright
# Copyright(c) 2008 - bayes-swarm project.
# Licensed under the Apache2 License.
module Pulsar
# An utility class to wrap a +url+, +ki... | Ruby |
# = Util
# The 'util' folder contains general purpose utilities and code
# supposed to be reused across different components, such as logging
# facilities, active_record binding code and web extractors.
#
# == Copyright
# Copyright(c) 2008 - bayes-swarm project.
# Licensed under the Apache2 License. | Ruby |
# = Utilities : File storage
# Contains code to handle saving web contents to the filesystem in
# an indexed manner, the so-called PageStore.
#
# See http://code.google.com/p/bayes-swarm/wiki/FileStorage for more info.
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# == Copyright
# Copyright(c) 2008 - bayes-... | Ruby |
# = Utilities : ActiveRecord management
# Contains general purpose utilities related to the ActiveRecord framework.
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# == Copyright
# Copyright(c) 2008 - bayes-swarm project.
# Licensed under the Apache2 License.
require 'active_record'
require 'util/log'
modul... | Ruby |
# = Test : UnitTests runner
# Executes the suite of available unit tests.
#
# To run the tests, use the +Runner+ as usual, but remember to add a +runner+
# option to tell Test::Unit which suite runner to use.
#
# ruby runner.rb -c test_shoal_options.yml \
# -f test/unittests \
# --ru... | Ruby |
# = Test : Blender
# A unit test for the BayesBlender, which is complex enough to
# require a dedicated effort to get it right.
#
# Refer to test/unittests.rb on how to run unit tests.
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# == Copyright
# Copyright(c) 2008 - bayes-swarm project.
# Licensed under th... | Ruby |
# = Unit
# The 'unit' folder contains unit tests.
#
# == Copyright
# Copyright(c) 2008 - bayes-swarm project.
# Licensed under the Apache2 License. | Ruby |
# = Test : ActiveRecord No-Op
# A simple component designed to verify that
# the ActiveReport bindings are working properly. Run with
#
# ruby runner.rb -c swarm_shoal_options.yml -f test/arnoop
#
# If everything is fine, it should print the list of pages stored in
# the database
#
# == Author
# Riccardo Govoni [batt... | Ruby |
# = Test : No-Op
# A simple component designed to verify that
# the Runner and component system are setup properly. Run with
#
# ruby runner.rb -c swarm_shoal_options.yml -f test/noop
#
# If everything is fine, it should just print a log line saying +NoOp.+
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# ... | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.