|
Building Parsers with Java | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--sjm.engine.Structure
|
+--sjm.engine.Gateway
A Gateway is a structure that can prove its truth at most once before failing.
Examples of gateways are comparisons, negations, and
mathematical evaluations. For example, Age >
18 is either true or not, it cannot prove itself in
more than one way. Also, not married(X) is
true only if the structure married(X) cannot
prove itself at all.
The fact that gateways can be true only once is important in rules. For example, a rule might contain:
..., plays(jim, Game, Rating),
Rating >= 7, likes(jane, Game), ...
As this rule proves itself, if it finds a game that Jim
plays with a rating of, say, 8, the rule will accept that
Rating >= 7. The rule will then proceed to
prove the structures after the comparison. The rule may
succeed with the latter structures many times, but
eventually these structures will run out of proofs, and the
rule will fail back to the comparison structure.
On failing back, the rule will ask the comparison for its
next proof. This amounts to asking if there is a different
way to prove that 8 is greater than or equal to 7. Since
the comparison has already succeeded once, which allowed
the rule to check the latter structures, on failing back
the comparison will fail. This will cause the rule to fail
back to the preceding plays structure, which
may be able to find other proofs.
If a preceding structure succeeds, the rule will move forward again, and ask a gateway to prove itself. Since the gateway has failed, it will try again to prove itself.
| Field Summary | |
protected boolean |
open
|
| Fields inherited from class sjm.engine.Structure |
emptyList,
functor,
terms |
| Constructor Summary | |
protected |
Gateway(java.lang.Object functor,
Term[] terms)
Allows subclasses to use this form of constructor. |
| Method Summary | |
boolean |
canFindNextProof()
Returns true if the gate is closed and this gateway can find a new proof. |
boolean |
canProveOnce()
Returns true if the comparison operator holds true between each pair of terms. |
protected void |
cleanup()
Insert the method's description here. |
| Methods inherited from class sjm.engine.Structure |
arity,
copyForProof,
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 |
protected boolean open
| Constructor Detail |
protected Gateway(java.lang.Object functor,
Term[] terms)
functor - the functor for this gatewayterms - the terms of the gatewayprogram - the program the gateway will prove itself
against| Method Detail |
public boolean canFindNextProof()
A gateway is a structure that can prove itself in at most one way. After a successful proof, a gateway leaves its gate open.
If the gate is open when this method executes, this method will shut the gate and return false. This occurs after a gateway has proven itself true once, and a rule has failed back to the point where it is asking the gateway for another proof.
If the gate is not open, this gateway will try to prove itself. Then,
Upon leaving the gate closed, this method unbinds any variables that instantiated as part of this gateway's proof. This method also sets rule checking to begin again at the first program rule, upon the next request for a proof sent to this gateway.
depth - the depth at which to print tracing informationpublic boolean canProveOnce()
This method recovers the comparison operator from the Token which is the functor for this Comparison. This method applies this comparison to each pair of terms. That is, this method compares term 0 with term 1, term 1 with term 2, term 2 with term 3, and so on. This method returns true if the comparison holds between each adjacent pair of terms.
If a term is a variable, this method uses the term's ground value in the comparison.
depth - the depth at which to print trace informationprotected void cleanup()
|
by Steve Metsker | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||