Skip to content

femto/rbclips

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rbClips

RbClips is a binary extension for Ruby language (MRI version), that allow you to use expert system tool CLIPS in your Ruby app.

Interface

I’m supposing that you’re already familiar with CLIPS tool and it’s user interface. Entire interface of rbClips have similar approach as ActiveRecord project.

Templates

Working with templates is done via Template class.

Example:

human_template = Template.new "human" do |s|
  s.slot name
  s.slot surname
  s.slot age, :constraint => { :type => :integer, :range => 0..120 }
end

Facts

Facts are wrapped by Fact class - both ordered and nonordered

Example with ordered facts:

Fact.new "animal", ["dog"]
Fact.new "child-f", %w(dog puppy)

Example with nonordered facts:

Fact.new human_template, :name => "Kocour", :surname => "Mikes", :age => 30

Rules

Entire work with rules is wrapped into Rule class.

Example:

mammal1 = Rule.new "mammal" do |r|
  r.pattern 'animal', :name
  r.pattern 'warm-blooded', :name
  r.not do |n|
     n.pattern 'lays-eggs', :name
  end
  r.assert 'mammal', :name
end

“Complex” example

# Load binary extension into memory
require 'Clips'

# Put it into local scope (avoid writing Clips:: before everything)
include 'Clips'

# Create facts
Fact.new('animal', %w(dog)).save
Fact.new('animal', %w(cat)).save
Fact.new('animal', %w(duck)).save
Fact.new('animal', %w(turtle)).save
Fact.new('warm-blooded', %w(dog)).save
Fact.new('warm-blooded', %w(cat)).save
Fact.new('warm-blooded', %w(duck)).save
Fact.new('lays-eggs', %w(duck)).save
Fact.new('lays-eggs', %w(turtle)).save
Fact.new('child-of', %w(dog puppy)).save
Fact.new('child-of', %w(cat kitten)).save
Fact.new('child-of', %w(tutrle hatchling)).save

# First rule
mammal1 = Rule.new "mammal" do |r|
  r.pattern 'animal', :name
  r.pattern 'warm-blooded', :name
  r.not do |n|
     n.pattern 'lays-eggs', :name
  end
  r.assert 'mammal', :name
end
mammal1.save

# Second rule
mammal2 = Rule.new "childs" do |r|
  r.pattern 'mammal', :name
  r.pattern 'child-of', :name, :young
  r.assert 'mammal', :young
end
mammal2.save

# Run the app
Base.run

Documentation

Documentation can be build from source codes using Doxygen tool. To build documentation just run “doxygen” command in doc/doxygen subdirectory.

License

Project is licensed under ASLv2.

About

Ruby bindings for CLIPS tool

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 95.2%
  • TeX 2.8%
  • C++ 1.2%
  • Other 0.8%