Class KnowledgeBaseUtils

java.lang.Object
org.projog.core.kb.KnowledgeBaseUtils

public final class KnowledgeBaseUtils extends Object
Helper methods for performing common tasks on KnowledgeBase instances.
  • Field Details

    • CONJUNCTION_PREDICATE_NAME

      public static final String CONJUNCTION_PREDICATE_NAME
      The functor of structures representing conjunctions (,).
      See Also:
    • IMPLICATION_PREDICATE_NAME

      public static final String IMPLICATION_PREDICATE_NAME
      The functor of structures representing implications (:-).
      See Also:
    • QUESTION_PREDICATE_NAME

      public static final String QUESTION_PREDICATE_NAME
      The functor of structures representing questions (i.e. queries) (?-).
      See Also:
  • Method Details

    • createKnowledgeBase

      public static KnowledgeBase createKnowledgeBase()
      Constructs a new KnowledgeBase object using ProjogDefaultProperties
    • createKnowledgeBase

      public static KnowledgeBase createKnowledgeBase(ProjogProperties projogProperties)
      Constructs a new KnowledgeBase object using the specified ProjogProperties
    • bootstrap

      public static void bootstrap(KnowledgeBase kb)
      Consults the ProjogProperties.getBootstrapScript() for the KnowledgeBase.

      This is a way to configure a new KnowledgeBase (i.e. plugging in ArithmeticOperator and PredicateFactory instances).

      When using ProjogDefaultProperties the resource parsed will be projog-bootstrap.pl (contained in projog-core.jar).

      See Also:
    • getPredicateKeysByName

      public static List<PredicateKey> getPredicateKeysByName(KnowledgeBase kb, String predicateName)
      Returns list of all user defined predicates with the specified name.
    • isQuestionOrDirectiveFunctionCall

      public static boolean isQuestionOrDirectiveFunctionCall(Term t)
      Returns true if the specified Term represents a question or directive, else false.

      A Term is judged to represent a question if it is a structure a single argument and with a functor QUESTION_PREDICATE_NAME or IMPLICATION_PREDICATE_NAME.

    • isSingleAnswer

      public static boolean isSingleAnswer(KnowledgeBase kb, Term term)
      Returns true if the predicate represented by the specified Term never succeeds on re-evaluation.
    • toArrayOfConjunctions

      public static Term[] toArrayOfConjunctions(Term t)
      Returns an array of all Terms that make up the conjunction represented by the specified Term.

      If the specified Term does not represent a conjunction then it will be used as the only element in the returned array.

    • isConjunction

      public static boolean isConjunction(Term t)
      Returns true if the specified Term represent a conjunction, else false.

      A Term is judged to represent a conjunction if is a structure with a functor of CONJUNCTION_PREDICATE_NAME and exactly two arguments.

    • instantiate

      public static <T> T instantiate(KnowledgeBase kb, String input) throws ReflectiveOperationException
      Returns a new object created using reflection.

      The input parameter can be in one of two formats:

      1. 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.
      2. 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:
      ReflectiveOperationException
    • newInstance

      public static Object newInstance(KnowledgeBase kb, Class<?> c) throws ReflectiveOperationException
      Returns a new instance of the specified class.

      If the class has a constructor that takes a KnowledgeBase as its single argument then an attempt is made to use that to construct the new instance - else an attempt is made to construct a new instance using the no-arg constructor.

      Throws:
      ReflectiveOperationException