Professional Documents
Culture Documents
EXPERT SYSTEMS
In Ruby
OSCAR RENDON
@orendon
OSCAR RENDON
@orendon
RUBY IN COLOMBIA
RUBY IN COLOMBIA
Payroll Systems
# some action…
end
paises = CityRule.new(‘MDE’)
caleños = CityRule.new(‘CLO’)
morosos = Overdue.new(30)
paisas_morosos = AndSpec.new(paisas, morosos)
if ( paisas_morosos.satisfied_by(invoice)
.or(caleños.satisfied_by(invoice) )
# some action…
end
invoice.find(999)
# some action…
end
SPECIFICATION PATTERN
<3 RUBY
RETE ALGORITHM
DSL + RETE
rule :Allergy,
[Patient,:p, {m.name=>:n}, m.rash==true] do |v|
name = v[:n]
assert Diagnosis.new(name, :allergy)
puts "Allergy diagnosed from rash for #{name}"
end
rule :Flu,
[Patient,:p, {m.name=>:n}, m.sore_throat==true,
m.fever(&c{|f| f==:mild || f==:high})] do |v|
name = v[:n]
assert Diagnosis.new(name, :flu)
puts "Flu diagnosed for #{name}"
end
engine :engine do |e|
DiagnosisRulebook.new e do |r|
r.rules
end
e.assert Patient.new('Fred',:none,true,false,false,false)
e.assert Patient.new('Joe',:high,false,false,true,false)
e.assert Patient.new('Bob',:high,true,false,false,true)
e.assert Patient.new('Tom',:none,false,true,false,false)
e.match
end
RECAP
GRACIAS
In Ruby
@orendon