Class PrologReasoner

java.lang.Object
nl.uu.cs.aplib.agents.PrologReasoner

public class PrologReasoner extends Object
Provide a Prolog-engine where you can add facts and rules, and perform queries/inference over those facts.
Author:
Wish.
  • Field Details

    • prolog

      public alice.tuprolog.Prolog prolog
  • Constructor Details

    • PrologReasoner

      public PrologReasoner()
  • Method Details

    • rule

      public static PrologReasoner.Rule rule(String head)
      Construct a representation of a prolog-rule consisting of just the head, and empty body. So, it has the form "head :- ".
    • predicate

      public static PrologReasoner.PredicateName predicate(String name)
      Construct a predicate name, e.g. "P". This can be combined with arguments to construct a string representing a predicate, e.g. as in: predicate("P").on("X","Y")
    • not

      public static String not(String t)
      Construct a string representing the prolog-term "not(t)".
    • or

      public static String or(String... args)
      Construct a string representing the prolog-term "(t1; t2; ...)", which denotes the disjunction of the composing terms.
    • and

      public static String and(String... args)
      Construct a string representing the prolog-term "(t1,t2,...)"; it denotes the conjunction of the composing terms.
    • facts

      public PrologReasoner facts(String... facts) throws alice.tuprolog.InvalidTheoryException
      Add new facts to the Prolog engine.
      Throws:
      alice.tuprolog.InvalidTheoryException
    • removeFacts

      public PrologReasoner removeFacts(String... facts) throws alice.tuprolog.InvalidTheoryException
      Remove facts from the Prolog engine.
      Throws:
      alice.tuprolog.InvalidTheoryException
    • add

      public PrologReasoner add(PrologReasoner.Rule... rules) throws alice.tuprolog.InvalidTheoryException
      Add new rules to the Prolog engine.
      Throws:
      alice.tuprolog.InvalidTheoryException
    • query

      public PrologReasoner.QueryResult query(String queryterm)
      Pose a query to the prolog-engine.
    • queryAll

      public List<PrologReasoner.QueryResult> queryAll(String queryterm)
    • test

      public boolean test(String queryterm)
      Check if the given query would return a result. If it does, this method returns true, and else false.
    • intval

      public static int intval(alice.tuprolog.Term t)
    • stringval

      public static String stringval(alice.tuprolog.Term t)
    • showTheory

      public String showTheory()
    • saveTheory

      public void saveTheory(String filename) throws IOException
      Save the current set of facts and rules to a file, which can be re-loaded later.
      Throws:
      IOException
    • loadTheory

      public void loadTheory(String filename) throws IOException, alice.tuprolog.InvalidTheoryException
      Clear the current theory, and replace it with a theory loaded form the specified file.
      Throws:
      IOException
      alice.tuprolog.InvalidTheoryException
    • main

      public static void main(String[] args) throws alice.tuprolog.InvalidTheoryException, IOException
      Throws:
      alice.tuprolog.InvalidTheoryException
      IOException