Class Projog
Contains a single instance of KnowledgeBase.

-
Constructor Summary
ConstructorsConstructorDescriptionProjog(ProjogListener... listeners) Projog(ProjogProperties projogProperties, ProjogListener... listeners) Constructs a newProjogobject with the specifiedProjogPropertiesandProjogListeners. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddArithmeticOperator(PredicateKey key, ArithmeticOperator operator) voidaddListener(ProjogListener listener) Registers anProjogListenerto receive notifications of events generated during the evaluation of Prolog goals.voidaddPredicateFactory(PredicateKey key, PredicateFactory predicateFactory) voidconsultFile(File prologScript) Populates this objectsKnowledgeBasewith clauses read from the specified file.voidconsultReader(Reader reader) Populates this objectsKnowledgeBasewith clauses read from the specifiedReader.voidconsultResource(String resourceName) Populates this objectsKnowledgeBasewith clauses read from the specified resource.createPlan(String prologQuery) Creates aQueryPlanfor querying the Projog environment.createStatement(String prologQuery) Creates aQueryStatementfor querying the Projog environment.voidexecuteOnce(String prologQuery) Evaluate once the given query.executeQuery(String prologQuery) Creates aQueryResultfor querying the Projog environment.formatTerm(Term t) Returns a string representation of the specifiedTerm.Returns theKnowledgeBaseassociated with this object.getStackTrace(Throwable exception) Provides programmatic access to the stack trace information printed byprintProjogStackTrace(Throwable).voidprintProjogStackTrace(Throwable exception) Prints the all clauses contained in the specified throwable's stack trace to the standard error stream.voidprintProjogStackTrace(Throwable exception, PrintStream out) Prints the all clauses contained in the specified throwable's stack trace to the specified print stream.voidReassigns the "standard" input stream.voidReassigns the "standard" output stream.
-
Constructor Details
-
Projog
-
Projog
Constructs a newProjogobject with the specifiedProjogPropertiesandProjogListeners.
-
-
Method Details
-
consultFile
Populates this objectsKnowledgeBasewith clauses read from the specified file.- Parameters:
prologScript- source of the prolog syntax defining the clauses to add- Throws:
ProjogException- if there is any problem parsing the syntax or adding the new clauses
-
consultReader
Populates this objectsKnowledgeBasewith clauses read from the specifiedReader.- Parameters:
reader- source of the prolog syntax defining the clauses to add- Throws:
ProjogException- if there is any problem parsing the syntax or adding the new clauses
-
consultResource
Populates this objectsKnowledgeBasewith clauses read from the specified resource.If
prologSourceResourceNamerefers to an existing file on the file system then that file is used as the source of the prolog syntax elseprologSourceResourceNameis read from the classpath.- Parameters:
resourceName- source of the prolog syntax defining clauses to add to the KnowledgeBase- Throws:
ProjogException- if there is any problem parsing the syntax or adding the new clauses to the KnowledgeBase
-
setUserInput
Reassigns the "standard" input stream.By default the "standard" input stream will be
System.in. -
setUserOutput
Reassigns the "standard" output stream.By default the "standard" output stream will be
System.out. -
addPredicateFactory
Associates aPredicateFactorywith theKnowledgeBaseof thisProjog.This method provides a mechanism for "plugging in" or "injecting" implementations of
PredicateFactoryat 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.- Parameters:
key- The name and arity to associate thePredicateFactorywith.predicateFactory- ThePredicateFactoryto be added.- Throws:
ProjogException- if there is already aPredicateFactoryassociated with thePredicateKey
-
addArithmeticOperator
Associates aArithmeticOperatorwith thisKnowledgeBaseof thisProjog.This method provides a mechanism for "plugging in" or "injecting" implementations of
ArithmeticOperatorat 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.- Parameters:
key- The name and arity to associate theArithmeticOperatorwith.operator- The instance ofArithmeticOperatorto be associated withkey.- Throws:
ProjogException- if there is already aArithmeticOperatorassociated with thePredicateKey
-
createPlan
Creates aQueryPlanfor querying the Projog environment.The newly created object represents the query parsed from the specified syntax. A single
QueryPlancan be used to create multipleQueryStatementobjects.- Parameters:
prologQuery- prolog syntax representing a query- Returns:
- representation of the query parsed from the specified syntax
- Throws:
ProjogException- if an error occurs parsingprologQuery- See Also:
-
createStatement
Creates aQueryStatementfor 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 callingQueryStatement.executeQuery(). The resultingQueryResultcan be used to access the result.Note: If you do not intend to assign terms to variables then
executeQuery(String)can be called instead.- Parameters:
prologQuery- prolog syntax representing a query- Returns:
- representation of the query parsed from the specified syntax
- Throws:
ProjogException- if an error occurs parsingprologQuery- See Also:
-
executeQuery
Creates aQueryResultfor querying the Projog environment.The newly created object represents the query parsed from the specified syntax. The
QueryResult.next()andQueryResult.getTerm(String)methods can be used to evaluate the query and access values unified to the variables of the query.- Parameters:
prologQuery- prolog syntax representing a query- Returns:
- representation of the query parsed from the specified syntax
- Throws:
ProjogException- if an error occurs parsingprologQuery- See Also:
-
executeOnce
Evaluate once the given query.The query will only be evaluated once, even if further solutions could of been found on backtracking.
- Parameters:
prologQuery- prolog syntax representing a query- Throws:
ProjogException- if an error occurs parsingprologQueryor no solution can be found for it- See Also:
-
addListener
Registers anProjogListenerto receive notifications of events generated during the evaluation of Prolog goals.- Parameters:
listener- an listener to be added
-
formatTerm
-
getKnowledgeBase
Returns theKnowledgeBaseassociated with this object.Each
Projogobject is associated with its ownKnowledgeBase. In normal usage it should not be necessary to call this method - as the other methods ofProjogprovide a more convenient mechanism for updating and querying the "core" inference engine.- Returns:
- the
KnowledgeBaseassociated with this object. - See Also:
-
printProjogStackTrace
Prints the all clauses contained in the specified throwable's stack trace to the standard error stream. -
printProjogStackTrace
Prints the all clauses contained in the specified throwable's stack trace to the specified print stream. -
getStackTrace
Provides programmatic access to the stack trace information printed byprintProjogStackTrace(Throwable).
-