Class DynamicUserDefinedPredicateFactory
- java.lang.Object
-
- org.projog.core.predicate.udp.DynamicUserDefinedPredicateFactory
-
- All Implemented Interfaces:
PredicateFactory,UserDefinedPredicateFactory
public final class DynamicUserDefinedPredicateFactory extends java.lang.Object implements UserDefinedPredicateFactory
Maintains a record of the clauses that represents a "dynamic" user defined predicate.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/1andretract/1predicates.- See Also:
InterpretedUserDefinedPredicate
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classDynamicUserDefinedPredicateFactory.ClauseActionIteratorprivate static classDynamicUserDefinedPredicateFactory.ClauseActionMetaDataprivate classDynamicUserDefinedPredicateFactory.ImplicationsIterator
-
Field Summary
Fields Modifier and Type Field Description private DynamicUserDefinedPredicateFactory.ClauseActionMetaData[]endsprivate static intFIRSTprivate booleanhasPrimaryKeyprivate java.util.concurrent.ConcurrentHashMap<Term,DynamicUserDefinedPredicateFactory.ClauseActionMetaData>indexprivate KnowledgeBasekbprivate static intLASTprivate java.lang.ObjectLOCKprivate SpyPoints.SpyPointspyPoint
-
Constructor Summary
Constructors Constructor Description DynamicUserDefinedPredicateFactory(KnowledgeBase kb, PredicateKey predicateKey)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFirst(ClauseModel clauseModel)Adds a clause to the beginning of the predicate's list of clauses.voidaddLast(ClauseModel clauseModel)Adds a clause to the end of the predicate's list of clauses.private voidaddToIndex(ClauseModel clauseModel, DynamicUserDefinedPredicateFactory.ClauseActionMetaData metaData)private DynamicUserDefinedPredicateFactory.ClauseActionMetaDatacreateClauseActionMetaData(ClauseModel clauseModel)ClauseModelgetClauseModel(int index)Returns the clause at the specified position in this predicate's list of clauses.java.util.Iterator<ClauseModel>getImplications()Returns an iterator over the clauses of this user defined predicate.PredicategetPredicate(Term[] args)Returns aPredicateto be used in the evaluation of a goal.PredicateKeygetPredicateKey()Returns the key for the predicate this object representsbooleanisDynamic()Returnstrueis this predicate is dynamic.booleanisRetryable()Should instances of this implementation be re-evaluated when backtracking?-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.projog.core.predicate.PredicateFactory
isAlwaysCutOnBacktrack
-
-
-
-
Field Detail
-
FIRST
private static final int FIRST
- See Also:
- Constant Field Values
-
LAST
private static final int LAST
- See Also:
- Constant Field Values
-
LOCK
private final java.lang.Object LOCK
-
kb
private final KnowledgeBase kb
-
spyPoint
private final SpyPoints.SpyPoint spyPoint
-
ends
private final DynamicUserDefinedPredicateFactory.ClauseActionMetaData[] ends
-
index
private java.util.concurrent.ConcurrentHashMap<Term,DynamicUserDefinedPredicateFactory.ClauseActionMetaData> index
-
hasPrimaryKey
private boolean hasPrimaryKey
-
-
Constructor Detail
-
DynamicUserDefinedPredicateFactory
public DynamicUserDefinedPredicateFactory(KnowledgeBase kb, PredicateKey predicateKey)
-
-
Method Detail
-
getPredicate
public Predicate getPredicate(Term[] args)
Description copied from interface:PredicateFactoryReturns aPredicateto be used in the evaluation of a goal.- Specified by:
getPredicatein interfacePredicateFactory- Parameters:
args- the arguments to use in the evaluation of the goal- Returns:
- Predicate to be used in the evaluation of the goal
- See Also:
Predicate.evaluate()
-
getPredicateKey
public PredicateKey getPredicateKey()
Description copied from interface:UserDefinedPredicateFactoryReturns the key for the predicate this object represents- Specified by:
getPredicateKeyin interfaceUserDefinedPredicateFactory- Returns:
- the key for the predicate this object represents
-
isDynamic
public boolean isDynamic()
Description copied from interface:UserDefinedPredicateFactoryReturnstrueis this predicate is dynamic.A "dynamic" predicate is a user defined predicate that can have clauses added or removed after is first defined.
- Specified by:
isDynamicin interfaceUserDefinedPredicateFactory- Returns:
trueis this predicate is dynamic
-
getImplications
public java.util.Iterator<ClauseModel> getImplications()
Returns an iterator over the clauses of this user defined predicate.The iterator returned will have the following characteristics:
- Calls to
Iterator.next()return a new copy of theClauseModelto avoid the original being altered. - Calls to
Iterator.remove()do alter the underlying structure of this user defined predicate.
- Specified by:
getImplicationsin interfaceUserDefinedPredicateFactory- Returns:
- an iterator over the clauses in the predicate in proper sequence.
- Calls to
-
addFirst
public void addFirst(ClauseModel clauseModel)
Description copied from interface:UserDefinedPredicateFactoryAdds a clause to the beginning of the predicate's list of clauses.- Specified by:
addFirstin interfaceUserDefinedPredicateFactory- Parameters:
clauseModel- the clause to add to the beginning of the predicate
-
addLast
public void addLast(ClauseModel clauseModel)
Description copied from interface:UserDefinedPredicateFactoryAdds a clause to the end of the predicate's list of clauses.- Specified by:
addLastin interfaceUserDefinedPredicateFactory- Parameters:
clauseModel- the clause to add to the end of the predicate
-
addToIndex
private void addToIndex(ClauseModel clauseModel, DynamicUserDefinedPredicateFactory.ClauseActionMetaData metaData)
-
getClauseModel
public ClauseModel getClauseModel(int index)
Description copied from interface:UserDefinedPredicateFactoryReturns the clause at the specified position in this predicate's list of clauses.- Specified by:
getClauseModelin interfaceUserDefinedPredicateFactory- Parameters:
index- index of the clause to return- Returns:
- the clause at the specified position in this predicate's list of clauses or
nullif out of bounds
-
createClauseActionMetaData
private DynamicUserDefinedPredicateFactory.ClauseActionMetaData createClauseActionMetaData(ClauseModel clauseModel)
-
isRetryable
public boolean isRetryable()
Description copied from interface:PredicateFactoryShould instances of this implementation be re-evaluated when backtracking?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 ofPredicatethat are designed to possibly havePredicate.evaluate()called on them multiple times for the same individual query this method should returntrue. For instances ofPredicatethat are designed to only be evaluated once per individual query this method should returnfalse.- Specified by:
isRetryablein interfacePredicateFactory- Returns:
trueif an attempt should be made to re-evaluate instances of implementing classes when backtracking,falseotherwise
-
-