public interface PrologClauseBuilder
Prolog clause builder to create prolog clauses. The mechanism to create a new
clause builder is using PrologEngine.newClauseBuilder()
. The clause
builder emulate the clause creation process. After define all participant
terms with the begin(PrologTerm)
method, we specify the head of the
clause.
If the clause is a rule, after head definition, the clause body is created
with neck(PrologTerm)
for the first term in the clause body. If the
clause body have more terms, they are created using
comma(PrologTerm)
for every one.
Clause builder have a getClauseString()
for string representation of
the clause in progress. After clause definition this builder have
asserta()
,assertz()
,clause()
,retract()
that use the wrapped engine invoking the correspondent methods for check,
insert or remove clause respectively.
PrologStructure blackZ = provider.newStructure("black", z); PrologStructure brownZ = provider.newStructure("brown", z); PrologClauseBuilder builder = engine.newClauseBuilder(); builder.begin(darkZ).neck(blackZ).assertz(); builder.begin(darkZ).neck(brownZ).assertz();Prolog result.
dark(Z) :- black(Z). dark(Z) :- brown(Z).
Modifier and Type | Method and Description |
---|---|
void |
asserta()
Add the current clause in the main memory program if the clause non exist.
|
void |
assertz()
Add the clause in the main memory program if the clause non exist.
|
PrologClauseBuilder |
begin(PrologTerm term)
Append to the clause builder the head term in the clause.
|
PrologClauseBuilder |
begin(String functor,
PrologTerm... arguments)
Append to the clause builder the head term in the clause.
|
boolean |
clause()
Check if the clause in the main memory program unify with the current clause
and return true.
|
PrologClauseBuilder |
comma(PrologTerm term)
Append to the clause builder other term in the clause body in conjunctive
mode.
|
PrologClauseBuilder |
comma(PrologTerm left,
String operator,
PrologTerm right)
Append to the clause builder other term in the clause body in conjunctive
mode.
|
PrologClauseBuilder |
comma(String functor,
PrologTerm... arguments)
Append to the clause builder other term in the clause body in conjunctive
mode.
|
String |
getClauseString()
Get the clause in string format.
|
PrologEngine |
getEngine()
Engine hold by the current builder
|
PrologClauseBuilder |
neck(PrologTerm term)
Append to the clause builder the first term in the clause body.
|
PrologClauseBuilder |
neck(PrologTerm left,
String operator,
PrologTerm right)
Append to the clause builder the first term in the clause body.
|
PrologClauseBuilder |
neck(String functor,
PrologTerm... arguments)
Append to the clause builder the first term in the clause body.
|
void |
retract()
Remove the clause in the main memory program if the clause exist.
|
PrologClauseBuilder begin(String functor, PrologTerm... arguments)
functor
- string name for the structure term.arguments
- prolog term arguments for the structure.PrologClauseBuilder begin(PrologTerm term)
term
- term to be the head in the clause.PrologClauseBuilder neck(PrologTerm left, String operator, PrologTerm right)
operator
- expression operator.left
- left hand prolog term operand.right
- right hand prolog term operand.PrologClauseBuilder neck(String functor, PrologTerm... arguments)
functor
- string name for the structure term.arguments
- prolog term arguments for the structure term.PrologClauseBuilder neck(PrologTerm term)
term
- term to be append in the clause body.PrologClauseBuilder comma(PrologTerm left, String operator, PrologTerm right)
operator
- expression operator.left
- left hand prolog term operand.right
- right hand prolog term operand.PrologClauseBuilder comma(String functor, PrologTerm... arguments)
functor
- string name for the structure term.arguments
- prolog term arguments for the structure term.PrologClauseBuilder comma(PrologTerm term)
term
- term to be query.String getClauseString()
boolean clause()
void asserta()
void assertz()
void retract()
PrologEngine getEngine()
Copyright © 2020–2024 Prolobjectlink Project. All rights reserved.