Class Predicates

java.lang.Object
org.projog.core.predicate.Predicates

public class Predicates extends Object
Acts as a repository of rules and facts.
  • Field Details

    • predicatesLock

      private final Object predicatesLock
    • javaPredicateClassNames

      private final Map<PredicateKey, String> javaPredicateClassNames
      The class names of "built-in" Java predicates (i.e. not defined using Prolog syntax) associated with this KnowledgeBase.
    • javaPredicateInstances

      private final Map<PredicateKey, PredicateFactory> javaPredicateInstances
      The instances of "built-in" Java predicates (i.e. not defined using Prolog syntax) associated with this KnowledgeBase.
    • userDefinedPredicates

      private final Map<PredicateKey, UserDefinedPredicateFactory> userDefinedPredicates
      The user-defined predicates (i.e. defined using Prolog syntax) associated with this KnowledgeBase.

      Uses TreeMap to enforce predictable ordering for when iterated (e.g. by listing(X)).

    • kb

      private final KnowledgeBase kb
  • Constructor Details

  • Method Details

    • getPredicate

      public Predicate getPredicate(Term t)
    • getAllDefinedPredicateKeys

      public Set<PredicateKey> getAllDefinedPredicateKeys()
      Returns details of all predicates, both user-defined and built-in predicates.
    • getUserDefinedPredicates

      public Map<PredicateKey, UserDefinedPredicateFactory> getUserDefinedPredicates()
      Returns details of all the user define predicates of this object.
    • createOrReturnUserDefinedPredicate

      public UserDefinedPredicateFactory createOrReturnUserDefinedPredicate(PredicateKey key)
      Returns the UserDefinedPredicateFactory for the specified PredicateKey.

      If this object does not already have a UserDefinedPredicateFactory for the specified PredicateKey then it will create it.

      Throws:
      ProjogException - if the specified PredicateKey represents an existing "plugin" predicate
    • addUserDefinedPredicate

      public void addUserDefinedPredicate(UserDefinedPredicateFactory userDefinedPredicate)
      Adds a user defined predicate to this object.

      Any existing UserDefinedPredicateFactory with the same PredicateKey will be replaced.

      Throws:
      ProjogException - if the PredicateKey of the specified UserDefinedPredicateFactory represents an existing "plugin" predicate
    • updateExistingPredicate

      private void updateExistingPredicate(PredicateKey key, UserDefinedPredicateFactory userDefinedPredicate)
    • getPreprocessedPredicateFactory

      public PredicateFactory getPreprocessedPredicateFactory(Term term)
    • getPredicateFactory

      public PredicateFactory getPredicateFactory(Term term)
      Returns the PredicateFactory associated with the specified Term.

      If this object has no PredicateFactory associated with the PredicateKey of the specified Term then a new instance of UnknownPredicate is returned.

    • getPredicateFactory

      public PredicateFactory getPredicateFactory(PredicateKey key)
      Returns the PredicateFactory associated with the specified PredicateKey.

      If this object has no PredicateFactory associated with the specified PredicateKey then a new instance of UnknownPredicate is returned.

    • getExistingPredicateFactory

      private PredicateFactory getExistingPredicateFactory(PredicateKey key)
    • instantiatePredicateFactory

      private PredicateFactory instantiatePredicateFactory(PredicateKey key)
    • instantiatePredicateFactory

      private PredicateFactory instantiatePredicateFactory(String className)
    • unknownPredicate

      private PredicateFactory unknownPredicate(PredicateKey key)
    • addPredicateFactory

      public void addPredicateFactory(PredicateKey key, String predicateFactoryClassName)
      Associates a PredicateFactory with this KnowledgeBase.

      This method provides a mechanism for "plugging in" or "injecting" implementations of PredicateFactory at runtime. This mechanism provides an easy way to configure and extend the functionality of Projog - including adding functionality not possible to define in pure Prolog syntax.

      Parameters:
      key - The name and arity to associate the PredicateFactory with.
      predicateFactoryClassName - The name of a class that implements PredicateFactory.
      Throws:
      ProjogException - if there is already a PredicateFactory associated with the PredicateKey
    • addPredicateFactory

      public void addPredicateFactory(PredicateKey key, PredicateFactory predicateFactory)
      Associates a PredicateFactory with this KnowledgeBase.

      This method provides a mechanism for "plugging in" or "injecting" implementations of PredicateFactory at runtime. This mechanism provides an easy way to configure and extend the functionality of Projog - including adding functionality not possible to define in pure Prolog syntax.

      Parameters:
      key - The name and arity to associate the PredicateFactory with.
      predicateFactory - The PredicateFactory to be added.
      Throws:
      ProjogException - if there is already a PredicateFactory associated with the PredicateKey
    • isExistingPredicate

      private boolean isExistingPredicate(PredicateKey key)
    • isExistingJavaPredicate

      private boolean isExistingJavaPredicate(PredicateKey key)
    • isExistingUserDefinedPredicate

      private boolean isExistingUserDefinedPredicate(PredicateKey key)