|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.Writer
lp.struct.util.LpPrinter<W>
lp.struct.util.LpPrettyPrinter<W>
public class LpPrettyPrinter<W extends Writer>
Transforms a logic program (or its components} represented by objects
implementing the LpStructureUnit
interface into a
human-readable (standard) textual representation.
For example the following code:
LpPredicate predP = LpPredicate.getInstance("p", 0); LpLiteral litP = LpAtom.getInstance(predP, null).getNegativeLiteral(); LpRule fact = new LpRule(litP, null); System.out.println(LpPrettyPrinter.asString(fact));would produce the following output:
not p.
LpPrinter
Field Summary | |
---|---|
protected String |
ARROW_STRING
String that separates the head and body of a rule. |
protected String |
SPACE_STRING
String containing a space or nothing. |
Fields inherited from class java.io.Writer |
---|
lock |
Constructor Summary | |
---|---|
LpPrettyPrinter(W out)
Creates a new instance of LpPrettyPrinter . |
|
LpPrettyPrinter(W out,
String arrow,
boolean withSpaces)
Creates a new instance of LpPrettyPrinter . |
Method Summary | |
---|---|
protected void |
appendRuleNoDot(LpRule rule)
Appends a natural textual form of rule to this character sequence
not taking into account the position of the rule within the structure and
without the trailing dot. |
protected void |
arrow()
Appends the ARROW_STRING . |
protected void |
beginParen()
Appends a left parenthesis. |
protected void |
comma()
Appends a comma. |
protected void |
dot()
Appends a dot. |
protected void |
endParen()
Appends a right parenthesis. |
static LpBuffer |
getBuffer()
A convenience method that creates a new LpBuffer that uses a new
LpPrettyPrinter instance to write
LpStructureUnit s. |
static LpBuffer |
getBuffer(String arrow,
boolean withSpaces)
A convenience method that creates a new LpBuffer that uses a new
LpPrettyPrinter instance to write
LpStructureUnit s. |
protected void |
literalPrefix(boolean positive)
Appends an empty string when positive is true and the
string "not " otherwise. |
protected void |
space()
Appends the SPACE_STRING . |
void |
visit(LpAtom atom)
Appends a natural textual form of a LpAtom instance to the
underlying Writer . |
void |
visit(LpCompoundTerm term)
Appends a natural textual form of a LpCompoundTerm instance to
the underlying Writer . |
void |
visit(LpConstant con)
Appends a natural textual form of a LpConstant instance to the
underlying Writer . |
void |
visit(LpFunction fun)
Appends a natural textual form of a LpFunction instance to the
underlying Writer . |
void |
visit(LpLiteral lit)
Appends a natural textual form of a LpLiteral instance to the
underlying Writer . |
void |
visit(LpPredicate pred)
Appends a natural textual form of a LpPredicate instance to the
underlying Writer . |
void |
visit(LpRule rule)
Appends a natural textual form of a LpRule instance to the
underlying Writer . |
void |
visit(LpVariable var)
Appends a natural textual form of a LpVariable instance to the
underlying Writer . |
protected void |
visitArgumentList(List<LpTerm> args)
This method is used in visit(LpCompoundTerm) and
visit(LpLiteral) . |
Methods inherited from class lp.struct.util.LpPrinter |
---|
append, append, append, append, close, flush, getOut, setOut, write, write, write, write, write, write |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final String ARROW_STRING
protected final String SPACE_STRING
Constructor Detail |
---|
public LpPrettyPrinter(W out)
LpPrettyPrinter
. It will use the string
"<-" to separate the head and body of a rule. The output will also
contain extra spaces to enhance readability.
out
- the underlying writer into which everything will be writtenpublic LpPrettyPrinter(W out, String arrow, boolean withSpaces)
LpPrettyPrinter
. It will use the string
arrow
to separate the head and body of a rule. If
withSpaces
is true
, then the output will also contain
extra spaces to enhance readability.
out
- the underlying writer into which everything will be writtenarrow
- the string to separate the head and body of a rulewithSpaces
- determines whether extra spaces should be added to
places where they can make the output more readable
IllegalArgumentException
- if arrow
is null
Method Detail |
---|
public static LpBuffer getBuffer()
LpBuffer
that uses a new
LpPrettyPrinter
instance to write
LpStructureUnit
s. It will use the string "<-" to
separate the head and body of a rule. The output will also contain extra
spaces to enhance readability.
LpBuffer
public static LpBuffer getBuffer(String arrow, boolean withSpaces)
LpBuffer
that uses a new
LpPrettyPrinter
instance to write
LpStructureUnit
s. It will use the string arrow
to separate the head and body of a rule. If withSpaces
is
true
, then the output will also contain extra spaces to enhance
readability.
arrow
- the string to separate the head and body of a rulewithSpaces
- determines whether extra spaces should be added to
places where they can make the output more readable
LpBuffer
protected void beginParen()
IOException
- (wrapped in an ExceptionAdapter
) in
case an I/O exception occurs while writing to the underlying
Writer
protected void endParen()
IOException
- (wrapped in an ExceptionAdapter
) in
case an I/O exception occurs while writing to the underlying
Writer
protected void comma()
IOException
- (wrapped in an ExceptionAdapter
) in
case an I/O exception occurs while writing to the underlying
Writer
protected void space()
SPACE_STRING
.
IOException
- (wrapped in an ExceptionAdapter
) in
case an I/O exception occurs while writing to the underlying
Writer
protected void literalPrefix(boolean positive)
positive
is true
and the
string "not " otherwise.
positive
- identifies whether a prefix for a positive or a negative
literal should be appended
IOException
- (wrapped in an ExceptionAdapter
) in
case an I/O exception occurs while writing to the underlying
Writer
protected void arrow()
ARROW_STRING
.
IOException
- (wrapped in an ExceptionAdapter
) in
case an I/O exception occurs while writing to the underlying
Writer
protected void dot()
IOException
- (wrapped in an ExceptionAdapter
) in
case an I/O exception occurs while writing to the underlying
Writer
public void visit(LpConstant con)
LpConstant
instance to the
underlying Writer
. Shouldn't be called directly,
LpPrinter.append(LpStructureUnit)
should be used instead.
The natural form of a constant is its name
(see LpConstant.getName()
).
con
- the LpConstant
instance whose natural textual
representation should be appended to the underlying Writer
NullPointerException
- if con
is null
IOException
- (wrapped in an ExceptionAdapter
) in
case an I/O exception occurs while writing to the underlying
Writer
LpPrinter
,
LpStructureUnitVisitor.visit(LpConstant)
public void visit(LpVariable var)
LpVariable
instance to the
underlying Writer
. Shouldn't be called directly,
LpPrinter.append(LpStructureUnit)
should be used instead.
The natural form of a variable is its name
(see LpVariable.getName()
).
var
- the LpVariable
instance whose natural textual
representation should be appended to the underlying Writer
NullPointerException
- if var
is null
IOException
- (wrapped in an ExceptionAdapter
) in
case an I/O exception occurs while writing to the underlying
Writer
LpPrinter
,
LpStructureUnitVisitor.visit(LpVariable)
public void visit(LpFunction fun)
LpFunction
instance to the
underlying Writer
. Shouldn't be called directly,
LpPrinter.append(LpStructureUnit)
should be used instead.
The natural form of a function is its name
(see LpFunction.getName()
).
fun
- the LpFunction
instance whose natural textual
representation should be appended to the underlying Writer
NullPointerException
- if fun
is null
IOException
- (wrapped in an ExceptionAdapter
) in
case an I/O exception occurs while writing to the underlying
Writer
LpPrinter
,
LpStructureUnitVisitor.visit(LpFunction)
protected void visitArgumentList(List<LpTerm> args)
visit(LpCompoundTerm)
and
visit(LpLiteral)
. Can also be useful for overriding classes.
It appends the natural textual form of a list of terms. It is composed of
a left parenthesis followed by natural textual representations of the
terms in the list, separated from each other by commas. It ends
with a right parenthesis.
args
- the argument list that will be appended to the
underlying Writer
IOException
- (wrapped in an ExceptionAdapter
) in
case an I/O exception occurs while writing to the underlying
Writer
public void visit(LpCompoundTerm term)
LpCompoundTerm
instance to
the underlying Writer
. Shouldn't be called directly,
LpPrinter.append(LpStructureUnit)
should be used instead.
The natural form of a compound term is its function's natural form
followed by a left parenthesis and the natural textual representations of
its arguments, separated from each other by commas. It ends
with a right parenthesis.
term
- the LpCompoundTerm
instance whose natural textual
representation should be appended to the underlying Writer
NullPointerException
- if term
is null
IOException
- (wrapped in an ExceptionAdapter
) in
case an I/O exception occurs while writing to the underlying
Writer
LpPrinter
,
LpStructureUnitVisitor.visit(LpCompoundTerm)
public void visit(LpPredicate pred)
LpPredicate
instance to the
underlying Writer
. Shouldn't be called directly,
LpPrinter.append(LpStructureUnit)
should be used instead.
The natural form of a predicate is its name
(see LpPredicate.getName()
).
pred
- the LpPredicate
instance whose natural textual
representation should be appended to the underlying Writer
NullPointerException
- if pred
is null
IOException
- (wrapped in an ExceptionAdapter
) in
case an I/O exception occurs while writing to the underlying
Writer
LpPrinter
,
LpStructureUnitVisitor.visit(LpPredicate)
public void visit(LpAtom atom)
LpAtom
instance to the
underlying Writer
. Shouldn't be called directly,
LpPrinter.append(LpStructureUnit)
should be used instead.
The natural form of an atom is the natural form of its predicate
followed by a left parenthesis and the natural textual representations of
its arguments, separated from each other by commas. It ends
with a right parenthesis.
atom
- the LpAtom
instance whose natural textual
representation should be appended to the underlying Writer
NullPointerException
- if atom
is null
IOException
- (wrapped in an ExceptionAdapter
) in
case an I/O exception occurs while writing to the underlying
Writer
LpPrinter
,
LpStructureUnitVisitor.visit(LpAtom)
public void visit(LpLiteral lit)
LpLiteral
instance to the
underlying Writer
. Shouldn't be called directly,
LpPrinter.append(LpStructureUnit)
should be used instead.
The natural form of a literal is the natural form of its underlying atom
with "not" and the SPACE_STRING string in front of it if
LpLiteral.isPositive()
is false
.
lit
- the LpLiteral
instance whose natural textual
representation should be appended to the underlying Writer
NullPointerException
- if lit
is null
IOException
- (wrapped in an ExceptionAdapter
) in
case an I/O exception occurs while writing to the underlying
Writer
LpPrinter
,
LpStructureUnitVisitor.visit(LpLiteral)
protected void appendRuleNoDot(LpRule rule)
rule
to this character sequence
not taking into account the position of the rule within the structure and
without the trailing dot.
rule
- the LpRule
instance whose natural textual
representation should be appended to the underlying Writer
NullPointerException
- if rule
is null
IOException
- (wrapped in an ExceptionAdapter
) in
case an I/O exception occurs while writing to the underlying
Writer
visit(LpRule)
public void visit(LpRule rule)
LpRule
instance to the
underlying Writer
. Shouldn't be called directly,
LpPrinter.append(LpStructureUnit)
should be used instead.
A natural form of a rule consists of the natural form of its head
followed by special separator (set in the constructor) and natural forms
of literals in its body, separated from each other by commas. It ends
with a dot.
If LpRule.getHead()
is null
, the natural form
begins with the separator string (the head's natural form is left out).
If LpRule.getBody()
is null
or has no
members, the natural form only consists of the head's natural form and a
dot.
rule
- the LpRule
instance whose natural textual
representation should be appended to the underlying Writer
NullPointerException
- if rule
is null
IOException
- (wrapped in an ExceptionAdapter
) in
case an I/O exception occurs while writing to the underlying
Writer
LpPrinter
,
LpStructureUnitVisitor.visit(LpRule)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |