public final class Projog extends Object
Contains a single instance of KnowledgeBase
.
Constructor and Description |
---|
Projog(ProjogListener... listeners)
|
Projog(ProjogProperties projogProperties,
ProjogListener... listeners)
Constructs a new
Projog object with the specified ProjogProperties and ProjogListener s. |
Modifier and Type | Method and Description |
---|---|
void |
addArithmeticOperator(PredicateKey key,
ArithmeticOperator operator)
|
void |
addListener(ProjogListener listener)
Registers an
ProjogListener to receive notifications of events generated during the evaluation of Prolog
goals. |
void |
addPredicateFactory(PredicateKey key,
PredicateFactory predicateFactory)
|
void |
consultFile(File prologScript)
Populates this objects
KnowledgeBase with clauses read from the specified file. |
void |
consultReader(Reader reader)
Populates this objects
KnowledgeBase with clauses read from the specified Reader . |
void |
consultResource(String resourceName)
Populates this objects
KnowledgeBase with clauses read from the specified resource. |
QueryPlan |
createPlan(String prologQuery)
Creates a
QueryPlan for querying the Projog environment. |
QueryStatement |
createStatement(String prologQuery)
Creates a
QueryStatement for querying the Projog environment. |
void |
executeOnce(String prologQuery)
Evaluate once the given query.
|
QueryResult |
executeQuery(String prologQuery)
Creates a
QueryResult for querying the Projog environment. |
String |
formatTerm(Term t)
Returns a string representation of the specified
Term . |
KnowledgeBase |
getKnowledgeBase()
Returns the
KnowledgeBase associated with this object. |
ProjogStackTraceElement[] |
getStackTrace(Throwable exception)
Provides programmatic access to the stack trace information printed by
printProjogStackTrace(Throwable) . |
void |
printProjogStackTrace(Throwable exception)
Prints the all clauses contained in the specified throwable's stack trace to the standard error stream.
|
void |
printProjogStackTrace(Throwable exception,
PrintStream out)
Prints the all clauses contained in the specified throwable's stack trace to the specified print stream.
|
void |
setUserInput(InputStream is)
Reassigns the "standard" input stream.
|
void |
setUserOutput(PrintStream ps)
Reassigns the "standard" output stream.
|
public Projog(ProjogListener... listeners)
public Projog(ProjogProperties projogProperties, ProjogListener... listeners)
Projog
object with the specified ProjogProperties
and ProjogListener
s.public void consultFile(File prologScript)
KnowledgeBase
with clauses read from the specified file.prologScript
- source of the prolog syntax defining the clauses to addProjogException
- if there is any problem parsing the syntax or adding the new clausespublic void consultReader(Reader reader)
KnowledgeBase
with clauses read from the specified Reader
.reader
- source of the prolog syntax defining the clauses to addProjogException
- if there is any problem parsing the syntax or adding the new clausespublic void consultResource(String resourceName)
KnowledgeBase
with clauses read from the specified resource.
If prologSourceResourceName
refers to an existing file on the file system then that file is used as the
source of the prolog syntax else prologSourceResourceName
is read from the classpath.
resourceName
- source of the prolog syntax defining clauses to add to the KnowledgeBaseProjogException
- if there is any problem parsing the syntax or adding the new clauses to the KnowledgeBasepublic void setUserInput(InputStream is)
By default the "standard" input stream will be System.in
.
public void setUserOutput(PrintStream ps)
By default the "standard" output stream will be System.out
.
public void addPredicateFactory(PredicateKey key, PredicateFactory predicateFactory)
PredicateFactory
with the KnowledgeBase
of this Projog
.
This method provides a mechanism for "plugging in" or "injecting" implementations of PredicateFactory
at
runtime. This mechanism provides an easy way to configure and extend the functionality of Projog - including
adding functionality not possible to define in pure Prolog syntax.
key
- The name and arity to associate the PredicateFactory
with.predicateFactory
- The PredicateFactory
to be added.ProjogException
- if there is already a PredicateFactory
associated with the PredicateKey
public void addArithmeticOperator(PredicateKey key, ArithmeticOperator operator)
ArithmeticOperator
with this KnowledgeBase
of this Projog
.
This method provides a mechanism for "plugging in" or "injecting" implementations of ArithmeticOperator
at
runtime. This mechanism provides an easy way to configure and extend the functionality of Projog - including
adding functionality not possible to define in pure Prolog syntax.
key
- The name and arity to associate the ArithmeticOperator
with.operator
- The instance of ArithmeticOperator
to be associated with key
.ProjogException
- if there is already a ArithmeticOperator
associated with the PredicateKey
public QueryPlan createPlan(String prologQuery)
QueryPlan
for querying the Projog environment.
The newly created object represents the query parsed from the specified syntax. A single QueryPlan
can be
used to create multiple QueryStatement
objects.
prologQuery
- prolog syntax representing a queryProjogException
- if an error occurs parsing prologQuery
createStatement(String)
,
executeQuery(String)
,
executeOnce(String)
public QueryStatement createStatement(String prologQuery)
QueryStatement
for querying the Projog environment.
The newly created object represents the query parsed from the specified syntax. Before the query is executed,
values can be assigned to variables in the query by using QueryStatement.setTerm(String, Term)
. The query
can be executed by calling QueryStatement.executeQuery()
. The resulting QueryResult
can be used to
access the result.
Note: If you do not intend to assign terms to variables then executeQuery(String)
can be called instead.
prologQuery
- prolog syntax representing a queryProjogException
- if an error occurs parsing prologQuery
createPlan(String)
,
executeQuery(String)
,
executeOnce(String)
public QueryResult executeQuery(String prologQuery)
QueryResult
for querying the Projog environment.
The newly created object represents the query parsed from the specified syntax. The QueryResult.next()
and
QueryResult.getTerm(String)
methods can be used to evaluate the query and access values unified to the
variables of the query.
prologQuery
- prolog syntax representing a queryProjogException
- if an error occurs parsing prologQuery
createPlan(String)
,
createStatement(String)
,
executeOnce(String)
public void executeOnce(String prologQuery)
The query will only be evaluated once, even if further solutions could of been found on backtracking.
prologQuery
- prolog syntax representing a queryProjogException
- if an error occurs parsing prologQuery
or no solution can be found for itcreatePlan(String)
,
createStatement(String)
,
executeQuery(String)
public void addListener(ProjogListener listener)
ProjogListener
to receive notifications of events generated during the evaluation of Prolog
goals.listener
- an listener to be addedpublic String formatTerm(Term t)
Term
.t
- the Term
to represent as a stringTerm
TermFormatter.formatTerm(Term)
public KnowledgeBase getKnowledgeBase()
KnowledgeBase
associated with this object.
Each Projog
object is associated with its own KnowledgeBase
. In normal usage it should not be
necessary to call this method - as the other methods of Projog
provide a more convenient mechanism for
updating and querying the "core" inference engine.
KnowledgeBase
associated with this object.KnowledgeBaseUtils
public void printProjogStackTrace(Throwable exception)
public void printProjogStackTrace(Throwable exception, PrintStream out)
public ProjogStackTraceElement[] getStackTrace(Throwable exception)
printProjogStackTrace(Throwable)
.Copyright © 2024. All rights reserved.