public interface PrologEngine extends Iterable<PrologClause>
PrologProvider.newEngine()
PrologProvider provider = Prolog.getProvider(Some_PrologProvider_Impl.class); PrologEngine engine = provider.newEngine();The
PrologProvider.newEngine(String)
method is used if the specified
file to consult is provided.
The prolog engine have a life cycle on the user application. After create an
instance we can consult any file with prolog programs using
consult(Reader)
or consult(String)
. If another prolog file
need to be include in main memory we can use include(Reader)
or
include(String)
. We can include so much files as we needed.
engine.consult("family.pl"); engine.include("company.pl"); engine.include("zoo.pl");To check if the given goal have solution using the resolution engine mechanism we can use
contains(String)
or
contains(PrologTerm, PrologTerm...)
. Both methods returning true if
the given goal have solution or false in other case.
boolean b = engine.clause("parent( pam, bob)");To check if there are a clause in the prolog engine we can use
clause(String)
or clause(PrologTerm, PrologTerm...)
. This
methods is based on the prolog engine built-in clause/2 that check if in the
currents predicates exist a clause definition that match with the given
clause. This methods return true if the given clause is defined in the prolog
engine or false in other case. The following cases return true.
engine.assertz("parent( pam, bob)"); boolean b = engine.clause("parent( X, Y); boolean t = engine.clause("parent( pam, bob)")Java Prolog Interface have an special interface to query to prolog engine about some specific clauses an operate over solution set.
PrologQuery
is the mechanism to query the prolog database loaded in prolog engine. The
way to create a new prolog query is invoking
query(String)
,
query(PrologTerm, PrologTerm...)
or
query(PrologTerm[])
. This interface have several methods
to obtain one, at least N or all query results.
PrologEngine engine = provider.newEngine("zoo.pl"); PrologVariable x = provider.newVariable("X", 0); PrologQuery query = engine.query(provider.newStructure("dark", x)); List<Object> solution = query.oneResult(); for (int i = 0; i < solution.size(); i++) { System.out.println(solution.get(i)); }Java Prolog Interface have shortcuts methods to obtain queries result from the engine. The shortcuts methods to obtain one result are
queryOne(PrologTerm)
,
queryOne(String)
,
queryOne(PrologTerm, PrologTerm...)
. This methods are
equivalent to call PrologEngine.query(...).oneVariablesResult()
.
queryN
The shortcuts methods to obtain all results are
queryAll(PrologTerm)
,
queryAll(String)
,
queryAll(PrologTerm, PrologTerm...)
. This methods are
equivalent to call PrologEngine.query(...).allVariablesResult()
.
After create an empty prolog engine and load any prolog program, we can
modify the program/database. For this propose we have the methods
asserta(String)
, asserta(PrologTerm,PrologTerm...)
or
assertz(String)
, assertz(PrologTerm,PrologTerm...)
. The
asserta methods are used when we need store a prolog clause term on top in
the clause family and assertz by other hand, are when we need store a prolog
clause term on the tail in the clause family.
engine.asserta("grandparent(X,Z):-parent(X,Y),parent(Y,Z)"); engine.asserta("parent( pat, jim)");
engine.assertz("parent( pat, jim)"); engine.assertz("grandparent(X,Z):-parent(X,Y),parent(Y,Z)");For remove clauses in the main memory program if the clause exist can be used
retract(String)
or retract(PrologTerm, PrologTerm...)
. Both
methods after build internal clause representation find the specific clause
and if this exist remove it. By other hand if we need remove all clause
family we can use abolish(String, int)
. This method remove all
predicates that match with the predicate indicator (PI) formed by the
concatenation of the given string functor and integer arity separated by
slash (functor/arity).
engine.retract("parent( tom, bob)");
engine.abolish("parent", 2);All change that take place in the current engine can save to some specific file using
persist(String)
or persist(Writer)
.
engine.assertz(provider.newStructure("parent", pam, bob)); engine.assertz(provider.newStructure("parent", tom, bob)); engine.assertz(provider.newStructure("parent", tom, liz)); engine.assertz(provider.newStructure("parent", bob, ann)); engine.assertz(provider.newStructure("parent", bob, pat)); engine.assertz(provider.newStructure("parent", pat, jim)); engine.persist("family.pl");By the last
dispose()
clear program in main memory. Release all
resources used and prepare the current engine for realize some new task.
engine.dispose();An additional capability of the prolog engine is the
Iterable
implementation. This allow to prolog engine iterate over all user defined
clauses using a for-each loop or iterator loop.
for (PrologClause c : engine) { // do something }
Iterator<?> i = engine.iterator(); while (i.hasNext()) { // do something }The shortcuts methods to obtain N results are
PrologEngine.queryN(Class)
, PrologEngine.queryN(Object)
,
PrologEngine.queryN(PrologTerm)
, PrologEngine.queryN(String)
,
PrologEngine.queryN(Class, Class...)
,
PrologEngine.queryN(Object, Object...)
,
PrologEngine.queryN(PrologTerm, PrologTerm...)
.
This methods are equivalent to call
PrologEngine.query(...).nVariablesResult()
.
Java Prolog Interface have shortcuts methods to obtain queries result from
the engine. The shortcuts methods to obtain one result are
PrologEngine.queryOne(Class)
, PrologEngine.queryOne(Object)
,
PrologEngine.queryOne(PrologTerm)
,
PrologEngine.queryOne(String)
,
PrologEngine.queryOne(Class, Class...)
,
PrologEngine.queryOne(Object, Object...)
,
PrologEngine.queryOne(PrologTerm, PrologTerm...)
. This methods are
equivalent to call PrologEngine.query(...).oneVariablesResult()
.
The shortcuts methods to obtain N results are
PrologEngine.queryN(Class)
, PrologEngine.queryN(Object)
,
PrologEngine.queryN(PrologTerm)
, PrologEngine.queryN(String)
,
PrologEngine.queryN(Class, Class...)
,
PrologEngine.queryN(Object, Object...)
,
PrologEngine.queryN(PrologTerm, PrologTerm...)
. This methods are
equivalent to call PrologEngine.query(...).nVariablesResult()
.
The shortcuts methods to obtain all results are
PrologEngine.queryAll(Class)
, PrologEngine.queryAll(Object)
,
PrologEngine.queryAll(PrologTerm)
,
PrologEngine.queryAll(String)
,
PrologEngine.queryAll(Class, Class...)
,
PrologEngine.queryAll(Object, Object...)
,
PrologEngine.queryAll(PrologTerm, PrologTerm...)
. This methods are
equivalent to call PrologEngine.query(...).allVariablesResult()
.Modifier and Type | Method and Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
void |
abolish(String functor,
int arity)
Remove all predicates that match with the predicate indicator (PI) formed by
the concatenation of the given string functor and integer arity separated by
slash (functor/arity).
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
void |
asserta(PrologTerm term)
Create internal prolog clause and add the clause in the main memory program
if the clause non exist.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
void |
asserta(PrologTerm head,
PrologTerm... body)
Add a rule specified by the rule head and rule body if the specified rule
clause non exist.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
void |
asserta(String stringClause)
Parse the string creating internal prolog clause and add the clause in the
main memory program if the clause non exist.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
void |
assertz(PrologTerm term)
Create internal prolog clause and add the clause in the main memory program
if the clause non exist.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
void |
assertz(PrologTerm head,
PrologTerm... body)
Add a rule specified by the rule head and rule body if the specified rule
clause non exist.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
void |
assertz(String stringClause)
Parse the string creating internal prolog clause and add the clause in the
main memory program if the clause non exist.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
boolean |
clause(PrologTerm term)
Find a rule specified by the rule head and rule body in main memory program
that unify with the given clause returning true in this case.If the clause
not exist in main memory program or exist but not unify with the given clause
false value is returned.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
boolean |
clause(PrologTerm head,
PrologTerm... body)
Find a rule specified by the rule head and rule body in main memory program
that unify with the given clause returning true in this case.If the clause
not exist in main memory program or exist but not unify with the given clause
false value is returned.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
boolean |
clause(String stringClause)
Parse the string creating internal prolog clause and returning true if the
clause in the main memory program unify with the given clause.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
void |
consult(Reader reader)
Consult a prolog program from specified reader parsing the prolog program and
put this program into prolog engine.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
void |
consult(String path)
Consult a file specified by the string path loading an parsing the prolog
program.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
boolean |
contains(PrologTerm goal)
Check if the given goal array have solution using the resolution engine
mechanism.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
boolean |
contains(PrologTerm goal,
PrologTerm... goals)
Check if the given goal array have solution using the resolution engine
mechanism.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
boolean |
contains(String goal)
Parse the string creating internal prolog clause and returning true if the
given goal have solution using the resolution engine mechanism.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
boolean |
currentOperator(int priority,
String specifier,
String operator)
Check if in the wrapped prolog engine is defined some particular operator
specified by your Priority, Specifier and Operator.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Set<PrologOperator> |
currentOperators()
Operator set defined in the wrapped prolog engine.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
boolean |
currentPredicate(String functor,
int arity)
Check if in the wrapped prolog engine is defined some particular predicate
specified by your predicate indicator (PI = functor/arity).
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Set<PrologIndicator> |
currentPredicates()
Predicate set defined in the wrapped prolog engine.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
void |
dispose()
Clear program in main memory.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Set<PrologIndicator> |
getBuiltIns()
Predicate set defined by the supported built-ins predicate in the wrapped
prolog engine.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String |
getLicense()
License of the wrapped engine.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PrologLogger |
getLogger()
Get the prolog system logger instance to report any errors or exceptions
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String |
getName()
Name of the wrapped engine.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String |
getOSArch()
Return the host operating system architecture.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String |
getOSName()
Return the host operating system name.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String |
getOSVersion()
Return the host operating system version.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Set<PrologIndicator> |
getPredicates()
User defined predicate set defined in the wrapped prolog engine.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PrologProgram |
getProgram()
Make and return a copy of the program.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Set<PrologClause> |
getProgramClauses()
Make and return a copy of the clause set present in the current engine.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Map<String,List<PrologClause>> |
getProgramMap()
Make and return a copy of the clause map present in the current engine.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
int |
getProgramSize()
Number of clauses in the current engine.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PrologProvider |
getProvider()
Get a Prolog provider instance hold in the current engine.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String |
getVendor()
Under-laying engine vendor
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String |
getVersion()
Version of the wrapped engine.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
void |
include(Reader reader)
Consult a prolog program from specified reader parsing the prolog program and
include this program into current prolog engine.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
void |
include(String path)
Consult a file specified by the string path loading an parsing the prolog
program and include the loaded program into current engine.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
boolean |
isProgramEmpty()
Check if the program in main memory is empty returning true if the clause
number in the program is 0 and false in otherwise.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Map<String,PrologTerm> |
match(PrologTerm t1,
PrologTerm t2)
Match to other term returning list of substitutions.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PrologClauseBuilder |
newClauseBuilder()
Create a new clause builder instance to build prolog clauses
programmatically.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PrologQueryBuilder |
newQueryBuilder()
Create a new query builder instance to build prolog goal programmatically.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
void |
operator(int priority,
String specifier,
String operator)
Define an operator in the wrapped prolog engine with priority between 0 and
1200 and associativity determined by specifier according to the table below
Copyright © 2020–2024 Prolobjectlink Project. All rights reserved. |