You are on page 1of 64

RULE-BASED


EXPERT SYSTEMS
In Ruby
OSCAR RENDON
@orendon
OSCAR RENDON
@orendon
RUBY IN COLOMBIA
RUBY IN COLOMBIA

Automatic Reporting Workflow for Hippocampal Volumetry



http://archive.rsna.org/2012/12034383.html
RUBY IN COLOMBIA

Automatic Reporting Workflow for Hippocampal Volumetry



http://archive.rsna.org/2012/12034383.html

Open-Source, Web-Based Dashboard Components for DICOM


Connectivity

http://link.springer.com/article/10.1007/s10278-016-9866-0?
wt_mc=internal.event.1.SEM.ArticleAuthorOnlineFirst
RUBY IN COLOMBIA

Automatic Reporting Workflow for Hippocampal Volumetry



http://archive.rsna.org/2012/12034383.html

Open-Source, Web-Based Dashboard Components for DICOM


Connectivity

http://link.springer.com/article/10.1007/s10278-016-9866-0?
wt_mc=internal.event.1.SEM.ArticleAuthorOnlineFirst

Automated Volumetric Report with Normative Ranges: A Ruby Based


Tool Integrated with FSL

https://c.ymcdn.com/sites/siim.org/resource/resmgr/
siim2016abstracts/Poster_Demo_Pineda.pdf
RUBY IN COLOMBIA
Automatic Reporting Workflow for Hippocampal Volumetry

http://archive.rsna.org/2012/12034383.html

Open-Source, Web-Based Dashboard Components for DICOM Connectivity



http://link.springer.com/article/10.1007/s10278-016-9866-0?wt_mc=internal.event.
1.SEM.ArticleAuthorOnlineFirst

Automated Volumetric Report with Normative Ranges: A Ruby Based Tool


Integrated with FSL

https://c.ymcdn.com/sites/siim.org/resource/resmgr/siim2016abstracts/
Poster_Demo_Pineda.pdf

A Ruby implementation of the Orthanc DICOM server



https://github.com/simonmd/orthanc-ruby
RUBY IN COLOMBIA

Radiology Information Systems (RIS)

Payroll Systems

Payment Platforms, credit card, cash payments and bank transfers

Expert Systems on different sectors


RULE-BASED
EXPERT SYSTEMS
RULE-BASED
EXPERT SYSTEMS
RULE-BASED
EXPERT SYSTEMS
BUSINESS RULES
FEATURE REQUEST
“A great way to increase sales is
by offering discounts on bulk
purchases. 

We give 10% off if you buy 12 or
more of the same product.”
–Our beloved user
CONDITIONALS!
def actual_price

if (quantity >= 12)

price - (price * 0.1)

else

price

end

end
FEATURE REQUEST
def actual_price

if (quantity >= 12)

price - (price * 0.1)

else

price

end

end
def actual_price

if (quantity >= 12 && clothes?)

price - (price * 0.1)

else

price

end

end
def actual_price

if (quantity >= 12 && clothes?)

if (code == ‘TSHIRT’)

price - (price * 0.15)

else

price - (price * 0.1)

end

else

price

end

end
IF-THEN-ELSE
FEATURE REQUEST
ABSTRACTIONS!
PATTERNS!
HARD CODED SPEC
if (Time.now - invoice.due_date) > 30.days

&& invoice.coverage_code == ‘MDE’)

# some action…

end
class OverdueRule

def satisfied_by?(invoice)

(Time.now - invoice.due_date) > 30.days

end

end
class CityRule

def satisfied_by?(invoice)

invoice.coverage_code == ‘MDE’

end

end
PARAMETERIZED SPEC
class OverdueRule

def initialize(limit)

@limit = limit

end


def satisfied_by?(invoice)

(Time.now - invoice.due_date) > @limit.days

end

end
class CityRule

def initialize(city_code)

@city_code = city_code

end


def satisfied_by?(invoice)

invoice.coverage_code == @city_code

end

end
COMPOSITE SPEC
module Specification

def and(other)

AndSpec.new(self, other)

end


def or(other)

OrSpec.new(self, other)

end


def not

NotSpec.new(self)

end
def satisfied_by?(object)

raise NotImplementedError

end

end
class AndSpec

include Specification


def initialize(left, right)

@left, @right = left, right

end


def satisfied_by?(object)

left.satisfied_by?(object) && 

right.satisfied_by?(object)

end

end
class OrSpec

include Specification


def initialize(left, right)

@left, @right = left, right

end


def satisfied_by?(object)

left.satisfied_by?(object) || 

right.satisfied_by?(object)

end

end
class NotSpec

include Specification


def initialize(spec)

@spec = spec

end


def satisfied_by?(object)

! spec.satisfied_by?(object)

end

end
invoice.find(999)

if ( (invoice.due_days > 30



&& invoice.coverage_code == ‘MDE’) ||

invoice.coverage_code == ‘CLO’)

# 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)

if ( (invoice.due_days > 30



&& invoice.coverage_code == ‘MDE’) ||

invoice.coverage_code == ‘CLO’)

# 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

You might also like