Package nl.uu.cs.aplib.agents
Class PrologReasoner
java.lang.Object
nl.uu.cs.aplib.agents.PrologReasoner
Provide a Prolog-engine where you can add facts and rules, and perform
queries/inference over those facts.
- Author:
- Wish.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A representation of a predicate-name.static class
Representing the result of a Prolog-query.static class
A represenration of a Prolog-rule. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(PrologReasoner.Rule... rules)
Add new rules to the Prolog engine.static String
Construct a string representing the prolog-term "(t1,t2,...)"; it denotes the conjunction of the composing terms.Add new facts to the Prolog engine.static int
intval(alice.tuprolog.Term t)
void
loadTheory(String filename)
Clear the current theory, and replace it with a theory loaded form the specified file.static void
static String
Construct a string representing the prolog-term "not(t)".static String
Construct a string representing the prolog-term "(t1; t2; ...)", which denotes the disjunction of the composing terms.static PrologReasoner.PredicateName
Construct a predicate name, e.g.Pose a query to the prolog-engine.removeFacts(String... facts)
Remove facts from the Prolog engine.static PrologReasoner.Rule
Construct a representation of a prolog-rule consisting of just the head, and empty body.void
saveTheory(String filename)
Save the current set of facts and rules to a file, which can be re-loaded later.static String
stringval(alice.tuprolog.Term t)
boolean
Check if the given query would return a result.
-
Field Details
-
prolog
public alice.tuprolog.Prolog prolog
-
-
Constructor Details
-
PrologReasoner
public PrologReasoner()
-
-
Method Details
-
rule
Construct a representation of a prolog-rule consisting of just the head, and empty body. So, it has the form "head :- ". -
predicate
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
Construct a string representing the prolog-term "not(t)". -
or
Construct a string representing the prolog-term "(t1; t2; ...)", which denotes the disjunction of the composing terms. -
and
Construct a string representing the prolog-term "(t1,t2,...)"; it denotes the conjunction of the composing terms. -
facts
Add new facts to the Prolog engine.- Throws:
alice.tuprolog.InvalidTheoryException
-
removeFacts
Remove facts from the Prolog engine.- Throws:
alice.tuprolog.InvalidTheoryException
-
add
public PrologReasoner add(PrologReasoner.Rule... rules) throws alice.tuprolog.InvalidTheoryExceptionAdd new rules to the Prolog engine.- Throws:
alice.tuprolog.InvalidTheoryException
-
query
Pose a query to the prolog-engine. -
queryAll
-
test
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
-
showTheory
-
saveTheory
Save the current set of facts and rules to a file, which can be re-loaded later.- Throws:
IOException
-
loadTheory
Clear the current theory, and replace it with a theory loaded form the specified file.- Throws:
IOException
alice.tuprolog.InvalidTheoryException
-
main
- Throws:
alice.tuprolog.InvalidTheoryException
IOException
-