Class KnowledgeBaseUtils


  • public final class KnowledgeBaseUtils
    extends java.lang.Object
    Helper methods for performing common tasks on KnowledgeBase instances.
    • 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
    • Constructor Detail

      • KnowledgeBaseUtils

        private KnowledgeBaseUtils()
        Private constructor as all methods are static.
    • Method Detail

      • 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)
        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 knowledgeBase,
                                        java.lang.String input)
                                 throws java.lang.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:
        java.lang.ReflectiveOperationException
      • instantiate

        private static <T> T instantiate​(java.lang.String input)
                                  throws java.lang.ReflectiveOperationException
        Throws:
        java.lang.ReflectiveOperationException