Package org.projog.core.kb
Class KnowledgeBaseUtils
- java.lang.Object
-
- org.projog.core.kb.KnowledgeBaseUtils
-
public final class KnowledgeBaseUtils extends java.lang.ObjectHelper methods for performing common tasks onKnowledgeBaseinstances.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCONJUNCTION_PREDICATE_NAMEThe functor of structures representing conjunctions (,).static java.lang.StringIMPLICATION_PREDICATE_NAMEThe functor of structures representing implications (:-).static java.lang.StringQUESTION_PREDICATE_NAMEThe functor of structures representing questions (i.e.
-
Constructor Summary
Constructors Modifier Constructor Description privateKnowledgeBaseUtils()Private constructor as all methods are static.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidbootstrap(KnowledgeBase kb)Consults theProjogProperties.getBootstrapScript()for theKnowledgeBase.static KnowledgeBasecreateKnowledgeBase()Constructs a newKnowledgeBaseobject usingProjogDefaultPropertiesstatic KnowledgeBasecreateKnowledgeBase(ProjogProperties projogProperties)Constructs a newKnowledgeBaseobject using the specifiedProjogPropertiesstatic java.util.List<PredicateKey>getPredicateKeysByName(KnowledgeBase kb, java.lang.String predicateName)Returns list of all user defined predicates with the specified name.private static <T> Tinstantiate(java.lang.String input)static <T> Tinstantiate(KnowledgeBase knowledgeBase, java.lang.String input)Returns a new object created using reflection.static booleanisConjunction(Term t)static booleanisQuestionOrDirectiveFunctionCall(Term t)static booleanisSingleAnswer(KnowledgeBase kb, Term term)Returnstrueif the predicate represented by the specifiedTermnever succeeds on re-evaluation.static Term[]toArrayOfConjunctions(Term t)
-
-
-
Field Detail
-
CONJUNCTION_PREDICATE_NAME
public static final java.lang.String CONJUNCTION_PREDICATE_NAME
The functor of structures representing conjunctions (,).- See Also:
- Constant Field Values
-
IMPLICATION_PREDICATE_NAME
public static final java.lang.String IMPLICATION_PREDICATE_NAME
The functor of structures representing implications (:-).- See Also:
- Constant Field Values
-
QUESTION_PREDICATE_NAME
public static final java.lang.String QUESTION_PREDICATE_NAME
The functor of structures representing questions (i.e. queries) (?-).- See Also:
- Constant Field Values
-
-
Method Detail
-
createKnowledgeBase
public static KnowledgeBase createKnowledgeBase()
Constructs a newKnowledgeBaseobject usingProjogDefaultProperties
-
createKnowledgeBase
public static KnowledgeBase createKnowledgeBase(ProjogProperties projogProperties)
Constructs a newKnowledgeBaseobject using the specifiedProjogProperties
-
bootstrap
public static void bootstrap(KnowledgeBase kb)
Consults theProjogProperties.getBootstrapScript()for theKnowledgeBase.This is a way to configure a new
KnowledgeBase(i.e. plugging inArithmeticOperatorandPredicateFactoryinstances).When using
ProjogDefaultPropertiesthe resource parsed will beprojog-bootstrap.pl(contained inprojog-core.jar).
-
getPredicateKeysByName
public static java.util.List<PredicateKey> getPredicateKeysByName(KnowledgeBase kb, java.lang.String predicateName)
Returns list of all user defined predicates with the specified name.
-
isQuestionOrDirectiveFunctionCall
public static boolean isQuestionOrDirectiveFunctionCall(Term t)
Returnstrueif the specifiedTermrepresents a question or directive, elsefalse.A
Termis judged to represent a question if it is a structure a single argument and with a functorQUESTION_PREDICATE_NAMEorIMPLICATION_PREDICATE_NAME.
-
isSingleAnswer
public static boolean isSingleAnswer(KnowledgeBase kb, Term term)
Returnstrueif the predicate represented by the specifiedTermnever succeeds on re-evaluation.
-
isConjunction
public static boolean isConjunction(Term t)
Returnstrueif the specifiedTermrepresent a conjunction, elsefalse.A
Termis judged to represent a conjunction if is a structure with a functor ofCONJUNCTION_PREDICATE_NAMEand exactly two arguments.
-
instantiate
public static <T> T instantiate(KnowledgeBase knowledgeBase, java.lang.String input) throws java.lang.ReflectiveOperationException
Returns a new object created using reflection.The
inputparameter can be in one of two formats:- The class name - e.g.
java.lang.String- this will cause an attempt to create a new instance of the specified class using its no argument constructor. - The class name and a method name (separated by a
/) - e.g.java.util.Calendar/getInstance- this will cause an attempt to create a new instance of the class by invoking the specified method (as a no argument static method) of the specified class.
- Throws:
java.lang.ReflectiveOperationException
- The class name - e.g.
-
instantiate
private static <T> T instantiate(java.lang.String input) throws java.lang.ReflectiveOperationException- Throws:
java.lang.ReflectiveOperationException
-
-