Liking cljdoc? Tell your friends :D

fogus.rv.productions

The simplest possible production rules system. A run pairs two abstractions: a knowledge base (facts + rules) with an engine (a rule-selection strategy paired with a quiessence-detection strategy).

A production rules system is built from two abstractions:

  1. A knowledge base is the rules and the facts they operate on (the WHAT)
  2. An engine is the policy that applies the rule processing (the HOW)

Productions are represented as maps having two privileged keys: {:antecedent ... :consequent ...}

The :antecedent key in the production map contains a sequence of EAV 3-tuples with logical variables at key locations for the purpose of pattern matching:

[[?id :person/name "Fogus"] [?id :language/speaks ?lang]]

The antecedent describes the patterns that must be present in the EAV set in order for the production to activate. The antecedent is also known as the left-hand-side (LHS) of the production.

When a production activates, the structure in the :consequent key in the production map is applied to the knowledge base to potentially create new facts. The consequent also contains a sequence of EAV 3-tuples with logical variables at key locations. However, these tuples describe new facts with values bound to embedded logic variables as defined within the antecedent context of a production activation.

A production set is a data structure defined as such:

  1. A production set is simply a vector of production definitions
  2. A production definition is a map containing :antecedent and :consequent keys
  3. An antecedent is a vector of EAV 3-tuples representing patterns in data
  4. An EAV 3-tuple is a vector of three elements: id, attribute, value
  5. A consequent is a vector of EAV 3-tuples representing new attribute assertions

A fact base is a set of EAV 3-tuples.

A knowledge base is a map of productions and facts, mapped to keys:

{:productions #{...} :facts #{...}}

An engine describes how a knowledge base is processed: which matching production fires next, how the stream of successive fact sets is shaped, and how quiessence is detected:

:rule-choice -> fn to pick which production fires next :state-xform -> transformer of fact-set states :quiesce -> a completing reducing function that detects when to stop

The production rules system implemented herein runs an engine against a knowledge base in four stages:

  1. Antecedent unifications over the KB's facts
  2. Production selection via the engine's :rule-choice
  3. Consequent substitution and assertion
  4. System quiessence via the engine's :quiesce, through :state-xform
The simplest possible production rules system. A run pairs two
abstractions: a knowledge base (facts + rules) with an engine (a
rule-selection strategy paired with a quiessence-detection strategy).

A production rules system is built from two abstractions:

  1. A knowledge base is the rules and the facts they operate on (the WHAT)
  2. An engine is the policy that applies the rule processing (the HOW)

Productions are represented as maps having two privileged keys:
{:antecedent ...
 :consequent ...}

The :antecedent key in the production map contains a sequence of EAV
3-tuples with logical variables at key locations for the purpose of
pattern matching:

  [[?id :person/name     "Fogus"]
   [?id :language/speaks ?lang]]

The antecedent describes the patterns that must be present in the EAV
set in order for the production to activate. The antecedent is also
known as the left-hand-side (LHS) of the production.

When a production activates, the structure in the :consequent key in
the production map is applied to the knowledge base to potentially
create new facts. The consequent also contains a sequence of EAV
3-tuples with logical variables at key locations. However, these tuples
describe new facts with values bound to embedded logic variables as
defined within the antecedent context of a production activation.

A production set is a data structure defined as such:

  1. A production set is simply a vector of production definitions
  2. A production definition is a map containing :antecedent and :consequent keys
  3. An antecedent is a vector of EAV 3-tuples representing patterns in data
  4. An EAV 3-tuple is a vector of three elements: id, attribute, value
  5. A consequent is a vector of EAV 3-tuples representing new attribute assertions

A fact base is a set of EAV 3-tuples.

A knowledge base is a map of productions and facts, mapped to keys:

{:productions #{...}
 :facts       #{...}}

An engine describes how a knowledge base is processed: which
matching production fires next, how the stream of successive fact sets
is shaped, and how quiessence is detected:

:rule-choice -> fn to pick which production fires next
:state-xform -> transformer of fact-set states
:quiesce     -> a completing reducing function that detects when to stop

The production rules system implemented herein runs an engine against
a knowledge base in four stages:

  1. Antecedent unifications over the KB's facts
  2. Production selection via the engine's :rule-choice
  3. Consequent substitution and assertion
  4. System quiessence via the engine's :quiesce, through :state-xform
raw docstring

apply-productionclj

(apply-production production facts context)
source

make-engineclj

(make-engine & {:as config})

Constructs a production rules engine from input functions:

:rule-choice -> fn to pick which production fires next :state-xform -> transformer of fact-set states :quiesce -> a completing reducing function that detects when to stop () initial accumulator (state) extract the final fact set (state s) new state, or (reduced acc)

Constructs a production rules engine from input functions:

:rule-choice -> fn to pick which production fires next
:state-xform -> transformer of fact-set states
:quiesce     -> a completing reducing function that detects when to stop
    () initial accumulator
    (state) extract the final fact set
    (state s) new state, or (reduced acc)
sourceraw docstring

runclj

(run {:keys [rule-choice state-xform quiesce]} kb)

Runs a production rules engine against a knowledge base, driving the state stream through the engine's transducer and quiessence function until quiessence is reached, then returning the final fact set.

Runs a production rules engine against a knowledge base, driving the
state stream through the engine's transducer and quiessence function
until quiessence is reached, then returning the final fact set.
sourceraw docstring

select-productionclj

(select-production selection-strategy {:keys [productions facts]})

Builds a sequence of bindings paired with each production and then uses a selection function to execute one of the productions that matched.

Builds a sequence of bindings paired with each production and then uses a selection 
function to execute one of the productions that matched.
sourceraw docstring

statesclj

(states choice-fn kb)

Will apply the result of one production firing to the fact base and feed the result forward into the next firing. The production selection is driven by choice-fn.

Will apply the result of one production firing to the fact base and feed
the result forward into the next firing. The production selection is
driven by choice-fn.
sourceraw docstring

stepclj

(step kb)
(step choice-fn kb)

Takes a set of productions and facts and returns a new fact base based on the application of single production.

Takes a set of productions and facts and returns a new fact base based on the application of single production.
sourceraw docstring

unificationsclj

(unifications [clause & more :as clauses] facts context)

Walks through all of the clauses in an implied antecedent and matches each against every fact provided. Returns a seq of contexts representing all of the bindings established by the antecedent unifications across all facts provided.

Walks through all of the clauses in an implied antecedent and matches 
each against every fact provided. Returns a seq of contexts representing
all of the bindings established by the antecedent unifications across all
facts provided.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close