Class Predicates


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

      • javaPredicateClassNames

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

        private final java.util.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 java.util.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)).

    • Method Detail

      • getAllDefinedPredicateKeys

        public java.util.Set<PredicateKey> getAllDefinedPredicateKeys()
        Returns details of all predicates, both user-defined and built-in predicates.
      • 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
      • 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.

      • instantiatePredicateFactory

        private PredicateFactory instantiatePredicateFactory​(java.lang.String className)
      • addPredicateFactory

        public void addPredicateFactory​(PredicateKey key,
                                        java.lang.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)