public class StaticUserDefinedPredicateFactory extends Object implements UserDefinedPredicateFactory, PreprocessablePredicateFactory
A "static" user defined predicate is one that can not have clauses added or removed after it is first defined.
| Constructor and Description |
|---|
StaticUserDefinedPredicateFactory(KnowledgeBase kb,
PredicateKey predicateKey) |
| Modifier and Type | Method and Description |
|---|---|
void |
addFirst(ClauseModel clauseModel)
Not supported.
|
void |
addLast(ClauseModel clauseModel)
Adds new clause to list of clauses for this predicate.
|
void |
compile() |
PredicateFactory |
getActualPredicateFactory() |
ClauseModel |
getClauseModel(int index)
Returns the clause at the specified position in this predicate's list of clauses.
|
Iterator<ClauseModel> |
getImplications()
Returns an iterator over the clauses of this user defined predicate.
|
Predicate |
getPredicate(Term[] args)
Returns a
Predicate to be used in the evaluation of a goal. |
PredicateKey |
getPredicateKey()
Returns the key for the predicate this object represents
|
boolean |
isDynamic()
Returns
true is this predicate is dynamic. |
boolean |
isRetryable()
Should instances of this implementation be re-evaluated when backtracking?
|
PredicateFactory |
preprocess(Term arg) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitisAlwaysCutOnBacktrackpublic StaticUserDefinedPredicateFactory(KnowledgeBase kb, PredicateKey predicateKey)
public void addFirst(ClauseModel clauseModel)
It is not possible to add a clause to the beginning of a static user defined predicate.
addFirst in interface UserDefinedPredicateFactoryclauseModel - the clause to add to the beginning of the predicateProjogExceptionpublic void addLast(ClauseModel clauseModel)
Note: it is not possible to add clauses to a static user defined predicate once it has been compiled.
addLast in interface UserDefinedPredicateFactoryclauseModel - the clause to add to the end of the predicateIllegalStateException - if the predicate has already been compiled.public void compile()
public Predicate getPredicate(Term[] args)
PredicateFactoryPredicate to be used in the evaluation of a goal.getPredicate in interface PredicateFactoryargs - the arguments to use in the evaluation of the goalPredicate.evaluate()public PredicateKey getPredicateKey()
UserDefinedPredicateFactorygetPredicateKey in interface UserDefinedPredicateFactorypublic PredicateFactory getActualPredicateFactory()
public Iterator<ClauseModel> getImplications()
The iterator returned will have the following characteristics which prevent the underlying structure of the user defined predicate being altered:
Iterator.next() return a new copy of the ClauseModel.Iterator.remove() cause a UnsupportedOperationExceptiongetImplications in interface UserDefinedPredicateFactorypublic boolean isDynamic()
UserDefinedPredicateFactorytrue is this predicate is dynamic.
A "dynamic" predicate is a user defined predicate that can have clauses added or removed after is first defined.
isDynamic in interface UserDefinedPredicateFactorytrue is this predicate is dynamicpublic ClauseModel getClauseModel(int index)
UserDefinedPredicateFactorygetClauseModel in interface UserDefinedPredicateFactoryindex - index of the clause to returnnull if out of boundspublic boolean isRetryable()
PredicateFactory
Some goals (e.g. X is 1) are only meant to be evaluated once (the statement is either true or false) while
others (e.g. repeat(3)) are meant to be evaluated multiple times. For instances of Predicate that
are designed to possibly have Predicate.evaluate() called on them multiple times for the same individual
query this method should return true. For instances of Predicate that are designed to only be
evaluated once per individual query this method should return false.
isRetryable in interface PredicateFactorytrue if an attempt should be made to re-evaluate instances of implementing classes when
backtracking, false otherwisepublic PredicateFactory preprocess(Term arg)
preprocess in interface PreprocessablePredicateFactoryCopyright © 2024. All rights reserved.