org.semwebcentral.sweetrules.ruleml
Class SweetRuleMLObjectModelProcessor

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

public class SweetRuleMLObjectModelProcessor
extends java.lang.Object

Created on Oct 23, 2004 This is wrapper for the RuleML object model. This is a singleton class.

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

Nested Class Summary
 class SweetRuleMLObjectModelProcessor.SweetLiteralProcessor
          Created on Oct 24, 2004 This is a utility class for processing Literals
 class SweetRuleMLObjectModelProcessor.SweetSensorEffectorProcessor
          Created on Oct 28, 2004 Utility class to process Effectors and Sensors
 class SweetRuleMLObjectModelProcessor.SweetTermProcessor
          Created on Oct 24, 2004 A utility class for processing terms i.e.
 
Field Summary
static java.lang.String CNEG_NO
          The no value for cneg
static java.lang.String CNEG_YES
          The yes value for cneg
private static SweetRuleMLObjectModelProcessor.SweetSensorEffectorProcessor effectorProcessor
          The singleton effector processor
static java.lang.String FNEG_NO
          The no value for fneg
static java.lang.String FNEG_YES
          The yes value for fneg
private static SweetRuleMLObjectModelProcessor.SweetLiteralProcessor literalProcessor
          Singleton instance of the literal processor
private static SweetRuleMLObjectModelProcessor rulemlObjectProcessor
          The singleton instance of the class
private static SweetRuleMLObjectModelProcessor.SweetTermProcessor termProcessor
          Singleton instance of the term processor
 
Constructor Summary
private SweetRuleMLObjectModelProcessor()
          The private constructor for the singleton class
 
Method Summary
 void convertImpFactsToFactElements(java.util.List impList)
          Processes the implications in a given list and replaces those without a body with fact elements
 org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FactType createFactFromImp(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.ImpType imp)
          Creates a fact from an implication, only if the input implication does not have a body.
 org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.ImpType createImpFromFact(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FactType fact)
          Creates an implication from a fact
 org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FactType[] getDuplicateFilteredFactVector(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FactType[] factArray)
          Removes the duplicates from a given fact array and returns a vector without duplicates
 org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FactType[] getFacts(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb)
          Returns the array of all facts
 org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FactType[] getFlattenedCslitFacts(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FactType[] factArray)
          Flattens a given fact array by removing the andh and converting atoms to cslits
 org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FactType[] getGroundFacts(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb)
          Returns the list of all ground facts
 org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FactType[] getGroundFactsFromFactArray(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FactType[] factArray)
          Gets all the ground facts from a fact array The original array is unaltered
static SweetRuleMLObjectModelProcessor getInstance()
          Accessor for the singleton
 SweetRuleMLObjectModelProcessor.SweetLiteralProcessor getLiteralProcessor()
          Accessor method for the Literal Processor
private  java.lang.String getNonZeroLengthString(java.lang.String str1, java.lang.String str2)
          Of the two input strings it returns the one with non zero length e.g. if str1=null and str2 = "abc" then str2 is returned and vice-versa
 SweetRuleMLObjectModelProcessor.SweetSensorEffectorProcessor getSensorEffectorProcessor()
          Gets the effector processor object (singleton)
 SweetRuleMLObjectModelProcessor.SweetTermProcessor getTermProcessor()
          Accessor method for the term processor (For handling var, ind and cterm)
 java.lang.String getValueOrHref(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.CtorType ctor)
          Gets either the Value or Href part whichever is present
 java.lang.String getValueOrHref(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.IndType ind)
          Gets either the Value or Href part whichever is present
 java.lang.String getValueOrHref(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RelType rel)
          Gets either the Value or Href part whichever is present
 boolean hasVariables(java.util.List indOrVarOrCtermList)
          Checks to see if the given list of Ind or Var or Cterm has any variables.
 int indexOf(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FactType oldFact, org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FactType[] newFacts)
          Checks if the given fact is a preserved old fact
private static void init()
          The init method to initialize the singleton objects in the required order.
 boolean isDatalog(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.CtermType cterm)
          Checks to see if the term is datalog or not
 boolean isFact(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.ImpType imp)
          Check to see if a given implication is a fact.
 boolean isGround(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.AtomType atom)
          Checks to see if the atom is ground or not
 boolean isGround(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.BodyType body)
          Checks to see if the given body is ground or not
 boolean isGround(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.CslitType cslit)
          Checks to see if a given Classical literal is ground or not
 boolean isGround(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.CtermType cterm)
          Checks to see if the given cterm is ground
 boolean isGround(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FactType fact)
          Checks to see if the given fact is ground
 boolean isGround(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FclitType fclit)
          Checks to see if the given Fclit is ground or not
 boolean isGround(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.HeadType head)
          Checks to see if the given head is ground or not
 boolean isGround(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.ImpType imp)
          Checks to see if the given implication is ground or not
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rulemlObjectProcessor

private static SweetRuleMLObjectModelProcessor rulemlObjectProcessor
The singleton instance of the class


literalProcessor

private static SweetRuleMLObjectModelProcessor.SweetLiteralProcessor literalProcessor
Singleton instance of the literal processor


termProcessor

private static SweetRuleMLObjectModelProcessor.SweetTermProcessor termProcessor
Singleton instance of the term processor


CNEG_YES

public static final java.lang.String CNEG_YES
The yes value for cneg

See Also:
Constant Field Values

CNEG_NO

public static final java.lang.String CNEG_NO
The no value for cneg

See Also:
Constant Field Values

FNEG_YES

public static final java.lang.String FNEG_YES
The yes value for fneg

See Also:
Constant Field Values

FNEG_NO

public static final java.lang.String FNEG_NO
The no value for fneg

See Also:
Constant Field Values

effectorProcessor

private static SweetRuleMLObjectModelProcessor.SweetSensorEffectorProcessor effectorProcessor
The singleton effector processor

Constructor Detail

SweetRuleMLObjectModelProcessor

private SweetRuleMLObjectModelProcessor()
The private constructor for the singleton class

Method Detail

getGroundFacts

public org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FactType[] getGroundFacts(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb)
Returns the list of all ground facts

Returns:
The ground facts

getFacts

public org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FactType[] getFacts(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RulebaseType rb)
Returns the array of all facts

Returns:
The facts in the rulebase

getFlattenedCslitFacts

public org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FactType[] getFlattenedCslitFacts(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FactType[] factArray)
Flattens a given fact array by removing the andh and converting atoms to cslits

Parameters:
factArray - The fact array to flatten
Returns:
The flattened fact array

getDuplicateFilteredFactVector

public org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FactType[] getDuplicateFilteredFactVector(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FactType[] factArray)
Removes the duplicates from a given fact array and returns a vector without duplicates

Parameters:
factArray - The fact array from which the duplicates have to be identified
Returns:
An array of facts not having any duplicates

indexOf

public int indexOf(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FactType oldFact,
                   org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FactType[] newFacts)
Checks if the given fact is a preserved old fact

Parameters:
oldFact - The old fact
newFacts - The new fact set
Returns:
index of the fact in the newFacts array if the old fact is in the new fact array, otherwise -1 is returned

isFact

public boolean isFact(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.ImpType imp)
Check to see if a given implication is a fact. If the body is null, then it is considered a fact

Parameters:
imp - The implication to be checked
Returns:
true if the implication is a fact

getInstance

public static SweetRuleMLObjectModelProcessor getInstance()
Accessor for the singleton

Returns:
The singleton instance

convertImpFactsToFactElements

public void convertImpFactsToFactElements(java.util.List impList)
Processes the implications in a given list and replaces those without a body with fact elements

Parameters:
impList - The impList to be processed

createFactFromImp

public org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FactType createFactFromImp(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.ImpType imp)
                                                                                      throws java.lang.IllegalArgumentException
Creates a fact from an implication, only if the input implication does not have a body. If it has a body then an exception is thrown

Parameters:
imp - The implication from which the fact should be constructed
Returns:
The fact corresponding to the implication
Throws:
java.lang.IllegalArgumentException - if given implication has a body

createImpFromFact

public org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.ImpType createImpFromFact(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FactType fact)
Creates an implication from a fact

Parameters:
fact - The fact from which the fact should be constructed
Returns:
The imp corresponding to the fact

getGroundFactsFromFactArray

public org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FactType[] getGroundFactsFromFactArray(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FactType[] factArray)
Gets all the ground facts from a fact array The original array is unaltered

Parameters:
factArray - The array of facts from which the ground facts are to retrieved
Returns:
The array of ground facts

isGround

public boolean isGround(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FactType fact)
Checks to see if the given fact is ground

Parameters:
fact - The fact to be checked
Returns:
true if the fact is ground

isGround

public boolean isGround(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.ImpType imp)
Checks to see if the given implication is ground or not

Parameters:
imp - The imp to be checked
Returns:
true if the imp is ground false otherwise

isGround

public boolean isGround(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.HeadType head)
                 throws java.lang.IllegalStateException
Checks to see if the given head is ground or not

Parameters:
head - The head to be checked
Returns:
true if the head is ground, false otherwise
Throws:
java.lang.IllegalStateException

isGround

public boolean isGround(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.BodyType body)
                 throws java.lang.IllegalStateException
Checks to see if the given body is ground or not

Parameters:
body - The body that should be checked
Returns:
true if the given body is ground
Throws:
java.lang.IllegalStateException - if an error occurs

isGround

public boolean isGround(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.CslitType cslit)
Checks to see if a given Classical literal is ground or not

Parameters:
cslit - The classical literal to be checked
Returns:
true if the classical literal is ground

isGround

public boolean isGround(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.FclitType fclit)
Checks to see if the given Fclit is ground or not

Parameters:
fclit - The fclit to be checked
Returns:
true if the given fclit is ground

isGround

public boolean isGround(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.AtomType atom)
Checks to see if the atom is ground or not

Parameters:
atom - The atom to be checked
Returns:
true if the atom is ground

hasVariables

public boolean hasVariables(java.util.List indOrVarOrCtermList)
Checks to see if the given list of Ind or Var or Cterm has any variables.

Parameters:
indOrVarOrCtermList - The list of ind or var or cterm
Returns:
true if the list has Ind or Var or Cterm
Throws:
java.lang.IllegalArgumentException - if the list has objects which are not instances of any of IndType, Var, Cterm

isGround

public boolean isGround(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.CtermType cterm)
Checks to see if the given cterm is ground

Parameters:
cterm - The complex term to be checked
Returns:
true if the given cterm has a variable

isDatalog

public boolean isDatalog(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.CtermType cterm)
Checks to see if the term is datalog or not

Parameters:
cterm - The complex term to check
Returns:
true if the term is datalog, false otherwise

getValueOrHref

public java.lang.String getValueOrHref(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.CtorType ctor)
                                throws java.lang.IllegalStateException
Gets either the Value or Href part whichever is present

Parameters:
ctor - The ctor whose Value or Href is to be returned
Returns:
Either the href or the value part
Throws:
java.lang.IllegalStateException - if either none of href and value are present or both are present

getValueOrHref

public java.lang.String getValueOrHref(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.RelType rel)
                                throws java.lang.IllegalStateException
Gets either the Value or Href part whichever is present

Parameters:
rel - The rel whose Value or Href is to be returned
Returns:
Either the href or the value part
Throws:
java.lang.IllegalStateException - if either none of href and value are present or both are present

getValueOrHref

public java.lang.String getValueOrHref(org.semwebcentral.sweetrules.ruleml.sweetrulemlobjectmodel.IndType ind)
                                throws java.lang.IllegalStateException
Gets either the Value or Href part whichever is present

Parameters:
ind - The ind whose Value or Href is to be returned
Returns:
Either the href or the value part
Throws:
java.lang.IllegalStateException - if either none of href and value are present or both are present

getLiteralProcessor

public SweetRuleMLObjectModelProcessor.SweetLiteralProcessor getLiteralProcessor()
Accessor method for the Literal Processor

Returns:
The Literal processor

getTermProcessor

public SweetRuleMLObjectModelProcessor.SweetTermProcessor getTermProcessor()
Accessor method for the term processor (For handling var, ind and cterm)

Returns:
The term processor

getSensorEffectorProcessor

public SweetRuleMLObjectModelProcessor.SweetSensorEffectorProcessor getSensorEffectorProcessor()
Gets the effector processor object (singleton)

Returns:
The effector processor object to handle effectors

init

private static void init()
The init method to initialize the singleton objects in the required order. Must be called in the get of every component processor


getNonZeroLengthString

private java.lang.String getNonZeroLengthString(java.lang.String str1,
                                                java.lang.String str2)
                                         throws java.lang.IllegalStateException
Of the two input strings it returns the one with non zero length e.g. if str1=null and str2 = "abc" then str2 is returned and vice-versa

Parameters:
str1 - The first string
str2 - The second string
Returns:
The non zero string of the two input strings
Throws:
java.lang.IllegalStateException - if both are non zero length