code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
# = ETL Utilities : Logging
# This file is part of the ETL package. It contains general purpose utilities related
# to logging
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# == Copyright
# Copyright(c) 2007 - bayes-swarm project.
# Licensed under the Apache2 License.
# A module that can be included in cla... | Ruby |
# = ETL Utilities : Database management
# This file is part of the ETL package. It contains general purpose utilities related
# to database management, Data Access Objects (DAO) and database interfacing in general
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# == Copyright
# Copyright(c) 2007 - bayes-swarm... | Ruby |
# = ETL Utilities : ActiveRecord management
# This file is part of the ETL package. It contains general purpose utilities related
# to the ActiveRecord framework.
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# == Copyright
# Copyright(c) 2007 - bayes-swarm project.
# Licensed under the Apache2 License.
re... | Ruby |
# = Database Load ETL blocks
# This file is part of the ETL package.
# This file contains ETL blocks that can be used to interoperate with a relational database,
# during the *load* phase of ETL processes.
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# == Copyright
# Copyright(c) 2007 - bayes-swarm project... | Ruby |
# = Multiplexer ETL blocks
# This file is part of the ETL package.
# This file contains the support structures to work with *multiplexed* etl blocks. A
# Multiplexer has the ability to perform its subsequent tasks a number of times,
# varying the DTO in use from time to time, depending on a given condition.
#
# == Aut... | Ruby |
# = Data Transfer Objects for bayes-swarm
# This file contains DTOs specific to the bayes-swarm project.
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# == Copyright
# Copyright(c) 2007 - bayes-swarm project.
# Licensed under the Apache2 License.
require 'dto/dto'
#
# An ETL DTO is the main object which i... | Ruby |
# = Multiplex ETL blocks for bayes-swarm
# This file contains ETL blocks specific to the bayes-swarm project.
# It contains multiplexers which scan through pages and sources.
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# == Copyright
# Copyright(c) 2007 - bayes-swarm project.
# Licensed under the Apache2 ... | Ruby |
# = Data Transfer Objects for bayes-swarm with ActiveRecord support
# This file contains DTOs specific to the bayes-swarm project, which are bound
# to ActiveRecord entities
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# == Copyright
# Copyright(c) 2007 - bayes-swarm project.
# Licensed under the Apache2 L... | Ruby |
# = Filtering ETL blocks for bayes-swarm
# This file contains ETL blocks specific to the bayes-swarm project.
# It contains filters that reduce the word list according to various algorithms
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# == Copyright
# Copyright(c) 2007 - bayes-swarm project.
# Licensed und... | Ruby |
# = Filtering ETL blocks for bayes-swarm
# This file contains ETL blocks specific to the bayes-swarm project.
# It contains grouping functions that compact the word list according to various algorithms
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# == Copyright
# Copyright(c) 2007 - bayes-swarm project.
# ... | Ruby |
# = Extractor ETL blocks for bayes-swarm
# This file contains ETL blocks specific to the bayes-swarm project.
# It contains extractors that can download pages from the file or load them from filesystem
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# == Copyright
# Copyright(c) 2007 - bayes-swarm project.
# ... | Ruby |
# = Cleaning ETL blocks for bayes-swarm
# This file contains ETL blocks specific to the bayes-swarm project.
# It contains extractors that clean raw contents from the previous steps.
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# == Copyright
# Copyright(c) 2007 - bayes-swarm project.
# Licensed under the ... | Ruby |
# = Extract ETL blocks
# This file contains ETL blocks used for testing purposes. Its content are
# subject to change without notice.
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# == Copyright
# Copyright(c) 2007 - bayes-swarm project.
# Licensed under the Apache2 License.
require 'etl/std'
require 'etl/m... | Ruby |
# = Storage and Load ETL blocks for bayes-swarm
# This file contains ETL blocks specific to the bayes-swarm project.
# It contains blocks that may be used to store DTOs into various output destinations
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# == Copyright
# Copyright(c) 2007 - bayes-swarm project.
# ... | Ruby |
# = Helper ETL blocks for bayes-swarm
# This file contains ETL blocks specific to the bayes-swarm project.
# It contains helper and utility blocks
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# == Copyright
# Copyright(c) 2007 - bayes-swarm project.
# Licensed under the Apache2 License.
require 'etl/std'
... | Ruby |
# = Data Transfer Objects
# This file is part of the ETL package
#
# == Description
# Data Transfer Objects (DTOs) are used to transfer values and application state
# between different ETL steps. They can be serialized and deserialized, to allow
# ETL partitioning and suspend/resume
#
# == Serialization
# The +json+ f... | Ruby |
# = Data Transfer Objects and Active Record
# This file is part of the ETL package and contains support structures to map between
# DTOs and ActiveRecord.
#
# == Object-Relational Mapping and JSON
# This file enriches ActiveRecord (by mixin some code into <tt>ActiveRecord::Base</tt> )
# to allow to-and-from conversion ... | Ruby |
# = Data Transfer Objects for Multiplexers
# This file is part of the ETL package
#
# == Description
# This file contains the definition of Data Transfer Objects suitable
# for multiplexed use.
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# == Copyright
# Copyright(c) 2007 - bayes-swarm project.
# Licensed... | Ruby |
require 'rubygems'
require 'etl/runner'
# $-v = true
e = ETLRunner.new("etl_sample.yml")
e.run | Ruby |
# = UnitTest : ActiveRecord - JSON interaction
# This file is part of the unit tests for the ETL package
#
# == Description
# The tests in this file verify interactions between ActiveRecord and JSON
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# == Copyright
# Copyright(c) 2007 - bayes-swarm project.
# Li... | Ruby |
# = 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'
gem 'ferret'
require 'ferret'
class FerretStemmer
def stem(content, lang)
langs = {:it => Ferret::Analysis::FULL_ITALIAN_STOP_WORDS,
:en => Ferret::Analysis::EXTENDED_ENGLISH_STOP_WORDS}
analyzer = StopAndStemAnalyzer.new
stream = analyzer.token_stream(nil, content, ... | 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'
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,
:database => @db_name
... | 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 |
# 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 SourceHelper
end
| Ruby |
# Provides a tag for embedding gruff graphs into your Rails app.
#
# To use, load it in your controller with
#
# helper :gruff
#
# AUTHOR
#
# Carlos Villela [mailto:cv@lixo.org]
# Geoffrey Grosenbach[mailto:boss@topfunky.com]
#
# http://lixo.org
# http://topfunky.com
#
# License
#
# This code is licensed under the ... | Ruby |
module IntwordHelper
end
| Ruby |
module HomeHelper
end
| Ruby |
module PageHelper
end
| Ruby |
class Page < ActiveRecord::Base
belongs_to :source
belongs_to :kind
belongs_to :language
end
| Ruby |
class Intword < ActiveRecord::Base
belongs_to :language
has_many :words
validates_presence_of :name, :language_id
validates_uniqueness_of :name, :scope => :language_id
def self.find_popular(l_id, n_months=1, n=999999, order_column="imp", visible=1, like=nil)
condi = "scantime>='#{Date.today()<<n_months}... | Ruby |
class Kind < ActiveRecord::Base
end
| Ruby |
class Word < ActiveRecord::Base
belongs_to :intword
end
| Ruby |
class Source < ActiveRecord::Base
has_many :pages
end
| Ruby |
class HomeController < ApplicationController
layout "standard"
def index
@n_intwords = Intword.count(:conditions => "visible=1")
@n_languages = LOCALES.length
@n_words = Word.count().localize
@attr = 'imp'
@action = 'show'
@intwords = Intword.find_popular(Locale.language.id, 1, 50, @attr, ... | Ruby |
# Handles requests for gruff graphs.
#
# You shouldn't need to edit or extend this, but you can read
# the documentation for GruffHelper to see how to call it from
# another view.
#
# AUTHOR
# Carlos Villela [mailto:cv@lixo.org]
# Geoffrey Grosenbach[mailto:boss@topfunky.com]
#
# http://lixo.org
# http://topfunky.com
#... | Ruby |
class IntwordController < ApplicationController
helper :plot
layout "standard"
def index
# cloud
@attr = 'imp'
@action = 'show'
@intwords = Intword.find_popular(Locale.language.id, 1, 999999, @attr, 1)
end
def show
@ids = params[:id]
intword_ids = @ids.split("-")
@... | Ruby |
class SourceController < ApplicationController
#scaffold :source
layout "standard"
def index
list
render :action => 'list'
end
def list
sources_with_pages_in_cur_locale = Page.find(:all,
:conditions=>"language_id = #{Locale.language.id}",
... | Ruby |
class PageController < ApplicationController
#scaffold :page
layout "standard"
def index
list
render :action => 'list'
end
def list
@page_pages, @pages = paginate(:page,
:per_page => 20,
:conditions => "language_id = #{Local... | 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 |
# 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 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 |
require 'date'
require 'erb'
output_file = "/home/battleho/swarm/sources/prototype1/ror/public/monitor.html"
storevalues = `find ~/swarm/pagestore/ -type d -maxdepth 3 | egrep '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}' | xargs du -s`
# Expected sample values
# storevalues = <<-EOF
# 47160 /home/battleho/swarm/pagestore/2008... | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.