code
stringlengths
1
1.73M
language
stringclasses
1 value
class WordController < ApplicationController end
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 scaffold :intword helper :plot layout "standard" def show @intword = Intword.find(@params["id"], :include => [:language]) end def edit @intword = Intword.find(@params["id"]) @languages = Language.find(:all) end def new @intword...
Ruby
class SourceController < ApplicationController scaffold :source end
Ruby
class LanguageController < ApplicationController end
Ruby
class KindController < ApplicationController end
Ruby
class PageController < ApplicationController scaffold :page def edit @page = Page.find(@params["id"]) @sources = Source.find_all @languages = Language.find_all end def show @page = Page.find(@params["id"], :include => [:source, :language]) end end
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
class CreateLanguages < ActiveRecord::Migration def self.up create_table :languages do |t| end end def self.down drop_table :languages 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
require "net/http" class HttpExtractor def extract(url) response = extract_with_redirect(url) response.body end def extract_with_redirect(url, limit=10) fail "#{self.class.name}: http redirect too deep" if limit.zero? puts "#{self.class.name}: Trying: #{url}" response = Net::HTTP.get_resp...
Ruby
require 'rubygems' gem 'ferret' require 'ferret' class FerretStemmer def stem(content) analyzer = StopAndStemAnalyzer.new stream = analyzer.token_stream(nil,content) token = stream.next res = [] until token.nil? res << token.text token = stream.next end return res en...
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 # Requires require 'swarm' require 'swarm_support' notidy = true sourcetype = :url pages = get_pages() interesting_stems = get_interesting_stems() for page in pages counted_stems = swarm_extract(page.url, sourcetype, notidy, interesting_stems) if ( counted_stems != nil ) insert_ste...
Ruby
#!/usr/bin/env ruby # Requires require 'swarm' require 'swarm_support' notidy = true sourcetype = :url pages = get_pages() interesting_stems = get_interesting_stems() for page in pages counted_stems = swarm_extract(page.url, sourcetype, notidy, interesting_stems) if ( counted_stems != nil ) insert_ste...
Ruby
#!/usr/bin/env ruby # Option parsing require 'optparse' require 'ostruct' # Requires require 'extractor' require 'html_tidy' require 'stemmer' require 'swarm_support' def swarm_extract(source, sourcetype, notidy = true, interesting_stems = nil) # Components setup if (sourcetype == :url) extractor = Htt...
Ruby
require "mysql" class StemCount attr_accessor :stem , :count def initialize(stem, count) @stem = stem @count = count end end class StemCountId attr_accessor :stem , :count, :id def initialize(stem, count, id) @id = id @stem = stem @count = count end end class Page attr_accessor :i...
Ruby
### Update the db with all the news of the day require 'rss/1.0' require 'rss/2.0' require 'open-uri' require 'mysql' require 'update_support' sources = get_sources() i=0 sources.length.times do id = sources[i].id name = sources[i].name load_pages(id,name) i += 1 end
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 ) values ( ? )" sources = Array.new sources[0]="http://www.corriere.it/rss/homepage.xml" sources[1]="http://www.lastampa.it/red...
Ruby
#!/usr/bin/env ruby # Option parsing require 'optparse' require 'ostruct' # Requires require 'extractor' require 'html_tidy' require 'stemmer' require 'swarm_support' def swarm_extract(source, sourcetype, notidy = true, interesting_stems = nil) # Components setup if (sourcetype == :url) extractor = Htt...
Ruby
require 'rss/1.0' require 'rss/2.0' require 'open-uri' require 'mysql' def load_pages(s_id, source) dbh = Mysql.real_connect("localhost", "testuser", "test", "bayesfortest") content = "" # raw content of rss feed will be loaded here open(source) do |s| content = s.read end rss = RSS::Parser.parse(content...
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
# 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 GNU General Public License v2. require 'active_record' class Intword < ActiveReco...
Ruby
# = Bayes : Sdb Console # A simple tool to perform SELECT queries against Amazon SDB. # # Make sure swarm_shoal_options.yml contains the credentials to connect to # SDB and just lunch from the command line. You'll get a shell that you can # use to send queries to SDB, one per line. # # Results are formatted and color...
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 : SimpleDB Domain creator # A simple script to create an Amazon SDB Domain. # # Run with # # ruby runner.rb -c swarm_shoal_options.yml \ # -f component/swarm_create_sdb_domain -d <domain_name> # # See swarm_mysql_to_sdb.rb for more information about the way Bayes-Swarm # uses Amazon SDB. # # == Author...
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 : Amazon SimpleDB migrator # A script to migrate contents from Bayes MySQL structure into Amazon SimpleDB. # # Run with # # ruby runner.rb -c swarm_shoal_options.yml \ # -f component/swarm_mysql_to_sdb -d <scantime> [--delete_domain] # # The script reads all the words stored in a Swarm MySQL db for a ...
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 GNU General Public License v2. require 'util/log' module Pulsar # Recursively searches for matches within a d...
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 GNU General Public License v2. module Pulsar # A module that can be included in classes to enrich them wit...
Ruby
# = Utilities : Amazon SimpleDB BatchPutAttributes # Extends the right_aws gem providing support for # Amazon SimpleDB BatchPutAttributes operation. # # The right_aws gem provides basic functionality to interact with Amazon # SimpleDB, but it doesn't support BatchPutAttributes (as of version 1.10.0), # severely limiti...
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 GNU General Public License v2. requ...
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 GNU General Public License v2. module Pulsar # An utility class to wra...
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 GNU General Public License v2.
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 GNU General Public License v2. require 'active_record' require 'ut...
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 : Amazon SimpleDB Test # A simple component designed to verify that # the basic Sdb bindings are working properly and to do a littel benchmark # to transfer a 1000 items back and forward to Amazon SimpleDb. # # This test uses SdbInterface directly, without using an ActiveSdb facade. # Run with # # ruby runne...
Ruby