Building Parsers with Java

sjm.engine
Class DynamicRule

java.lang.Object
  |
  +--sjm.engine.Rule
        |
        +--sjm.engine.DynamicRule
Direct Known Subclasses:
Query

public class DynamicRule
extends Rule
implements DynamicAxiom

A DynamicRule represents a provable statement that a structure is true if a following series of other structures are true.

For example,

     bachelor(X) :- male(X), unmarried(X);
 

is a logical rule.

The head of this rule is the structure bachelor(X) . A structure bachelor(B) can prove itself by unifying with the head, and then proving the remaining structures or "tail". The tail in this example contains male(X) and unmarried(X).


Field Summary
protected  AxiomSource as
           
protected  boolean headInvolved
           
protected  Scope scope
           
protected  DynamicRule tail
           
 
Fields inherited from class sjm.engine.Rule
structures
 
Constructor Summary
protected DynamicRule(AxiomSource as, Scope scope, Rule rule)
          Construct a provable rule for the given axiom source, scope, and rule.
protected DynamicRule(AxiomSource as, Scope scope, Structure[] structures)
           
 
Method Summary
 boolean canEstablish()
          "Can establish" means that either a rule can prove itself, or that the rule is empty.
 boolean canFindNextProof()
          Tests if this rule can find another proof, and, if so, sets this rule's variables to the values that make the proof true.
 Scope getScope()
          Return the home of this dynamic rule's variables.
 boolean isEmpty()
          Return true if this rule contains no structures.
 Variable lookup(java.lang.String name)
          Return a variable of the given name.
protected static Structure[] provableStructures(AxiomSource as, Scope scope, Structure[] structures)
          Create provable versions of an input array of structures.
 DynamicRule resolvent()
          Returns the series of structures which, if proven, prove the truth of the head.
 DynamicRule tail()
          Returns the series of structures after the head.
 Unification variables()
          Returns this executable rule's variables.
 
Methods inherited from class sjm.engine.Rule
dynamicAxiom, equals, head, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

as

protected AxiomSource as

scope

protected Scope scope

headInvolved

protected boolean headInvolved

tail

protected DynamicRule tail
Constructor Detail

DynamicRule

protected DynamicRule(AxiomSource as,
                      Scope scope,
                      Structure[] structures)

DynamicRule

protected DynamicRule(AxiomSource as,
                      Scope scope,
                      Rule rule)
Construct a provable rule for the given axiom source, scope, and rule.
Parameters:
AxiomSource - the source to consult for proving the structures in this dynamic rule
Scope - a home for the variables in this dynamic rule
Rule - the non-dynamic source of this rule.
Method Detail

canEstablish

public boolean canEstablish()
"Can establish" means that either a rule can prove itself, or that the rule is empty. When a structure unifies with the head of a rule, the structure asks the rule's tail if it can "establish" itself. This amounts to proving the tail, unless this rule is empty. If this rule is empty, it can "establish" itself, but it cannot "find next proof".
Returns:
true if this rule is empty, or if it is nonempty and can find another proof

canFindNextProof

public boolean canFindNextProof()
Tests if this rule can find another proof, and, if so, sets this rule's variables to the values that make the proof true.

Returns:
true if this rule can find another proof.

getScope

public Scope getScope()
Return the home of this dynamic rule's variables.
Returns:
the home of this dynamic rule's variables

isEmpty

public boolean isEmpty()
Return true if this rule contains no structures.
Returns:
true if this rule contains no structures.

lookup

public Variable lookup(java.lang.String name)
Return a variable of the given name.
Parameters:
String - the name to look up
Returns:
a variable of the given name

provableStructures

protected static Structure[] provableStructures(AxiomSource as,
                                                Scope scope,
                                                Structure[] structures)
Create provable versions of an input array of structures.

resolvent

public DynamicRule resolvent()
Returns the series of structures which, if proven, prove the truth of the head.
Specified by:
resolvent in interface DynamicAxiom
Returns:
the tail of this rule

tail

public DynamicRule tail()
Returns the series of structures after the head.
Returns:
the tail of this rule

variables

public Unification variables()
Returns this executable rule's variables.
Returns:
unification a collection of variables from this rule

by Steve Metsker