org.semwebcentral.sweetrules.ruleml
Class SweetRuleMLHelper

java.lang.Object
  extended byorg.semwebcentral.sweetrules.ruleml.SweetRuleMLHelper

public class SweetRuleMLHelper
extends java.lang.Object

Helper class to perform RuleML input/output

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

Field Summary
private static java.lang.String ANSWER_TAG
          The answer element tag
private static java.lang.String ANSWERSET_ELEMENT_TAG
          The answerSet element tag
private static java.lang.String BINDING_TAG
          The Binding element tag
private static java.lang.String BSUBSTITUTION_TAG
          The binding substitution tag
private static java.lang.String BVAR_TAG
          The Binding variable element tag
private static java.lang.String CTOR_TAG
          The constructor tag from RuleML
private static Logger logger
          The logger object for this class;
private static java.lang.String OPC_TAG
          The _opc flag from RuleML
private static java.lang.String rulemLMungeOrDemungeXSLFileURL
           
private static java.lang.String transformXSLFileURL
          URL for the xsl file that performs one substitution at a time
private static java.lang.String VAR_TAG
          The variable element tag
private static java.lang.String variableNameParameter
          The variableName parameter of substitutor xslt
private static java.lang.String variableValueParameter
          The variableValue parameter of the substitutor xslt
 
Constructor Summary
SweetRuleMLHelper()
           
 
Method Summary
static java.lang.String[] applyAllSubstitutions(java.lang.String xml, java.util.Vector variableNameVector, java.util.Vector answerBindingMatrix)
          Generates an array of XML strings having the substituted values for the variables for each answer set from the answerMatrix
static java.lang.String applySubstitution(java.lang.String xml, java.util.Vector variableNameVector, java.util.Vector answerVector)
          This returns the input XML with variables substituted by their values specified in the bindingSet.
static java.lang.String demungedRuleMLGenerator(java.lang.String demungedRuleML)
          Generates demunged RuleML from munged RuleML, by demunging the URIs
static java.lang.String generateBindingListXML(java.util.Vector variableVector, java.util.Vector answerBindingMatrix)
          Generates XML String from the input matrix
static java.lang.String mungedRuleMLGenerator(java.lang.String unmungedRuleML)
          Generates munged RuleML from unmunged RuleML, by munging the URIs
private static java.lang.String mungeOrDemungeRuleML(java.lang.String input, java.lang.String mungeOrDemunge)
          Common method that performs either munging or demunging
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rulemLMungeOrDemungeXSLFileURL

private static final java.lang.String rulemLMungeOrDemungeXSLFileURL
See Also:
Constant Field Values

transformXSLFileURL

private static final java.lang.String transformXSLFileURL
URL for the xsl file that performs one substitution at a time

See Also:
Constant Field Values

logger

private static final Logger logger
The logger object for this class;


variableNameParameter

private static final java.lang.String variableNameParameter
The variableName parameter of substitutor xslt

See Also:
Constant Field Values

variableValueParameter

private static final java.lang.String variableValueParameter
The variableValue parameter of the substitutor xslt

See Also:
Constant Field Values

CTOR_TAG

private static final java.lang.String CTOR_TAG
The constructor tag from RuleML

See Also:
Constant Field Values

ANSWERSET_ELEMENT_TAG

private static final java.lang.String ANSWERSET_ELEMENT_TAG
The answerSet element tag

See Also:
Constant Field Values

ANSWER_TAG

private static final java.lang.String ANSWER_TAG
The answer element tag

See Also:
Constant Field Values

BINDING_TAG

private static final java.lang.String BINDING_TAG
The Binding element tag

See Also:
Constant Field Values

BVAR_TAG

private static final java.lang.String BVAR_TAG
The Binding variable element tag

See Also:
Constant Field Values

BSUBSTITUTION_TAG

private static final java.lang.String BSUBSTITUTION_TAG
The binding substitution tag

See Also:
Constant Field Values

VAR_TAG

private static final java.lang.String VAR_TAG
The variable element tag

See Also:
Constant Field Values

OPC_TAG

private static final java.lang.String OPC_TAG
The _opc flag from RuleML

See Also:
Constant Field Values
Constructor Detail

SweetRuleMLHelper

public SweetRuleMLHelper()
Method Detail

generateBindingListXML

public static java.lang.String generateBindingListXML(java.util.Vector variableVector,
                                                      java.util.Vector answerBindingMatrix)
                                               throws SweetException
Generates XML String from the input matrix

Parameters:
variableVector - The vector with variable names
answerBindingMatrix - A vector of vectors, with each vector representing a binding list
Returns:
The binding list in the XML format
Throws:
SweetException - if any inconsistency is detected

applyAllSubstitutions

public static java.lang.String[] applyAllSubstitutions(java.lang.String xml,
                                                       java.util.Vector variableNameVector,
                                                       java.util.Vector answerBindingMatrix)
                                                throws SweetException
Generates an array of XML strings having the substituted values for the variables for each answer set from the answerMatrix

Parameters:
xml - The xml query to be substituted
variableNameVector - The vector of variables
answerBindingMatrix - The matrix of answers
Returns:
An array of Strings each representing a substitution instance. Refer to the return list of "applySubstitution" for details about the length requirements of these vectors
Throws:
SweetException - if an exception occurs

applySubstitution

public static java.lang.String applySubstitution(java.lang.String xml,
                                                 java.util.Vector variableNameVector,
                                                 java.util.Vector answerVector)
                                          throws SweetException
This returns the input XML with variables substituted by their values specified in the bindingSet. The nodes are replaced with <_opc>.

If the variables and the answer sets are of unequal size then the substitution is performed for the smaller set

Parameters:
xml - The input ruleml query
variableNameVector - The vector representing variable names
answerVector - The corresponding answerSet
Returns:
The result of substitution if neither xml, nor variableVector nor answerVector are null Otherwise the original xml is returned.
Throws:
SweetException

mungedRuleMLGenerator

public static java.lang.String mungedRuleMLGenerator(java.lang.String unmungedRuleML)
                                              throws SweetTranslatorException
Generates munged RuleML from unmunged RuleML, by munging the URIs

Parameters:
unmungedRuleML - The original RuleML
Returns:
The munged RuleML
Throws:
SweetTranslatorException

demungedRuleMLGenerator

public static java.lang.String demungedRuleMLGenerator(java.lang.String demungedRuleML)
                                                throws SweetTranslatorException
Generates demunged RuleML from munged RuleML, by demunging the URIs

Returns:
The demunged RuleML
Throws:
SweetTranslatorException

mungeOrDemungeRuleML

private static java.lang.String mungeOrDemungeRuleML(java.lang.String input,
                                                     java.lang.String mungeOrDemunge)
                                              throws SweetTranslatorException
Common method that performs either munging or demunging

Parameters:
input - The ruleml input
mungeOrDemunge - if it is "munge" the input is munged if it is "demunge" the input is demunged
Returns:
The munged or demunged RuleML
Throws:
SweetTranslatorException