ruleby 0.2 → 0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/benchmarks/basic_rules.rb +66 -0
- data/benchmarks/joined_rules.rb +73 -0
- data/benchmarks/miss_manners/data.rb +11 -0
- data/benchmarks/miss_manners/miss_manners.rb +11 -1
- data/benchmarks/miss_manners/model.rb +11 -0
- data/benchmarks/miss_manners/rules.rb +49 -110
- data/benchmarks/model.rb +36 -0
- data/examples/example_diagnosis.rb +35 -73
- data/examples/example_hello.rb +20 -22
- data/examples/example_politician.rb +22 -11
- data/examples/example_ticket.rb +40 -85
- data/examples/fibonacci_example1.rb +13 -2
- data/examples/fibonacci_example2.rb +11 -0
- data/examples/fibonacci_rulebook.rb +58 -111
- data/examples/test_self_reference.rb +51 -9
- data/lib/core/atoms.rb +53 -116
- data/lib/core/engine.rb +96 -96
- data/lib/core/nodes.rb +330 -298
- data/lib/core/patterns.rb +36 -39
- data/lib/core/utils.rb +141 -3
- data/lib/dsl/ferrari.rb +263 -0
- data/lib/dsl/letigre.rb +212 -0
- data/lib/dsl/steel.rb +313 -0
- data/lib/rulebook.rb +82 -265
- data/lib/ruleby.rb +13 -0
- metadata +21 -19
- data/benchmarks/50_joined_rules.rb +0 -78
- data/benchmarks/50_rules.rb +0 -57
- data/benchmarks/5_joined_rules.rb +0 -78
- data/benchmarks/5_rules.rb +0 -57
data/benchmarks/50_rules.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
$LOAD_PATH << File.join(File.dirname(__FILE__), '../lib/')
|
2
|
-
require 'ruleby'
|
3
|
-
require 'rulebook'
|
4
|
-
|
5
|
-
class Account
|
6
|
-
def initialize(status, title, account_id)
|
7
|
-
@status = status
|
8
|
-
@title = title
|
9
|
-
@account_id = account_id
|
10
|
-
end
|
11
|
-
|
12
|
-
attr :status, true
|
13
|
-
attr :title, true
|
14
|
-
attr :account_id, true
|
15
|
-
end
|
16
|
-
|
17
|
-
class TestRulebook < Rulebook
|
18
|
-
def rules
|
19
|
-
(0..50).each do |index|
|
20
|
-
rule "Rule-#{index}" do |r|
|
21
|
-
r.when do |has|
|
22
|
-
has.a Account
|
23
|
-
has.a.status = 'standard'
|
24
|
-
has.a.title = 'mr'
|
25
|
-
has.a.account_id = "acc#{index}"
|
26
|
-
end
|
27
|
-
|
28
|
-
r.then do |e,vars|
|
29
|
-
puts "rule #{index} fired"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
include Ruleby
|
37
|
-
|
38
|
-
t1 = Time.new
|
39
|
-
engine :engine do |e|
|
40
|
-
TestRulebook.new(e).rules
|
41
|
-
|
42
|
-
t2 = Time.new
|
43
|
-
diff = t2.to_f - t1.to_f
|
44
|
-
puts 'time to create rule set: ' + diff.to_s
|
45
|
-
for k in (0..500)
|
46
|
-
e.assert Account.new('standard', 'mr', ('acc'+k.to_s))
|
47
|
-
end
|
48
|
-
|
49
|
-
t3 = Time.new
|
50
|
-
diff = t3.to_f - t2.to_f
|
51
|
-
puts 'time to assert facts: ' + diff.to_s
|
52
|
-
e.match
|
53
|
-
|
54
|
-
t4 = Time.new
|
55
|
-
diff = t4.to_f - t3.to_f
|
56
|
-
puts 'time to match rules: ' + diff.to_s
|
57
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
$LOAD_PATH << File.join(File.dirname(__FILE__), '../lib/')
|
2
|
-
require 'ruleby'
|
3
|
-
require 'rulebook'
|
4
|
-
|
5
|
-
class Account
|
6
|
-
def initialize(status, title, account_id)
|
7
|
-
@status = status
|
8
|
-
@title = title
|
9
|
-
@account_id = account_id
|
10
|
-
end
|
11
|
-
|
12
|
-
attr :status, true
|
13
|
-
attr :title, true
|
14
|
-
attr :account_id, true
|
15
|
-
end
|
16
|
-
|
17
|
-
class Address
|
18
|
-
def initialize(addr_id, city, state, zip)
|
19
|
-
@addr_id = addr_id
|
20
|
-
@city = city
|
21
|
-
@state = state
|
22
|
-
@zip = zip
|
23
|
-
end
|
24
|
-
|
25
|
-
attr :addr_id, true
|
26
|
-
attr :city, true
|
27
|
-
attr :state, true
|
28
|
-
attr :zip, true
|
29
|
-
end
|
30
|
-
|
31
|
-
class TestRulebook < Rulebook
|
32
|
-
def rules
|
33
|
-
(0..5).each do |index|
|
34
|
-
rule "Rule-#{index}" do |r|
|
35
|
-
r.when do |has|
|
36
|
-
has.a Account
|
37
|
-
has.a.status = 'standard'
|
38
|
-
|
39
|
-
has.addr Address
|
40
|
-
has.addr.addr_id = "acc#{index}"
|
41
|
-
has.addr.city = 'Foobar'
|
42
|
-
has.addr.state = 'FB'
|
43
|
-
has.addr.zip = '12345'
|
44
|
-
end
|
45
|
-
|
46
|
-
r.then do |e,vars|
|
47
|
-
puts "rule #{index} fired"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
include Ruleby
|
55
|
-
|
56
|
-
t1 = Time.new
|
57
|
-
engine :engine do |e|
|
58
|
-
TestRulebook.new(e).rules
|
59
|
-
|
60
|
-
t2 = Time.new
|
61
|
-
diff = t2.to_f - t1.to_f
|
62
|
-
puts 'time to create rule set: ' + diff.to_s
|
63
|
-
|
64
|
-
e.assert Account.new('standard', nil, nil)
|
65
|
-
for k in (0..500)
|
66
|
-
e.assert Address.new(('acc'+k.to_s),'Foobar', 'FB', '12345')
|
67
|
-
end
|
68
|
-
|
69
|
-
t3 = Time.new
|
70
|
-
diff = t3.to_f - t2.to_f
|
71
|
-
puts 'time to assert facts: ' + diff.to_s
|
72
|
-
|
73
|
-
e.match
|
74
|
-
|
75
|
-
t4 = Time.new
|
76
|
-
diff = t4.to_f - t3.to_f
|
77
|
-
puts 'time to match rules: ' + diff.to_s
|
78
|
-
end
|
data/benchmarks/5_rules.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
$LOAD_PATH << File.join(File.dirname(__FILE__), '../lib/')
|
2
|
-
require 'ruleby'
|
3
|
-
require 'rulebook'
|
4
|
-
|
5
|
-
class Account
|
6
|
-
def initialize(status, title, account_id)
|
7
|
-
@status = status
|
8
|
-
@title = title
|
9
|
-
@account_id = account_id
|
10
|
-
end
|
11
|
-
|
12
|
-
attr :status, true
|
13
|
-
attr :title, true
|
14
|
-
attr :account_id, true
|
15
|
-
end
|
16
|
-
|
17
|
-
class TestRulebook < Rulebook
|
18
|
-
def rules
|
19
|
-
(0..5).each do |index|
|
20
|
-
rule "Rule-#{index}" do |r|
|
21
|
-
r.when do |has|
|
22
|
-
has.a Account
|
23
|
-
has.a.status = 'standard'
|
24
|
-
has.a.title = 'mr'
|
25
|
-
has.a.account_id = "acc#{index}"
|
26
|
-
end
|
27
|
-
|
28
|
-
r.then do |e,vars|
|
29
|
-
puts "rule #{index} fired"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
include Ruleby
|
37
|
-
|
38
|
-
t1 = Time.new
|
39
|
-
engine :engine do |e|
|
40
|
-
TestRulebook.new(e).rules
|
41
|
-
|
42
|
-
t2 = Time.new
|
43
|
-
diff = t2.to_f - t1.to_f
|
44
|
-
puts 'time to create rule set: ' + diff.to_s
|
45
|
-
for k in (0..500)
|
46
|
-
e.assert Account.new('standard', 'mr', ('acc'+k.to_s))
|
47
|
-
end
|
48
|
-
|
49
|
-
t3 = Time.new
|
50
|
-
diff = t3.to_f - t2.to_f
|
51
|
-
puts 'time to assert facts: ' + diff.to_s
|
52
|
-
e.match
|
53
|
-
|
54
|
-
t4 = Time.new
|
55
|
-
diff = t4.to_f - t3.to_f
|
56
|
-
puts 'time to match rules: ' + diff.to_s
|
57
|
-
end
|