lp.trans
Class DlpGrounder.DlpTagger<W extends Writer>

java.lang.Object
  extended by java.io.Writer
      extended by lp.struct.util.LpPrinter<W>
          extended by lp.struct.util.LpPrettyPrinter<W>
              extended by lp.trans.DlpGrounder.DlpTagger<W>
All Implemented Interfaces:
Closeable, Flushable, Appendable, LpStructureUnitVisitor
Enclosing class:
DlpGrounder

private static class DlpGrounder.DlpTagger<W extends Writer>
extends LpPrettyPrinter<W>

A special LpStructureUnit printer that:

  1. gets rid of negation in rule heads by prepending a "p_" or "n_"
  2. adds a tagging literal to body of every rule. This literal is of the form "tag#" where # is some non-negative number. It indicates which program of the sequence the rule came from

Version:
1.0.0
Author:
Martin Slota

Field Summary
private  int tagNumber
          Contains the current tag number used for adding the tagging literals.
private  boolean visitingHead
          Indicates whether a rule's head or a body literal is being processed.
 
Fields inherited from class lp.struct.util.LpPrettyPrinter
ARROW_STRING, SPACE_STRING
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
DlpGrounder.DlpTagger(W out)
          Creates a new instance of TaggingPrettyPrinter.
 
Method Summary
 void appendTagFacts()
          Appends facts with all tagging literals used until now to this character sequence.
 void incTagNumber()
          Increments the tag number used for adding the tagging literals.
 void reset()
           
 void visit(LpLiteral lit)
          Appends a textual form of a LpLiteral instance to this character sequence.
 void visit(LpRule rule)
          Appends a textual form of a LpRule instance to this character sequence.
 
Methods inherited from class lp.struct.util.LpPrettyPrinter
appendRuleNoDot, arrow, beginParen, comma, dot, endParen, getBuffer, getBuffer, literalPrefix, space, visit, visit, visit, visit, visit, visit, visitArgumentList
 
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

tagNumber

private int tagNumber
Contains the current tag number used for adding the tagging literals.


visitingHead

private boolean visitingHead
Indicates whether a rule's head or a body literal is being processed.

Constructor Detail

DlpGrounder.DlpTagger

public DlpGrounder.DlpTagger(W out)
Creates a new instance of TaggingPrettyPrinter.

Method Detail

reset

public void reset()

incTagNumber

public void incTagNumber()
Increments the tag number used for adding the tagging literals. Initially it is 0.


visit

public void visit(LpRule rule)
Appends a textual form of a LpRule instance to this character sequence. Shouldn't be called directly, LpPrinter.append(LpStructureUnit) should be used instead. In case it has a negative literal in its head, it is output as a positive literal, but "n_" is prepended to the predicate's name. In case the head is a positive literal, "p_" is prepended to its head. Polarity of body literals is not changed but the "p_" is always prepended to their predicate names to recognize them from the tagging literal (lparse changes the order of literals so this couldn't be used). A tagging literal of the form "tag#" is added to each rule's body. The # is substituted with the current tag number.

Specified by:
visit in interface LpStructureUnitVisitor
Overrides:
visit in class LpPrettyPrinter<W extends Writer>
Parameters:
rule - the LpRule instance whose textual representation should be appended to this character sequence
Throws:
NullPointerException - if rule is null
See Also:
LpPrinter, LpStructureUnitVisitor.visit(LpRule)

visit

public void visit(LpLiteral lit)
Appends a textual form of a LpLiteral instance to this character sequence. Shouldn't be called directly, LpPrinter.append(LpStructureUnit) should be used instead. The behaviour of this method depends on the context of the given literal—whether it is a body literal or a head literal. See visit(LpRule).

Specified by:
visit in interface LpStructureUnitVisitor
Overrides:
visit in class LpPrettyPrinter<W extends Writer>
Parameters:
lit - the LpLiteral instance whose textual representation should be appended to this character sequence
Throws:
NullPointerException - if lit is null
See Also:
LpPrinter, LpStructureUnitVisitor.visit(LpLiteral)

appendTagFacts

public void appendTagFacts()
Appends facts with all tagging literals used until now to this character sequence.