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, wait
isAlwaysCutOnBacktrack
public 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 UserDefinedPredicateFactory
clauseModel
- the clause to add to the beginning of the predicateProjogException
public 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 UserDefinedPredicateFactory
clauseModel
- 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)
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 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 UnsupportedOperationException
getImplications
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 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
otherwisepublic PredicateFactory preprocess(Term arg)
preprocess
in interface PreprocessablePredicateFactory
Copyright © 2024. All rights reserved.