Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ of IF-THEN statements known as production rules. These rules are matched to obje
the forward chaining Rete algorithm. Ruleby provides an internal Domain Specific Language
(DSL) for building the productions that make up a Ruleby program.

Test
-------------

Run test with
```
ruby test/test.rb
```

Version
-------
0.9.b7
Expand Down
4 changes: 2 additions & 2 deletions examples/fibonacci_example1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

$LOAD_PATH << File.join(File.dirname(__FILE__), '../lib/')
require 'ruleby'
require 'fibonacci_rulebook'
require_relative 'fibonacci_rulebook'
class Fibonacci
def initialize(sequence,value=-1)
@sequence = sequence
Expand Down Expand Up @@ -41,4 +41,4 @@ def to_s
end
t2 = Time.new
diff = t2.to_f - t1.to_f
puts diff.to_s
puts diff.to_s
4 changes: 2 additions & 2 deletions examples/fibonacci_example2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

$LOAD_PATH << File.join(File.dirname(__FILE__), '../lib/')
require 'ruleby'
require 'fibonacci_rulebook'
require_relative 'fibonacci_rulebook'
class Fibonacci
def initialize(sequence,value=-1)
@sequence = sequence
Expand All @@ -37,4 +37,4 @@ def to_s
e.assert fib1
e.assert fib2
e.match
end
end
8 changes: 4 additions & 4 deletions examples/ticket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def rules
# the same rule set.
rule :New_Ticket, {:priority => 10}, # :duration => 10},
[Customer, :c],
[Ticket, :ticket, {m.customer => :c}, m.status == :New] do |vars|
[Ticket, :ticket, {m.customer => :ticket_customer}, m.customer == b(:c), m.status == :New] do |vars|
puts 'New : ' + vars[:ticket].to_s
end

Expand Down Expand Up @@ -75,13 +75,13 @@ def rules

rule :Escalate,
[Customer, :c],
[Ticket, :ticket, {m.customer => :c}, m.status == :Escalate] do |vars|
[Ticket, :ticket, {m.customer => :ticket_customer}, m.customer == b(:c), m.status == :Escalate] do |vars|
puts 'Email : ' + vars[:ticket].to_s
end

rule :Done,
[Customer, :c],
[Ticket, :ticket, {m.customer => :c}, m.status == :Done] do |vars|
[Ticket, :ticket, {m.customer => :ticket_cutomer}, m.customer == b(:c), m.status == :Done] do |vars|
puts 'Done : ' + vars[:ticket].to_s
end
end
Expand Down Expand Up @@ -110,4 +110,4 @@ def rules
e.assert t3
e.assert t4
e.match
end
end
7 changes: 5 additions & 2 deletions lib/core/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ def to_s
# properties of the activation.
class RulebyConflictResolver
def resolve(agenda)
return agenda.sort
# Sorting objects with equal properties will not preserve original sort so
# we need to use index since someone could rely on the order of rules
# https://stackoverflow.com/a/64793425/287166
agenda.sort_by.with_index { |a, i| [a, i] }
end
end

Expand Down Expand Up @@ -296,4 +299,4 @@ def retract_fact(fact)
end
end
end
end
end
20 changes: 10 additions & 10 deletions tests/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
#
# * Authors: John Mettraux
#
require 'common'
require 'duck_type'
require 'self_reference'
require 'regex'
require 'gets'
require 'assert_facts'
require 'not_patterns'
require 'or_patterns'
require 'join_nodes'
require 'nil'
require_relative 'common'
require_relative 'duck_type'
require_relative 'self_reference'
require_relative 'regex'
require_relative 'gets'
require_relative 'assert_facts'
require_relative 'not_patterns'
require_relative 'or_patterns'
require_relative 'join_nodes'
require_relative 'nil'