Class Predicates
- java.lang.Object
-
- org.projog.core.predicate.Predicates
-
public class Predicates extends java.lang.ObjectActs as a repository of rules and facts.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<PredicateKey,java.lang.String>javaPredicateClassNamesThe class names of "built-in" Java predicates (i.e.private java.util.Map<PredicateKey,PredicateFactory>javaPredicateInstancesThe instances of "built-in" Java predicates (i.e.private KnowledgeBasekbprivate java.lang.ObjectpredicatesLockUsed to coordinate access tojavaPredicateClassNames,javaPredicateInstancesanduserDefinedPredicatesprivate java.util.Map<PredicateKey,UserDefinedPredicateFactory>userDefinedPredicatesThe user-defined predicates (i.e.
-
Constructor Summary
Constructors Constructor Description Predicates(KnowledgeBase kb)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPredicateFactory(PredicateKey key, java.lang.String predicateFactoryClassName)Associates aPredicateFactorywith thisKnowledgeBase.voidaddPredicateFactory(PredicateKey key, PredicateFactory predicateFactory)Associates aPredicateFactorywith thisKnowledgeBase.voidaddUserDefinedPredicate(UserDefinedPredicateFactory userDefinedPredicate)Adds a user defined predicate to this object.UserDefinedPredicateFactorycreateOrReturnUserDefinedPredicate(PredicateKey key)Returns theUserDefinedPredicateFactoryfor the specifiedPredicateKey.java.util.Set<PredicateKey>getAllDefinedPredicateKeys()Returns details of all predicates, both user-defined and built-in predicates.private PredicateFactorygetExistingPredicateFactory(PredicateKey key)PredicategetPredicate(Term t)PredicateFactorygetPredicateFactory(PredicateKey key)Returns thePredicateFactoryassociated with the specifiedPredicateKey.PredicateFactorygetPredicateFactory(Term term)Returns thePredicateFactoryassociated with the specifiedTerm.PredicateFactorygetPreprocessedPredicateFactory(Term term)java.util.Map<PredicateKey,UserDefinedPredicateFactory>getUserDefinedPredicates()Returns details of all the user define predicates of this object.private PredicateFactoryinstantiatePredicateFactory(java.lang.String className)private PredicateFactoryinstantiatePredicateFactory(PredicateKey key)private booleanisExistingJavaPredicate(PredicateKey key)private booleanisExistingPredicate(PredicateKey key)private booleanisExistingUserDefinedPredicate(PredicateKey key)private PredicateFactoryunknownPredicate(PredicateKey key)private voidupdateExistingPredicate(PredicateKey key, UserDefinedPredicateFactory userDefinedPredicate)
-
-
-
Field Detail
-
predicatesLock
private final java.lang.Object predicatesLock
Used to coordinate access tojavaPredicateClassNames,javaPredicateInstancesanduserDefinedPredicates
-
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 thisKnowledgeBase.
-
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 thisKnowledgeBase.
-
userDefinedPredicates
private final java.util.Map<PredicateKey,UserDefinedPredicateFactory> userDefinedPredicates
The user-defined predicates (i.e. defined using Prolog syntax) associated with thisKnowledgeBase.Uses TreeMap to enforce predictable ordering for when iterated (e.g. by
listing(X)).
-
kb
private final KnowledgeBase kb
-
-
Constructor Detail
-
Predicates
public Predicates(KnowledgeBase kb)
-
-
Method Detail
-
getAllDefinedPredicateKeys
public java.util.Set<PredicateKey> getAllDefinedPredicateKeys()
Returns details of all predicates, both user-defined and built-in predicates.
-
getUserDefinedPredicates
public java.util.Map<PredicateKey,UserDefinedPredicateFactory> getUserDefinedPredicates()
Returns details of all the user define predicates of this object.
-
createOrReturnUserDefinedPredicate
public UserDefinedPredicateFactory createOrReturnUserDefinedPredicate(PredicateKey key)
Returns theUserDefinedPredicateFactoryfor the specifiedPredicateKey.If this object does not already have a
UserDefinedPredicateFactoryfor the specifiedPredicateKeythen it will create it.- Throws:
ProjogException- if the specifiedPredicateKeyrepresents an existing "plugin" predicate
-
addUserDefinedPredicate
public void addUserDefinedPredicate(UserDefinedPredicateFactory userDefinedPredicate)
Adds a user defined predicate to this object.Any existing
UserDefinedPredicateFactorywith the samePredicateKeywill be replaced.- Throws:
ProjogException- if thePredicateKeyof the specifiedUserDefinedPredicateFactoryrepresents 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 thePredicateFactoryassociated with the specifiedTerm.If this object has no
PredicateFactoryassociated with thePredicateKeyof the specifiedTermthen a new instance ofUnknownPredicateis returned.
-
getPredicateFactory
public PredicateFactory getPredicateFactory(PredicateKey key)
Returns thePredicateFactoryassociated with the specifiedPredicateKey.If this object has no
PredicateFactoryassociated with the specifiedPredicateKeythen a new instance ofUnknownPredicateis returned.
-
getExistingPredicateFactory
private PredicateFactory getExistingPredicateFactory(PredicateKey key)
-
instantiatePredicateFactory
private PredicateFactory instantiatePredicateFactory(PredicateKey key)
-
instantiatePredicateFactory
private PredicateFactory instantiatePredicateFactory(java.lang.String className)
-
unknownPredicate
private PredicateFactory unknownPredicate(PredicateKey key)
-
addPredicateFactory
public void addPredicateFactory(PredicateKey key, java.lang.String predicateFactoryClassName)
Associates aPredicateFactorywith thisKnowledgeBase.This method provides a mechanism for "plugging in" or "injecting" implementations of
PredicateFactoryat 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 thePredicateFactorywith.predicateFactoryClassName- The name of a class that implementsPredicateFactory.- Throws:
ProjogException- if there is already aPredicateFactoryassociated with thePredicateKey
-
addPredicateFactory
public void addPredicateFactory(PredicateKey key, PredicateFactory predicateFactory)
Associates aPredicateFactorywith thisKnowledgeBase.This method provides a mechanism for "plugging in" or "injecting" implementations of
PredicateFactoryat 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 thePredicateFactorywith.predicateFactory- ThePredicateFactoryto be added.- Throws:
ProjogException- if there is already aPredicateFactoryassociated with thePredicateKey
-
isExistingPredicate
private boolean isExistingPredicate(PredicateKey key)
-
isExistingJavaPredicate
private boolean isExistingJavaPredicate(PredicateKey key)
-
isExistingUserDefinedPredicate
private boolean isExistingUserDefinedPredicate(PredicateKey key)
-
-