Building Parsers with Java

sjm.engine
Class Fact

java.lang.Object
  |
  +--sjm.engine.Structure
        |
        +--sjm.engine.Fact
Direct Known Subclasses:
Atom, EmptyList

public class Fact
extends Structure
implements Axiom, DynamicAxiom

A Fact is a Structure that contains only other Facts.

For example,

     Fact s = new Fact(
         "starred", 
         new Fact[]{
             new Fact("James Cagney"),
             new Fact("Yankee Doodle Dandy")}); 
 
The Fact class offers several convenience constructors. For example, you can create an identical fact with:
     Fact s = new Fact(
         "starred", "James Cagney", "Yankee Doodle Dandy"); 
 
or with:
     Fact s = new Fact(
         "starred", 
         new Object[]{
             "James Cagney", "Yankee Doodle Dandy"}); 
 
Since they do not contain variables, Facts do not need to copy themselves when they provide a "copy" for a proof. They also avoid copying when then provide a dynamic axiom.


Field Summary
protected static DynamicRule resolvent
           
 
Fields inherited from class sjm.engine.Structure
emptyList, functor, terms
 
Constructor Summary
Fact(java.lang.Object functor)
          Contructs a fact from the specified object.
Fact(java.lang.Object functor, Fact[] terms)
          Constructs a fact with the specified functor and facts.
Fact(java.lang.Object functor, java.lang.Object o)
          A convenience, equivalent to new Fact(functor, new Object[]{o}).
Fact(java.lang.Object functor, java.lang.Object[] objects)
          Constructs a fact with the specified functor, and with terms that are atoms wrapped around the supplied objects.
Fact(java.lang.Object functor, java.lang.Object o1, java.lang.Object o2)
          A convenience, equivalent to new Fact(functor, new Object[]{o1, o2}).
Fact(java.lang.Object functor, Term[] objects)
          Although "public", this method is not for public use.
 
Method Summary
 Term copyForProof(AxiomSource ignored, Scope ignored2)
          Returns this fact.
 DynamicAxiom dynamicAxiom(AxiomSource ignored)
          Returns this fact.
protected static Fact[] facts(java.lang.Object[] objects)
           
 Structure head()
          Returns this fact.
 DynamicRule resolvent()
          Returns an empty resolvent
 Unification unify(Fact f)
          A speedier version of unify(Structure s).
 
Methods inherited from class sjm.engine.Structure
arity, canFindNextProof, equals, eval, functorAndArityEquals, headAndTail, isList, list, list, list, listTailString, listTermsToString, terms, toString, unify, unify, unify, variables
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

resolvent

protected static final DynamicRule resolvent
Constructor Detail

Fact

public Fact(java.lang.Object functor)
Contructs a fact from the specified object.
Parameters:
Object - the functor for this fact

Fact

public Fact(java.lang.Object functor,
            java.lang.Object[] objects)
Constructs a fact with the specified functor, and with terms that are atoms wrapped around the supplied objects.
Parameters:
Object - the functor of the structure
Object[] - the objects to convert into atoms and use as the terms of this fact

Fact

public Fact(java.lang.Object functor,
            Fact[] terms)
Constructs a fact with the specified functor and facts.
Parameters:
Object - the functor of the structure
Term[] - the terms of this fact, which can only be other facts

Fact

public Fact(java.lang.Object functor,
            Term[] objects)
Although "public", this method is not for public use.

Without this constructor, or if this constructor were private,

 
 new Fact(
     "starred", 
     new Term[]{new Fact("Cagney", "Yankee Doodle Dandy")})
 
would match the signature on Fact(Object, Object[]) , which is not what we want. This would wrap each fact in another fact.

Allowing this constructor gives the appearance of allowing Facts with any kind of terms, including variables, which are verboten.

Throws:
java.lang.RuntimeException - Cannot construct a fact from generic terms; Use new Fact(functor, new Fact[]{...})

Fact

public Fact(java.lang.Object functor,
            java.lang.Object o)
A convenience, equivalent to new Fact(functor, new Object[]{o}).
Parameters:
Object - the functor of the structure
Object - the object to convert to an atom and use as the term of this fact

Fact

public Fact(java.lang.Object functor,
            java.lang.Object o1,
            java.lang.Object o2)
A convenience, equivalent to new Fact(functor, new Object[]{o1, o2}).
Parameters:
Object - the functor of the structure
Object - an object to convert to an atom and use as the first term of this fact
Object - an object to convert to an atom and use as the second term of this fact
Method Detail

copyForProof

public Term copyForProof(AxiomSource ignored,
                         Scope ignored2)
Returns this fact.
Overrides:
copyForProof in class Structure
Returns:
this fact

dynamicAxiom

public DynamicAxiom dynamicAxiom(AxiomSource ignored)
Returns this fact.
Specified by:
dynamicAxiom in interface Axiom
Returns:
this fact

facts

protected static Fact[] facts(java.lang.Object[] objects)

head

public Structure head()
Returns this fact.
Specified by:
head in interface Axiom
Returns:
this fact

resolvent

public DynamicRule resolvent()
Returns an empty resolvent
Specified by:
resolvent in interface DynamicAxiom
Returns:
a dynamic rule with nothing in it

unify

public Unification unify(Fact f)
A speedier version of unify(Structure s).
Returns:
either an empty Unification, indicating success, or null, indicating failure

by Steve Metsker