org.deri.iris.rules
Class RuleManipulator

java.lang.Object
  extended by org.deri.iris.rules.RuleManipulator

public class RuleManipulator
extends Object

A collection of useful rule manipulation operations.


Constructor Summary
RuleManipulator()
           
 
Method Summary
 IRule addBodyLiteral(IRule rule, ILiteral literal)
          Add a literal to a rule body.
 IRule addEquality(IRule rule, ITerm term1, ITerm term2)
          Append an equality term to the rule body.
 IRule addInequality(IRule rule, ITerm term1, ITerm term2)
          Append an inequality term to the rule body.
static IQuery removeDuplicateLiterals(IQuery query)
          Creates a new query with all duplicates removed.
 IRule removeDuplicateLiterals(IRule rule)
          Traverse the body literals and remove any duplicates.
 IRule removeUnnecessaryEqualityBuiltins(IRule rule)
          Remove positive equalities that equate something to itself.
 IAtom replace(IAtom atom, ITerm remove, ITerm replaceWith)
           
 IRule replace(IRule rule, boolean processHead, ITerm remove, ITerm replaceWith)
          Replace all occurrences of 'remove' with 'replaceWith'.
 IRule replaceVariablesWithConstants(IRule rule, boolean strict)
          Iterate the rule looking for positive variable==constant exact equalities.
 IRule replaceVariablesWithVariables(IRule rule)
          Iterate the rule looking for positive variable=variable equality built-ins.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RuleManipulator

public RuleManipulator()
Method Detail

addEquality

public IRule addEquality(IRule rule,
                         ITerm term1,
                         ITerm term2)
Append an equality term to the rule body.

Parameters:
rule - The rule to process.
term1 - The first argument to the equality.
term2 - The second argument to the equality.
Returns:
The new rule.

addInequality

public IRule addInequality(IRule rule,
                           ITerm term1,
                           ITerm term2)
Append an inequality term to the rule body.

Parameters:
rule - The rule to process.
term1 - The first argument to the inequality.
term2 - The second argument to the inequality.
Returns:
The new rule.

addBodyLiteral

public IRule addBodyLiteral(IRule rule,
                            ILiteral literal)
Add a literal to a rule body.

Parameters:
rule - The rule to process.
literal - The literal to add.
Returns:
The new rule.

removeDuplicateLiterals

public static IQuery removeDuplicateLiterals(IQuery query)
Creates a new query with all duplicates removed.

Parameters:
query - the query from where to take the literals
Returns:
the newly created query with all duplicates removed

removeDuplicateLiterals

public IRule removeDuplicateLiterals(IRule rule)
Traverse the body literals and remove any duplicates.

Parameters:
rule - The rule to examine.
Returns:
The modified rule.

replaceVariablesWithVariables

public IRule replaceVariablesWithVariables(IRule rule)
Iterate the rule looking for positive variable=variable equality built-ins. For each one found, traverse the whole rule and replace one variable with the other.

Parameters:
rule - The rule to process.
Returns:
The new rule.

replaceVariablesWithConstants

public IRule replaceVariablesWithConstants(IRule rule,
                                           boolean strict)
Iterate the rule looking for positive variable==constant exact equalities. For each one found, replace the variable with the constant in the other rule literals.

Parameters:
rule - The rule to process
strict - True, do replacements only for exact equalities. False, use any equality.
Returns:
A new rule

removeUnnecessaryEqualityBuiltins

public IRule removeUnnecessaryEqualityBuiltins(IRule rule)
Remove positive equalities that equate something to itself.

Parameters:
rule - The rule to process.
Returns:
The new rule.

replace

public IRule replace(IRule rule,
                     boolean processHead,
                     ITerm remove,
                     ITerm replaceWith)
Replace all occurrences of 'remove' with 'replaceWith'.

Parameters:
rule - The rule to modify
processHead - true, to modifix the head as well as the body
remove - The term to remove
replaceWith - The term to replace with
Returns:
The new rule

replace

public IAtom replace(IAtom atom,
                     ITerm remove,
                     ITerm replaceWith)