lp.trans
Class LpGrounder

java.lang.Object
  extended by lp.trans.Grounder<LogicProgram>
      extended by lp.trans.LpGrounder

public class LpGrounder
extends Grounder<LogicProgram>

Creates a grounded version of a normal logic program. This means that the resulting program output has the same stable models as the original program and output.isGround() returns true. The transformation is performed using LparseWrapper and can be executed by calling the Grounder.ground(Object) method. Lparse warnings (see LparseWrapper.getWarnings()) issued during the grounding process are translated into GrounderMessages and can be retrieved through the Grounder.getWarnings() method.

Version:
1.0.0
Author:
Martin Slota
See Also:
LparseWrapper, LpSolver

Field Summary
private  LpParser parser
          Used to parse lparse's output.
private  LpPrinter<Writer> pp
          An instance of LpPrettyPrinter that is used to create the lparse input with the original (non-ground) program.
 
Constructor Summary
LpGrounder()
          Creates a new instance of LpGrounder that creates its own LparseWrapper instance using its default constructors.
LpGrounder(LparseWrapper wrapper)
          Creates a new instance of LpGrounder that uses the given object to invoke lparse and process its output.
 
Method Summary
protected  GrounderMessage makeGrounderMessage(LparseMessage message, LogicProgram inputProgram)
          Creates an error message based on lparseMessage from lparse and the input program.
protected  LogicProgram parseOutput(String program)
          Parses the given lparse output and returns the grounded program.
protected  void printProgram(LogicProgram inputProgram, Writer writer)
          Prints inputProgram in a form that is groundable by lparse (as long as the programmer didn't break the constraints imposed by lparse).
 
Methods inherited from class lp.trans.Grounder
getWarnings, ground, setLparsePath
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pp

private final LpPrinter<Writer> pp
An instance of LpPrettyPrinter that is used to create the lparse input with the original (non-ground) program.


parser

private final LpParser parser
Used to parse lparse's output.

Constructor Detail

LpGrounder

public LpGrounder()
Creates a new instance of LpGrounder that creates its own LparseWrapper instance using its default constructors.


LpGrounder

public LpGrounder(LparseWrapper wrapper)
Creates a new instance of LpGrounder that uses the given object to invoke lparse and process its output.

Parameters:
wrapper - the object used to execute lparse, parse its warnings and/or errors and create corresponding LparseMessage objects
Method Detail

printProgram

protected void printProgram(LogicProgram inputProgram,
                            Writer writer)
Prints inputProgram in a form that is groundable by lparse (as long as the programmer didn't break the constraints imposed by lparse).

Specified by:
printProgram in class Grounder<LogicProgram>
Parameters:
inputProgram - the (ungrounded) input program
writer - a Writer to write to

makeGrounderMessage

protected GrounderMessage makeGrounderMessage(LparseMessage message,
                                              LogicProgram inputProgram)
Creates an error message based on lparseMessage from lparse and the input program.

Specified by:
makeGrounderMessage in class Grounder<LogicProgram>
Parameters:
message - the error or warning message issued by lparse
inputProgram - the input program
Returns:
an enhanced message containing a reference to the problematic rule

parseOutput

protected LogicProgram parseOutput(String program)
Parses the given lparse output and returns the grounded program.

Specified by:
parseOutput in class Grounder<LogicProgram>
Parameters:
program - the lparse output
Returns:
the grounded program