Class DynamicUserDefinedPredicateFactory

java.lang.Object
org.projog.core.predicate.udp.DynamicUserDefinedPredicateFactory
All Implemented Interfaces:
PredicateFactory, UserDefinedPredicateFactory

public final class DynamicUserDefinedPredicateFactory extends 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/1 and retract/1 predicates.

See Also:
  • Constructor Details

    • DynamicUserDefinedPredicateFactory

      public DynamicUserDefinedPredicateFactory(KnowledgeBase kb, PredicateKey predicateKey)
  • Method Details

    • getPredicate

      public Predicate getPredicate(Term term)
      Description copied from interface: PredicateFactory
      Returns a Predicate to be used in the evaluation of a goal.
      Specified by:
      getPredicate in interface PredicateFactory
      Parameters:
      term - the term containing the arguments to use in the evaluation of the goal
      Returns:
      Predicate to be used in the evaluation of the goal
      See Also:
    • getPredicateKey

      public PredicateKey getPredicateKey()
      Description copied from interface: UserDefinedPredicateFactory
      Returns the key for the predicate this object represents
      Specified by:
      getPredicateKey in interface UserDefinedPredicateFactory
      Returns:
      the key for the predicate this object represents
    • isDynamic

      public boolean isDynamic()
      Description copied from interface: UserDefinedPredicateFactory
      Returns 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.

      Specified by:
      isDynamic in interface UserDefinedPredicateFactory
      Returns:
      true is this predicate is dynamic
    • isRetryable

      public boolean isRetryable()
      Description copied from interface: PredicateFactory
      Should 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 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.

      Specified by:
      isRetryable in interface PredicateFactory
      Returns:
      true if an attempt should be made to re-evaluate instances of implementing classes when backtracking, false otherwise
    • compile

      public void compile()
      Specified by:
      compile in interface UserDefinedPredicateFactory
    • getImplications

      public Iterator<ClauseModel> getImplications()
      Returns an iterator over the clauses of this user defined predicate.

      The iterator returned will have the following characteristics:

      Specified by:
      getImplications in interface UserDefinedPredicateFactory
      Returns:
      an iterator over the clauses in the predicate in proper sequence.
    • addFirst

      public void addFirst(ClauseModel clauseModel)
      Description copied from interface: UserDefinedPredicateFactory
      Adds a clause to the beginning of the predicate's list of clauses.
      Specified by:
      addFirst in interface UserDefinedPredicateFactory
      Parameters:
      clauseModel - the clause to add to the beginning of the predicate
    • addLast

      public void addLast(ClauseModel clauseModel)
      Description copied from interface: UserDefinedPredicateFactory
      Adds a clause to the end of the predicate's list of clauses.
      Specified by:
      addLast in interface UserDefinedPredicateFactory
      Parameters:
      clauseModel - the clause to add to the end of the predicate
    • getClauseModel

      public ClauseModel getClauseModel(int index)
      Description copied from interface: UserDefinedPredicateFactory
      Returns the clause at the specified position in this predicate's list of clauses.
      Specified by:
      getClauseModel in interface UserDefinedPredicateFactory
      Parameters:
      index - index of the clause to return
      Returns:
      the clause at the specified position in this predicate's list of clauses or null if out of bounds