org.semwebcentral.sweetrules.sweetjess
Class SweetRuleML2JessSerializer

java.lang.Object
  extended byorg.semwebcentral.sweetrules.sweetjess.SweetRuleML2JessSerializer

final class SweetRuleML2JessSerializer
extends java.lang.Object

Created on Nov 5, 2004 The RuleML object model to Jess serializer class The rbaseIncludes are not expanded by this class. They need to be expanded and passed. Since this is a singleton class the extensions should avoid member variables unless they are final and use parameter passing (similar to the behavior of static methods) as much as possible as thread safety is easily ensured. This class handles cterms only in the datalog case.

Author:
Shashidhara K Ganjugunte, Dr. Benjamin Grosof, Dr. Said Tabet, Chitravanu Neogy

Field Summary
private static java.lang.String LINE_BREAK
          The LINE_BREAK TODO: USE A SINGLE GLOBAL CONSTANT across all files
private  Logger logger
          The logger object
private static java.lang.String RULE_LABEL_PREFIX
          The prefix for a rulelabel
private  java.math.BigInteger ruleLabelCount
          Counts the rulelabels seen so far
private static SweetRuleML2JessSerializer rulemlToJessSerializer
          The singleton instance
private static int SALIENCE_MULTIPLCATION_FACTOR
          The multiplication factor to ensure more spacing between salience numbers
 
Constructor Summary
private SweetRuleML2JessSerializer()
          The singleton constructor
 
Method Summary
private  java.util.Vector collectParameterValues(java.util.List parameterList, SweetRuleMLObjectModelProcessor rulemlObjProc)
           
private  java.lang.String getBuiltinTransform(java.lang.String predicateName)
          Gets the builtin transform for the specified predicate
(package private) static SweetRuleML2JessSerializer getInstance()
          Accessor for the singleton class
private  boolean needBuiltinTransform(java.lang.String predicateName)
          This method indicates if a given predicate is a builtin which needs to be transformed.
private  void serializeRuleMLAsJess(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb, org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.BodyType body, java.io.BufferedWriter bufferedWriter, SweetRuleMLObjectModelProcessor rulemlObjProc)
           
 void serializeRuleMLAsJess(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb, java.io.BufferedWriter bufferedWriter)
          This serializes a RuleML rulebase as Jess
private  void serializeRuleMLAsJess(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb, org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.EffeType effe, java.io.BufferedWriter bufferedWriter, SweetRuleMLObjectModelProcessor rulemlObjProc)
           
private  void serializeRuleMLAsJess(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb, org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FactType fact, java.io.BufferedWriter bufferedWriter, SweetRuleMLObjectModelProcessor rulemlObjProc)
           
private  void serializeRuleMLAsJess(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb, org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.HeadType head, java.io.BufferedWriter bufferedWriter, SweetRuleMLObjectModelProcessor rulemlObjProc)
           
private  void serializeRuleMLAsJess(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb, org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.ImpType imp, java.util.Set labelSet, java.util.Hashtable stratificationTable, java.io.BufferedWriter bufferedWriter, SweetRuleMLObjectModelProcessor rulemlObjProc)
           
private  void serializeRuleMLAsJess(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb, org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RlabType rlab, java.util.Set labelSet, java.io.BufferedWriter bufferedWriter, SweetRuleMLObjectModelProcessor rulemlObjProc)
          Serializes a rule label into Jess
private  void serializeRuleMLAsJess(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb, org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.SensType sens, java.io.BufferedWriter bufferedWriter, SweetRuleMLObjectModelProcessor rulemlObjProc)
           
private  void serializeRuleMLAsJessInBody(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb, org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.AndbType andbElement, java.io.BufferedWriter bufferedWriter, SweetRuleMLObjectModelProcessor rulemlObjProc)
           
private  void serializeRuleMLAsJessInBody(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb, org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.AndType andElement, java.io.BufferedWriter bufferedWriter, SweetRuleMLObjectModelProcessor rulemlObjProc)
           
private  void serializeRuleMLAsJessInBody(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb, org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.AtomType atom, java.io.BufferedWriter bufferedWriter, SweetRuleMLObjectModelProcessor rulemlObjProc)
           
private  void serializeRuleMLAsJessInBody(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb, org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.CslitType cslit, java.io.BufferedWriter bufferedWriter, SweetRuleMLObjectModelProcessor rulemlObjProc)
           
private  void serializeRuleMLAsJessInBody(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb, org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FclitType fclit, java.io.BufferedWriter bufferedWriter, SweetRuleMLObjectModelProcessor rulemlObjProc)
           
private  void serializeRuleMLAsJessInBody(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb, org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FlitType flit, java.io.BufferedWriter bufferedWriter, SweetRuleMLObjectModelProcessor rulemlObjProc)
           
private  void serializeRuleMLAsJessInBody(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb, java.util.List literalList, java.io.BufferedWriter bufferedWriter, SweetRuleMLObjectModelProcessor rulemlObjProc)
           
private  void serializeRuleMLAsJessInBody(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb, org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.OrbType orbElement, java.io.BufferedWriter bufferedWriter, SweetRuleMLObjectModelProcessor rulemlObjProc)
           
private  void serializeRuleMLAsJessInHead(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb, org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.AndhType andh, java.io.BufferedWriter bufferedWriter, SweetRuleMLObjectModelProcessor rulemlObjProc)
           
private  void serializeRuleMLAsJessInHead(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb, org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.AtomType atom, java.io.BufferedWriter bufferedWriter, SweetRuleMLObjectModelProcessor rulemlObjProc)
           
private  void serializeRuleMLAsJessInHead(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb, org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.CslitType cslitElement, java.io.BufferedWriter bufferedWriter, SweetRuleMLObjectModelProcessor rulemlObjProc)
           
private  void writeLineToBufferedWriter(java.io.BufferedWriter bw, java.lang.String line)
          Utility function to write to a buffered writer
private  void writeToBufferedWriter(java.io.BufferedWriter bw, java.lang.String str)
          Utility to write to a buffered writer (without a new line)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LINE_BREAK

private static final java.lang.String LINE_BREAK
The LINE_BREAK TODO: USE A SINGLE GLOBAL CONSTANT across all files


ruleLabelCount

private java.math.BigInteger ruleLabelCount
Counts the rulelabels seen so far


RULE_LABEL_PREFIX

private static final java.lang.String RULE_LABEL_PREFIX
The prefix for a rulelabel

See Also:
Constant Field Values

rulemlToJessSerializer

private static SweetRuleML2JessSerializer rulemlToJessSerializer
The singleton instance


SALIENCE_MULTIPLCATION_FACTOR

private static final int SALIENCE_MULTIPLCATION_FACTOR
The multiplication factor to ensure more spacing between salience numbers

See Also:
Constant Field Values

logger

private final Logger logger
The logger object

Constructor Detail

SweetRuleML2JessSerializer

private SweetRuleML2JessSerializer()
The singleton constructor

Method Detail

getInstance

static SweetRuleML2JessSerializer getInstance()
Accessor for the singleton class

Returns:
The singleton instance

serializeRuleMLAsJess

public void serializeRuleMLAsJess(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb,
                                  java.io.BufferedWriter bufferedWriter)
                           throws SweetException
This serializes a RuleML rulebase as Jess

Parameters:
bufferedWriter - The writer to write the result of serialization to.
Returns:
The serialized Jess rulebase
Throws:
SweetException

writeToBufferedWriter

private void writeToBufferedWriter(java.io.BufferedWriter bw,
                                   java.lang.String str)
                            throws SweetException
Utility to write to a buffered writer (without a new line)

Parameters:
bw - The writer to write to
str - The string to write
Throws:
SweetException - if an error occurs

writeLineToBufferedWriter

private void writeLineToBufferedWriter(java.io.BufferedWriter bw,
                                       java.lang.String line)
                                throws SweetException
Utility function to write to a buffered writer

Parameters:
bw - The buffered writer to write to
line - The line to be written
Throws:
SweetException - if an error occurs

serializeRuleMLAsJess

private void serializeRuleMLAsJess(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb,
                                   org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.ImpType imp,
                                   java.util.Set labelSet,
                                   java.util.Hashtable stratificationTable,
                                   java.io.BufferedWriter bufferedWriter,
                                   SweetRuleMLObjectModelProcessor rulemlObjProc)
                            throws SweetException
Throws:
SweetException

serializeRuleMLAsJess

private void serializeRuleMLAsJess(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb,
                                   org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.HeadType head,
                                   java.io.BufferedWriter bufferedWriter,
                                   SweetRuleMLObjectModelProcessor rulemlObjProc)
                            throws SweetException
Throws:
SweetException

serializeRuleMLAsJess

private void serializeRuleMLAsJess(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb,
                                   org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.BodyType body,
                                   java.io.BufferedWriter bufferedWriter,
                                   SweetRuleMLObjectModelProcessor rulemlObjProc)
                            throws SweetException
Parameters:
body -
bufferedWriter -
rulemlObjProc -
Throws:
SweetException

serializeRuleMLAsJessInBody

private void serializeRuleMLAsJessInBody(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb,
                                         java.util.List literalList,
                                         java.io.BufferedWriter bufferedWriter,
                                         SweetRuleMLObjectModelProcessor rulemlObjProc)
                                  throws SweetException
Parameters:
bufferedWriter -
rulemlObjProc -
Throws:
SweetException

serializeRuleMLAsJessInBody

private void serializeRuleMLAsJessInBody(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb,
                                         org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.AndbType andbElement,
                                         java.io.BufferedWriter bufferedWriter,
                                         SweetRuleMLObjectModelProcessor rulemlObjProc)
                                  throws SweetException
Throws:
SweetException

serializeRuleMLAsJessInBody

private void serializeRuleMLAsJessInBody(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb,
                                         org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.OrbType orbElement,
                                         java.io.BufferedWriter bufferedWriter,
                                         SweetRuleMLObjectModelProcessor rulemlObjProc)
                                  throws SweetException
Throws:
SweetException

serializeRuleMLAsJessInBody

private void serializeRuleMLAsJessInBody(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb,
                                         org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.AndType andElement,
                                         java.io.BufferedWriter bufferedWriter,
                                         SweetRuleMLObjectModelProcessor rulemlObjProc)
                                  throws SweetException
Throws:
SweetException

serializeRuleMLAsJessInHead

private void serializeRuleMLAsJessInHead(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb,
                                         org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.AtomType atom,
                                         java.io.BufferedWriter bufferedWriter,
                                         SweetRuleMLObjectModelProcessor rulemlObjProc)
                                  throws SweetException
Throws:
SweetException

serializeRuleMLAsJessInHead

private void serializeRuleMLAsJessInHead(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb,
                                         org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.AndhType andh,
                                         java.io.BufferedWriter bufferedWriter,
                                         SweetRuleMLObjectModelProcessor rulemlObjProc)
                                  throws SweetException
Throws:
SweetException

serializeRuleMLAsJessInHead

private void serializeRuleMLAsJessInHead(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb,
                                         org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.CslitType cslitElement,
                                         java.io.BufferedWriter bufferedWriter,
                                         SweetRuleMLObjectModelProcessor rulemlObjProc)
                                  throws SweetException
Throws:
SweetException

serializeRuleMLAsJessInBody

private void serializeRuleMLAsJessInBody(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb,
                                         org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.AtomType atom,
                                         java.io.BufferedWriter bufferedWriter,
                                         SweetRuleMLObjectModelProcessor rulemlObjProc)
                                  throws SweetException
Parameters:
atom -
bufferedWriter -
rulemlObjProc -
Throws:
SweetException

needBuiltinTransform

private boolean needBuiltinTransform(java.lang.String predicateName)
This method indicates if a given predicate is a builtin which needs to be transformed. Currently only notEquals is supported

Parameters:
predicateName - The predicate name to be checked
Returns:
true if the builtin needs to be transformed

getBuiltinTransform

private java.lang.String getBuiltinTransform(java.lang.String predicateName)
Gets the builtin transform for the specified predicate

Parameters:
predicateName - The predicate name to be transformed
Returns:
The predicateName

serializeRuleMLAsJessInBody

private void serializeRuleMLAsJessInBody(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb,
                                         org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FlitType flit,
                                         java.io.BufferedWriter bufferedWriter,
                                         SweetRuleMLObjectModelProcessor rulemlObjProc)
                                  throws SweetException
Throws:
SweetException

collectParameterValues

private java.util.Vector collectParameterValues(java.util.List parameterList,
                                                SweetRuleMLObjectModelProcessor rulemlObjProc)

serializeRuleMLAsJessInBody

private void serializeRuleMLAsJessInBody(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb,
                                         org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.CslitType cslit,
                                         java.io.BufferedWriter bufferedWriter,
                                         SweetRuleMLObjectModelProcessor rulemlObjProc)
                                  throws SweetException
Parameters:
cslit -
bufferedWriter -
rulemlObjProc -
Throws:
SweetException

serializeRuleMLAsJessInBody

private void serializeRuleMLAsJessInBody(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb,
                                         org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FclitType fclit,
                                         java.io.BufferedWriter bufferedWriter,
                                         SweetRuleMLObjectModelProcessor rulemlObjProc)
                                  throws SweetException
Parameters:
fclit -
bufferedWriter -
rulemlObjProc -
Throws:
SweetException

serializeRuleMLAsJess

private void serializeRuleMLAsJess(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb,
                                   org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RlabType rlab,
                                   java.util.Set labelSet,
                                   java.io.BufferedWriter bufferedWriter,
                                   SweetRuleMLObjectModelProcessor rulemlObjProc)
                            throws SweetException
Serializes a rule label into Jess

Parameters:
rlab - The ruleml object processor
bufferedWriter - The writer to write to
rulemlObjProc - The RuleML Object model
Throws:
SweetException - if an error occurs

serializeRuleMLAsJess

private void serializeRuleMLAsJess(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb,
                                   org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FactType fact,
                                   java.io.BufferedWriter bufferedWriter,
                                   SweetRuleMLObjectModelProcessor rulemlObjProc)
                            throws SweetException
Throws:
SweetException

serializeRuleMLAsJess

private void serializeRuleMLAsJess(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb,
                                   org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.SensType sens,
                                   java.io.BufferedWriter bufferedWriter,
                                   SweetRuleMLObjectModelProcessor rulemlObjProc)
                            throws SweetException
Throws:
SweetException

serializeRuleMLAsJess

private void serializeRuleMLAsJess(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb,
                                   org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.EffeType effe,
                                   java.io.BufferedWriter bufferedWriter,
                                   SweetRuleMLObjectModelProcessor rulemlObjProc)
                            throws SweetException
Throws:
SweetException