public final class DynamicUserDefinedPredicateFactory extends Object implements UserDefinedPredicateFactory
A "dynamic" user defined predicate is one that can have clauses added and removed after it has been first
defined. This is normally done using the asserta/1
, assertz/1
and retract/1
predicates.
InterpretedUserDefinedPredicate
Constructor and Description |
---|
DynamicUserDefinedPredicateFactory(KnowledgeBase kb,
PredicateKey predicateKey) |
Modifier and Type | Method and Description |
---|---|
void |
addFirst(ClauseModel clauseModel)
Adds a clause to the beginning of the predicate's list of clauses.
|
void |
addLast(ClauseModel clauseModel)
Adds a clause to the end of the predicate's list of clauses.
|
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?
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
isAlwaysCutOnBacktrack
public DynamicUserDefinedPredicateFactory(KnowledgeBase kb, PredicateKey predicateKey)
public Predicate getPredicate(Term[] args)
PredicateFactory
Predicate
to be used in the evaluation of a goal.getPredicate
in interface PredicateFactory
args
- the arguments to use in the evaluation of the goalPredicate.evaluate()
public PredicateKey getPredicateKey()
UserDefinedPredicateFactory
getPredicateKey
in interface UserDefinedPredicateFactory
public boolean isDynamic()
UserDefinedPredicateFactory
true
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 UserDefinedPredicateFactory
true
is this predicate is dynamicpublic Iterator<ClauseModel> getImplications()
The iterator returned will have the following characteristics:
Iterator.next()
return a new copy of the ClauseModel
to avoid the
original being altered.Iterator.remove()
do alter the underlying structure of this user defined
predicate.getImplications
in interface UserDefinedPredicateFactory
public void addFirst(ClauseModel clauseModel)
UserDefinedPredicateFactory
addFirst
in interface UserDefinedPredicateFactory
clauseModel
- the clause to add to the beginning of the predicatepublic void addLast(ClauseModel clauseModel)
UserDefinedPredicateFactory
addLast
in interface UserDefinedPredicateFactory
clauseModel
- the clause to add to the end of the predicatepublic ClauseModel getClauseModel(int index)
UserDefinedPredicateFactory
getClauseModel
in interface UserDefinedPredicateFactory
index
- 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 PredicateFactory
true
if an attempt should be made to re-evaluate instances of implementing classes when
backtracking, false
otherwiseCopyright © 2024. All rights reserved.