Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 0f45db4e77164dce2ad1c1b29ad3919fafadd5e7 Matt Smith committed May 18, 2008
Oops, something went wrong.
@@ -0,0 +1,52 @@
+Ruleby is copyrighted free software by Joe Kutner and Matt Smith. You can
+redistribute it and/or modify it under either the terms of the GPL (see the
+GPL.txt file), or the conditions below:
+
+ 1. You may make and give away verbatim copies of the source form of the
+ software without restriction, provided that you duplicate all of the
+ original copyright notices and associated disclaimers.
+
+ 2. You may modify your copy of the software in any way, provided that
+ you do at least ONE of the following:
+
+ a) place your modifications in the Public Domain or otherwise
+ make them Freely Available, such as by posting said
+ modifications to Usenet or an equivalent medium, or by allowing
+ the author to include your modifications in the software.
+
+ b) use the modified software only within your corporation or
+ organization.
+
+ c) rename any non-standard executables so the names do not conflict
+ with standard executables, which must also be provided.
+
+ d) make other distribution arrangements with the author.
+
+ 3. You may distribute the software in object code or executable
+ form, provided that you do at least ONE of the following:
+
+ a) distribute the executables and library files of the software,
+ together with instructions (in the manual page or equivalent)
+ on where to get the original distribution.
+
+ b) accompany the distribution with the machine-readable source of
+ the software.
+
+ c) give non-standard executables non-standard names, with
+ instructions on where to get the original software distribution.
+
+ d) make other distribution arrangements with the author.
+
+ 4. You may modify and include the part of the software into any other
+ software (possibly commercial).
+
+ 5. The scripts and library files supplied as input to or produced as
+ output from the software do not automatically fall under the
+ copyright of the software, but belong to whomever generated them,
+ and may be sold commercially, and may be aggregated with this
+ software.
+
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE.
@@ -0,0 +1,115 @@
+
+require 'rubygems'
+
+require 'rake'
+require 'rake/clean'
+require 'rake/packagetask'
+require 'rake/gempackagetask'
+require 'rake/rdoctask'
+require 'rake/testtask'
+
+#
+# GEM SPEC
+
+spec = Gem::Specification.new do |s|
+
+ s.name = "ruleby"
+ s.version = "0.4"
+ s.authors = [ "Joe Kutner", "Matt Smith" ]
+ s.email = 'matt@ruleby.org'
+ s.homepage = "http://ruleby.org"
+ s.platform = Gem::Platform::RUBY
+ s.summary = "Rete based Ruby Rule Engine"
+ s.required_ruby_version = '>= 1.8.2'
+ #s.license = "GPL3"
+
+ s.require_paths = [ "lib" ]
+ s.autorequire = "ruleby"
+ s.test_file = "tests/test.rb"
+ s.has_rdoc = true
+ #s.extra_rdoc_files = [ 'README.txt' ]
+
+ #[ 'other-gem', 'yet-another-gem' ].each do |d|
+ # s.requirements << d
+ # s.add_dependency d
+ #end
+
+ files = FileList[ "{lib}/**/*" ]
+ #files.exclude "rdoc"
+ s.files = files.to_a
+end
+
+#
+# tasks
+
+CLEAN.include("pkg", "rdoc")
+
+task :default => [ :clean, :repackage ]
+
+
+#
+# TESTING
+
+Rake::TestTask.new(:test) do |t|
+ t.libs << "tests"
+ t.test_files = FileList['tests/test.rb']
+ t.verbose = true
+end
+
+#
+# PACKAGING
+
+Rake::GemPackageTask.new(spec) do |pkg|
+ #pkg.need_tar = true
+end
+
+Rake::PackageTask.new(spec.name, spec.version) do |pkg|
+
+ pkg.need_zip = true
+ pkg.package_files = FileList[
+ "Rakefile",
+ "*.txt",
+ "lib/**/*",
+ "tests/**/*"
+ ].to_a
+ #pkg.package_files.delete("MISC.txt")
+ class << pkg
+ def package_name
+ "#{@name}-#{@version}-src"
+ end
+ end
+end
+
+#
+# DOCUMENTATION
+
+#ALLISON=`allison --path`
+#ALLISON="/Library/Ruby/Gems/1.8/gems/allison-2.0.3/lib/allison.rb"
+
+Rake::RDocTask.new do |rd|
+
+ #rd.main = "README.txt"
+ #rd.rdoc_dir = "html/rufus-verbs"
+
+ rd.rdoc_files.include(
+ "LICENSE.txt",
+ "lib/**/*.rb")
+
+ rd.title = "ruleby rdoc"
+
+ rd.options << '-N' # line numbers
+ rd.options << '-S' # inline source
+
+ #rd.template = ALLISON if File.exist?(ALLISON)
+end
+
+
+#
+# WEBSITE
+
+#task :upload_website => [ :clean, :rdoc ] do
+# account = "whoever@rubyforge.org"
+# webdir = "/var/www/gforge-projects/ruleby"
+# sh "rsync -azv -e ssh html/source #{account}:#{webdir}/"
+#end
+
@@ -0,0 +1,61 @@
+# This file is part of the Ruleby project (http://ruleby.org)
+#
+# This application is free software; you can redistribute it and/or
+# modify it under the terms of the Ruby license defined in the
+# LICENSE.txt file.
+#
+# Copyright (c) 2007 Joe Kutner and Matt Smith. All rights reserved.
+#
+# * Authors: Joe Kutner, Matt Smith
+#
+
+$LOAD_PATH << File.join(File.dirname(__FILE__), '../lib/')
+require 'ruleby'
+require 'model'
+
+include Ruleby
+
+class TestRulebook < Rulebook
+ def rules(n)
+ (0..n).each do |index|
+ rule "Rule-#{index}".to_sym,
+ [Account,
+ method.status == 'standard',
+ method.title == 'mr',
+ method.account_id == "acc#{index}"] do |vars|
+# puts "rule #{index} fired"
+ end
+ end
+ end
+end
+
+def run_benchmark(rules, facts)
+ puts "running benchmark for: #{rules} rules and #{facts} facts"
+
+ t1 = Time.new
+ engine :engine do |e|
+ TestRulebook.new(e).rules(rules)
+
+ t2 = Time.new
+ diff = t2.to_f - t1.to_f
+ puts 'time to create rule set: ' + diff.to_s
+ for k in (0..facts)
+ e.assert Account.new('standard', 'mr', ('acc'+k.to_s))
+ end
+
+ t3 = Time.new
+ diff = t3.to_f - t2.to_f
+ puts 'time to assert facts: ' + diff.to_s
+ e.match
+
+ t4 = Time.new
+ diff = t4.to_f - t3.to_f
+ puts 'time to run agenda: ' + diff.to_s
+ end
+end
+
+run_benchmark(5, 500)
+puts '-------'
+run_benchmark(50, 500)
+puts '-------'
+run_benchmark(500, 500)
@@ -0,0 +1,66 @@
+# This file is part of the Ruleby project (http://ruleby.org)
+#
+# This application is free software; you can redistribute it and/or
+# modify it under the terms of the Ruby license defined in the
+# LICENSE.txt file.
+#
+# Copyright (c) 2007 Joe Kutner and Matt Smith. All rights reserved.
+#
+# * Authors: Joe Kutner, Matt Smith
+#
+
+$LOAD_PATH << File.join(File.dirname(__FILE__), '../lib/')
+require 'ruleby'
+require 'model'
+
+include Ruleby
+
+class TestRulebook < Rulebook
+ def rules(n)
+ (1..n).each do |index|
+ rule "Rule-#{index}".to_sym,
+ [Account, :acc,
+ method.status == 'standard',
+ {method.account_id => :id}
+ ],
+ [Address, :addr,
+ method.addr_id == b(:id),
+ method.city == 'Foobar',
+ method.state == 'FB',
+ method.zip == '12345'],
+ &lambda {|vars| }
+ end
+ end
+end
+
+def run_benchmark(rules,facts)
+ puts "running benchmark for: #{rules} rules and #{facts} facts"
+
+ t1 = Time.new
+ engine :engine do |e|
+ TestRulebook.new(e).rules(rules)
+
+ t2 = Time.new
+ diff = t2.to_f - t1.to_f
+ puts 'time to create rule set: ' + diff.to_s
+#e.print
+ for k in (1..facts)
+ e.assert Account.new('standard', nil, "acc#{k}")
+ e.assert Address.new("acc#{k}",'Foobar', 'FB', '12345')
+ end
+#exit(0)
+ t3 = Time.new
+ diff = t3.to_f - t2.to_f
+ puts 'time to assert facts: ' + diff.to_s
+
+ e.match
+
+ t4 = Time.new
+ diff = t4.to_f - t3.to_f
+ puts 'time to run agenda: ' + diff.to_s
+ end
+end
+
+run_benchmark(5, 50)
+puts '-------'
+run_benchmark(50, 50)
Oops, something went wrong.

0 comments on commit 0f45db4

Please sign in to comment.