ruleby 0.3 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/core/atoms.rb +76 -27
- data/lib/core/engine.rb +11 -5
- data/lib/core/nodes.rb +175 -71
- data/lib/core/patterns.rb +21 -18
- data/lib/dsl/ferrari.rb +50 -33
- data/lib/dsl/letigre.rb +43 -17
- data/lib/dsl/steel.rb +1 -0
- data/lib/dsl/yaml_dsl.rb +23 -0
- data/lib/rulebook.rb +18 -3
- data/lib/ruleby.rb +37 -0
- data/tests/test.rb +15 -0
- metadata +53 -57
- data/benchmarks/basic_rules.rb +0 -66
- data/benchmarks/joined_rules.rb +0 -73
- data/benchmarks/miss_manners/data.rb +0 -146
- data/benchmarks/miss_manners/miss_manners.rb +0 -33
- data/benchmarks/miss_manners/model.rb +0 -193
- data/benchmarks/miss_manners/rules.rb +0 -104
- data/benchmarks/model.rb +0 -36
- data/examples/example_diagnosis.rb +0 -117
- data/examples/example_hello.rb +0 -46
- data/examples/example_politician.rb +0 -97
- data/examples/example_ticket.rb +0 -113
- data/examples/fibonacci_example1.rb +0 -44
- data/examples/fibonacci_example2.rb +0 -40
- data/examples/fibonacci_rulebook.rb +0 -84
- data/examples/test_self_reference.rb +0 -77
data/tests/test.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# This file is part of the Ruleby project (http://ruleby.org)
|
2
|
+
#
|
3
|
+
# This application is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the Ruby license defined in the
|
5
|
+
# LICENSE.txt file.
|
6
|
+
#
|
7
|
+
# Copyright (c) 2008 Joe Kutner and Matt Smith. All rights reserved.
|
8
|
+
#
|
9
|
+
# * Authors: John Mettraux
|
10
|
+
#
|
11
|
+
require 'common'
|
12
|
+
require 'test_duck_type'
|
13
|
+
require 'test_self_reference'
|
14
|
+
require 'test_re'
|
15
|
+
|
metadata
CHANGED
@@ -1,70 +1,66 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.0
|
3
|
-
specification_version: 1
|
4
2
|
name: ruleby
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: "0.
|
7
|
-
date: 2007-09-03 00:00:00 -05:00
|
8
|
-
summary: the Rule Engine for Ruby
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: matt@ruleby.org
|
12
|
-
homepage: http://www.ruleby.org
|
13
|
-
rubyforge_project:
|
14
|
-
description: ruleby is the Rule Engine for Ruby
|
15
|
-
autorequire: ruleby
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: false
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 1.8.2
|
24
|
-
version:
|
4
|
+
version: "0.4"
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
|
-
- Joe Kutner
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
- ./lib/dsl/letigre.rb
|
36
|
-
- ./lib/dsl/steel.rb
|
37
|
-
- ./lib/core/patterns.rb
|
38
|
-
- ./lib/core/utils.rb
|
39
|
-
- ./lib/core/atoms.rb
|
40
|
-
- ./lib/core/engine.rb
|
41
|
-
- ./lib/core/nodes.rb
|
42
|
-
- ./benchmarks/model.rb
|
43
|
-
- ./benchmarks/joined_rules.rb
|
44
|
-
- ./benchmarks/basic_rules.rb
|
45
|
-
- ./benchmarks/miss_manners/miss_manners.rb
|
46
|
-
- ./benchmarks/miss_manners/model.rb
|
47
|
-
- ./benchmarks/miss_manners/data.rb
|
48
|
-
- ./benchmarks/miss_manners/rules.rb
|
49
|
-
- ./examples/fibonacci_example1.rb
|
50
|
-
- ./examples/fibonacci_example2.rb
|
51
|
-
- ./examples/example_hello.rb
|
52
|
-
- ./examples/example_ticket.rb
|
53
|
-
- ./examples/fibonacci_rulebook.rb
|
54
|
-
- ./examples/example_politician.rb
|
55
|
-
- ./examples/test_self_reference.rb
|
56
|
-
- ./examples/example_diagnosis.rb
|
57
|
-
test_files: []
|
58
|
-
|
59
|
-
rdoc_options: []
|
7
|
+
- Joe Kutner
|
8
|
+
- Matt Smith
|
9
|
+
autorequire: ruleby
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
60
12
|
|
61
|
-
|
13
|
+
date: 2008-05-18 00:00:00 -05:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
62
16
|
|
17
|
+
description:
|
18
|
+
email: matt@ruleby.org
|
63
19
|
executables: []
|
64
20
|
|
65
21
|
extensions: []
|
66
22
|
|
67
|
-
|
23
|
+
extra_rdoc_files: []
|
68
24
|
|
69
|
-
|
25
|
+
files:
|
26
|
+
- lib/core
|
27
|
+
- lib/core/atoms.rb
|
28
|
+
- lib/core/engine.rb
|
29
|
+
- lib/core/nodes.rb
|
30
|
+
- lib/core/patterns.rb
|
31
|
+
- lib/core/utils.rb
|
32
|
+
- lib/dsl
|
33
|
+
- lib/dsl/ferrari.rb
|
34
|
+
- lib/dsl/letigre.rb
|
35
|
+
- lib/dsl/steel.rb
|
36
|
+
- lib/dsl/yaml_dsl.rb
|
37
|
+
- lib/rulebook.rb
|
38
|
+
- lib/ruleby.rb
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://ruleby.org
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 1.8.2
|
51
|
+
version:
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
requirements: []
|
70
59
|
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.0.1
|
62
|
+
signing_key:
|
63
|
+
specification_version: 2
|
64
|
+
summary: Rete based Ruby Rule Engine
|
65
|
+
test_files:
|
66
|
+
- tests/test.rb
|
data/benchmarks/basic_rules.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
# This file is part of the Ruleby project (http://ruleby.org)
|
2
|
-
#
|
3
|
-
# This application is free software; you can redistribute it and/or
|
4
|
-
# modify it under the terms of the Ruby license defined in the
|
5
|
-
# LICENSE.txt file.
|
6
|
-
#
|
7
|
-
# Copyright (c) 2007 Joe Kutner and Matt Smith. All rights reserved.
|
8
|
-
#
|
9
|
-
# * Authors: Joe Kutner, Matt Smith
|
10
|
-
#
|
11
|
-
|
12
|
-
$LOAD_PATH << File.join(File.dirname(__FILE__), '../lib/')
|
13
|
-
require 'ruleby'
|
14
|
-
require 'model'
|
15
|
-
|
16
|
-
include Ruleby
|
17
|
-
|
18
|
-
class TestRulebook < Rulebook
|
19
|
-
def rules(n)
|
20
|
-
(0..n).each do |index|
|
21
|
-
rule "Rule-#{index}".to_sym do |r|
|
22
|
-
r.when do |has|
|
23
|
-
has.a Account
|
24
|
-
has.a.status = 'standard'
|
25
|
-
has.a.title = 'mr'
|
26
|
-
has.a.account_id = "acc#{index}"
|
27
|
-
end
|
28
|
-
|
29
|
-
r.then do |e,vars|
|
30
|
-
# puts "rule #{index} fired"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def run_benchmark(rules, facts)
|
38
|
-
puts "running benchmark for: #{rules} rules and #{facts} facts"
|
39
|
-
|
40
|
-
t1 = Time.new
|
41
|
-
engine :engine do |e|
|
42
|
-
TestRulebook.new(e).rules(rules)
|
43
|
-
|
44
|
-
t2 = Time.new
|
45
|
-
diff = t2.to_f - t1.to_f
|
46
|
-
puts 'time to create rule set: ' + diff.to_s
|
47
|
-
for k in (0..facts)
|
48
|
-
e.assert Account.new('standard', 'mr', ('acc'+k.to_s))
|
49
|
-
end
|
50
|
-
|
51
|
-
t3 = Time.new
|
52
|
-
diff = t3.to_f - t2.to_f
|
53
|
-
puts 'time to assert facts: ' + diff.to_s
|
54
|
-
e.match
|
55
|
-
|
56
|
-
t4 = Time.new
|
57
|
-
diff = t4.to_f - t3.to_f
|
58
|
-
puts 'time to run agenda: ' + diff.to_s
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
run_benchmark(5, 500)
|
63
|
-
puts '-------'
|
64
|
-
run_benchmark(50, 500)
|
65
|
-
puts '-------'
|
66
|
-
run_benchmark(500, 500)
|
data/benchmarks/joined_rules.rb
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
# This file is part of the Ruleby project (http://ruleby.org)
|
2
|
-
#
|
3
|
-
# This application is free software; you can redistribute it and/or
|
4
|
-
# modify it under the terms of the Ruby license defined in the
|
5
|
-
# LICENSE.txt file.
|
6
|
-
#
|
7
|
-
# Copyright (c) 2007 Joe Kutner and Matt Smith. All rights reserved.
|
8
|
-
#
|
9
|
-
# * Authors: Joe Kutner, Matt Smith
|
10
|
-
#
|
11
|
-
|
12
|
-
$LOAD_PATH << File.join(File.dirname(__FILE__), '../lib/')
|
13
|
-
require 'ruleby'
|
14
|
-
require 'model'
|
15
|
-
|
16
|
-
include Ruleby
|
17
|
-
|
18
|
-
class TestRulebook < Rulebook
|
19
|
-
def rules(n)
|
20
|
-
(0..n).each do |index|
|
21
|
-
rule "Rule-#{index}".to_sym do |r|
|
22
|
-
r.when do |has|
|
23
|
-
has.a Account
|
24
|
-
has.a.status = 'standard'
|
25
|
-
has.a.account_id :id
|
26
|
-
|
27
|
-
has.addr Address
|
28
|
-
has.addr.addr_id = :id, :%
|
29
|
-
has.addr.city = 'Foobar'
|
30
|
-
has.addr.state = 'FB'
|
31
|
-
has.addr.zip = '12345'
|
32
|
-
end
|
33
|
-
|
34
|
-
r.then do |e,vars|
|
35
|
-
# puts "rule #{index} fired"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def run_benchmark(rules,facts)
|
43
|
-
puts "running benchmark for: #{rules} rules and #{facts} facts"
|
44
|
-
|
45
|
-
t1 = Time.new
|
46
|
-
engine :engine do |e|
|
47
|
-
TestRulebook.new(e).rules(rules)
|
48
|
-
|
49
|
-
t2 = Time.new
|
50
|
-
diff = t2.to_f - t1.to_f
|
51
|
-
puts 'time to create rule set: ' + diff.to_s
|
52
|
-
|
53
|
-
|
54
|
-
for k in (0..facts)
|
55
|
-
e.assert Account.new('standard', nil, "acc#{k}")
|
56
|
-
e.assert Address.new("acc#{k}",'Foobar', 'FB', '12345')
|
57
|
-
end
|
58
|
-
|
59
|
-
t3 = Time.new
|
60
|
-
diff = t3.to_f - t2.to_f
|
61
|
-
puts 'time to assert facts: ' + diff.to_s
|
62
|
-
|
63
|
-
e.match
|
64
|
-
|
65
|
-
t4 = Time.new
|
66
|
-
diff = t4.to_f - t3.to_f
|
67
|
-
puts 'time to run agenda: ' + diff.to_s
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
run_benchmark(5, 50)
|
72
|
-
puts '-------'
|
73
|
-
run_benchmark(50, 50)
|
@@ -1,146 +0,0 @@
|
|
1
|
-
# This file is part of the Ruleby project (http://ruleby.org)
|
2
|
-
#
|
3
|
-
# This application is free software; you can redistribute it and/or
|
4
|
-
# modify it under the terms of the Ruby license defined in the
|
5
|
-
# LICENSE.txt file.
|
6
|
-
#
|
7
|
-
# Copyright (c) 2007 Joe Kutner and Matt Smith. All rights reserved.
|
8
|
-
#
|
9
|
-
# * Authors: Joe Kutner, Matt Smith
|
10
|
-
#
|
11
|
-
|
12
|
-
module MissManners
|
13
|
-
class MannersData
|
14
|
-
def initialize
|
15
|
-
@guests16 = [
|
16
|
-
Guest.new(:n1, :f, :h3),
|
17
|
-
Guest.new(:n1, :f, :h1),
|
18
|
-
Guest.new(:n1, :f, :h2),
|
19
|
-
Guest.new(:n2, :f, :h3),
|
20
|
-
Guest.new(:n2, :f, :h2),
|
21
|
-
Guest.new(:n3, :m, :h1),
|
22
|
-
Guest.new(:n3, :m, :h3),
|
23
|
-
Guest.new(:n4, :m, :h2),
|
24
|
-
Guest.new(:n4, :m, :h1),
|
25
|
-
Guest.new(:n5, :m, :h2),
|
26
|
-
Guest.new(:n5, :m, :h3),
|
27
|
-
Guest.new(:n6, :m, :h2),
|
28
|
-
Guest.new(:n6, :m, :h1),
|
29
|
-
Guest.new(:n7, :f, :h2),
|
30
|
-
Guest.new(:n7, :f, :h1),
|
31
|
-
Guest.new(:n7, :f, :h3),
|
32
|
-
Guest.new(:n8, :f, :h3),
|
33
|
-
Guest.new(:n8, :f, :h2),
|
34
|
-
Guest.new(:n9, :f, :h1),
|
35
|
-
Guest.new(:n9, :f, :h3),
|
36
|
-
Guest.new(:n9, :f, :h2),
|
37
|
-
Guest.new(:n10, :m, :h2),
|
38
|
-
Guest.new(:n10, :m, :h3),
|
39
|
-
Guest.new(:n11, :m, :h3),
|
40
|
-
Guest.new(:n11, :m, :h2),
|
41
|
-
Guest.new(:n11, :m, :h1),
|
42
|
-
Guest.new(:n12, :m, :h3),
|
43
|
-
Guest.new(:n12, :m, :h1),
|
44
|
-
Guest.new(:n13, :m, :h2),
|
45
|
-
Guest.new(:n13, :m, :h3),
|
46
|
-
Guest.new(:n13, :m, :h1),
|
47
|
-
Guest.new(:n14, :f, :h3),
|
48
|
-
Guest.new(:n14, :f, :h1),
|
49
|
-
Guest.new(:n15, :f, :h3),
|
50
|
-
Guest.new(:n15, :f, :h2),
|
51
|
-
Guest.new(:n15, :f, :h1),
|
52
|
-
Guest.new(:n16, :f, :h3),
|
53
|
-
Guest.new(:n16, :f, :h2),
|
54
|
-
Guest.new(:n16, :f, :h1),
|
55
|
-
LastSeat.new(16)]
|
56
|
-
|
57
|
-
@guests32 = [
|
58
|
-
Guest.new(:n1, :m, :h1),
|
59
|
-
Guest.new(:n1, :m, :h3),
|
60
|
-
Guest.new(:n2, :f, :h3),
|
61
|
-
Guest.new(:n2, :f, :h2),
|
62
|
-
Guest.new(:n2, :f, :h1),
|
63
|
-
Guest.new(:n3, :f, :h1),
|
64
|
-
Guest.new(:n3, :f, :h2),
|
65
|
-
Guest.new(:n4, :f, :h3),
|
66
|
-
Guest.new(:n4, :f, :h1),
|
67
|
-
Guest.new(:n5, :f, :h1),
|
68
|
-
Guest.new(:n5, :f, :h2),
|
69
|
-
Guest.new(:n6, :m, :h1),
|
70
|
-
Guest.new(:n6, :m, :h2),
|
71
|
-
Guest.new(:n6, :m, :h3),
|
72
|
-
Guest.new(:n7, :f, :h2),
|
73
|
-
Guest.new(:n7, :f, :h1),
|
74
|
-
Guest.new(:n7, :f, :h3),
|
75
|
-
Guest.new(:n8, :f, :h1),
|
76
|
-
Guest.new(:n8, :f, :h3),
|
77
|
-
Guest.new(:n8, :f, :h2),
|
78
|
-
Guest.new(:n9, :f, :h1),
|
79
|
-
Guest.new(:n9, :f, :h3),
|
80
|
-
Guest.new(:n9, :f, :h2),
|
81
|
-
Guest.new(:n10, :m, :h2),
|
82
|
-
Guest.new(:n10, :m, :h1),
|
83
|
-
Guest.new(:n11, :m, :h2),
|
84
|
-
Guest.new(:n11, :m, :h1),
|
85
|
-
Guest.new(:n12, :m, :h3),
|
86
|
-
Guest.new(:n12, :m, :h2),
|
87
|
-
Guest.new(:n13, :m, :h1),
|
88
|
-
Guest.new(:n13, :m, :h3),
|
89
|
-
Guest.new(:n14, :m, :h3),
|
90
|
-
Guest.new(:n14, :m, :h2),
|
91
|
-
Guest.new(:n15, :f, :h2),
|
92
|
-
Guest.new(:n15, :f, :h1),
|
93
|
-
Guest.new(:n15, :f, :h3),
|
94
|
-
Guest.new(:n16, :f, :h3),
|
95
|
-
Guest.new(:n16, :f, :h2),
|
96
|
-
Guest.new(:n16, :f, :h1),
|
97
|
-
Guest.new(:n17, :m, :h3),
|
98
|
-
Guest.new(:n17, :m, :h2),
|
99
|
-
Guest.new(:n18, :f, :h2),
|
100
|
-
Guest.new(:n18, :f, :h1),
|
101
|
-
Guest.new(:n19, :f, :h1),
|
102
|
-
Guest.new(:n19, :f, :h2),
|
103
|
-
Guest.new(:n19, :f, :h3),
|
104
|
-
Guest.new(:n20, :f, :h1),
|
105
|
-
Guest.new(:n20, :f, :h2),
|
106
|
-
Guest.new(:n20, :f, :h3),
|
107
|
-
Guest.new(:n21, :m, :h2),
|
108
|
-
Guest.new(:n21, :m, :h3),
|
109
|
-
Guest.new(:n21, :m, :h1),
|
110
|
-
Guest.new(:n22, :f, :h1),
|
111
|
-
Guest.new(:n22, :f, :h2),
|
112
|
-
Guest.new(:n22, :f, :h3),
|
113
|
-
Guest.new(:n23, :f, :h3),
|
114
|
-
Guest.new(:n23, :f, :h1),
|
115
|
-
Guest.new(:n23, :f, :h2),
|
116
|
-
Guest.new(:n24, :m, :h1),
|
117
|
-
Guest.new(:n24, :m, :h3),
|
118
|
-
Guest.new(:n25, :f, :h3),
|
119
|
-
Guest.new(:n25, :f, :h2),
|
120
|
-
Guest.new(:n25, :f, :h1),
|
121
|
-
Guest.new(:n26, :f, :h3),
|
122
|
-
Guest.new(:n26, :f, :h2),
|
123
|
-
Guest.new(:n26, :f, :h1),
|
124
|
-
Guest.new(:n27, :m, :h3),
|
125
|
-
Guest.new(:n27, :m, :h1),
|
126
|
-
Guest.new(:n27, :m, :h2),
|
127
|
-
Guest.new(:n28, :m, :h3),
|
128
|
-
Guest.new(:n28, :m, :h1),
|
129
|
-
Guest.new(:n29, :m, :h3),
|
130
|
-
Guest.new(:n29, :m, :h2),
|
131
|
-
Guest.new(:n29, :m, :h1),
|
132
|
-
Guest.new(:n30, :m, :h2),
|
133
|
-
Guest.new(:n30, :m, :h1),
|
134
|
-
Guest.new(:n30, :m, :h3),
|
135
|
-
Guest.new(:n31, :m, :h2),
|
136
|
-
Guest.new(:n31, :m, :h1),
|
137
|
-
Guest.new(:n32, :m, :h1),
|
138
|
-
Guest.new(:n32, :m, :h3),
|
139
|
-
Guest.new(:n32, :m, :h2),
|
140
|
-
LastSeat.new(32)]
|
141
|
-
end
|
142
|
-
|
143
|
-
attr_reader :guests16
|
144
|
-
attr_reader :guests32
|
145
|
-
end
|
146
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# This file is part of the Ruleby project (http://ruleby.org)
|
2
|
-
#
|
3
|
-
# This application is free software; you can redistribute it and/or
|
4
|
-
# modify it under the terms of the Ruby license defined in the
|
5
|
-
# LICENSE.txt file.
|
6
|
-
#
|
7
|
-
# Copyright (c) 2007 Joe Kutner and Matt Smith. All rights reserved.
|
8
|
-
#
|
9
|
-
# * Authors: Joe Kutner, Matt Smith
|
10
|
-
#
|
11
|
-
|
12
|
-
$LOAD_PATH << File.join(File.dirname(__FILE__), '../../lib/')
|
13
|
-
require 'ruleby'
|
14
|
-
require 'model'
|
15
|
-
require 'data'
|
16
|
-
require 'rules'
|
17
|
-
|
18
|
-
include Ruleby
|
19
|
-
include MissManners
|
20
|
-
|
21
|
-
t1 = Time.new
|
22
|
-
engine :e do |e|
|
23
|
-
MannersRulebook.new(e).rules
|
24
|
-
MannersData.new.guests16.each do |g|
|
25
|
-
e.assert g
|
26
|
-
end
|
27
|
-
e.assert Context.new(:start)
|
28
|
-
e.assert Count.new(1)
|
29
|
-
e.match
|
30
|
-
end
|
31
|
-
t2 = Time.new
|
32
|
-
diff = t2.to_f - t1.to_f
|
33
|
-
puts diff.to_s
|