|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.deri.iris.rules.RuleHeadEqualityRewriter
public class RuleHeadEqualityRewriter
An utility class that creates new rules to realize support for rule head
equality. This class replaces all occurrences of rule head equality with a
special predicate. This class creates 2 unsafe rules (see rule 1 and rule 2),
therefore any reasoner, that uses rules created by this class must support
unsafe rules. Here, rule head equality is denoted by the predicate
equivalent.
New rules are created to define rule head equality. Note that rule 1 and 2 are unsafe rules, since the property "each variable in the rule head appears in a non-negated, relational subgoal" is violated.
equivalent(?X, ?X).equivalent(?X, ?Y) :- ?X = ?Y.equivalent(?Y, ?X) :- equivalent(?X, ?Y).equivalent(?X, ?Z) :- equivalent(?X, ?Y), equivalent(?Y, ?Z).
For each predicate occurring in a given set of facts (relations) or in any
rule of a given collection of rules, n additional rules are created
where n is the arity of the predicate. Assume a predicate
hasName(?X, ?Y, ?Z) with arity 3. For this predicate the
following three rules are created:
hasName(?U, ?Y, ?Z) :- hasName(?X, ?Y, ?Z), equivalent(?X, ?U).hasName(?X, ?U, ?Z) :- hasName(?X, ?Y, ?Z), equivalent(?Y, ?U).hasName(?X, ?Y, ?U) :- hasName(?X, ?Y, ?Z), equivalent(?Z, ?U).
| Field Summary | |
|---|---|
static IPredicate |
PREDICATE
The predicate replacing the rule head equality predicate. |
| Constructor Summary | |
|---|---|
RuleHeadEqualityRewriter()
Default constructor. |
|
RuleHeadEqualityRewriter(boolean checkForOccurrence,
boolean useUnsafeRules)
Default constructor. |
|
| Method Summary | |
|---|---|
protected Collection<IRule> |
createEqualityRules()
Creates the necessary equality rules, that is: |
protected static ILiteral |
createLiteral(boolean isPositive,
ITerm x,
ITerm y)
Creates a literal representing rule head equality, e.g. |
protected static ILiteral |
createLiteral(boolean isPositive,
ITuple tuple)
Creates a literal representing rule head equality, e.g. |
protected static ILiteral |
createLiteral(ITerm x,
ITerm y)
Creates a positive literal representing rule head equality, e.g. |
protected static ILiteral |
createLiteral(ITuple tuple)
Creates a positive literal representing rule head equality, e.g. |
protected Set<IPredicate> |
extractPredicatesFromRules(Collection<IRule> rules)
Extracts all predicates occurring in the specified collection of rules. |
List<IRule> |
process(List<IRule> rules,
IFacts facts)
Pre-process the given rules and facts. |
static List<IRule> |
replaceHead(List<IRule> rules)
|
Collection<IRule> |
rewrite(Collection<IRule> rules)
Creates new rules for the specified collection of rules, depending on the value of checkForOccurence. |
Collection<IRule> |
rewrite(Collection<IRule> rules,
IFacts facts)
Creates new rules for the specified collection of rules and facts, depending on the value of checkForOccurence. |
Collection<IRule> |
rewrite(IPredicate predicate)
Creates new rules for the specified predicate. |
Collection<IRule> |
rewrite(IRule rule)
Creates new rules for the specified rule. |
protected Collection<IRule> |
rewritePredicates(Collection<IPredicate> predicates)
Creates new rules for the specified predicates. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final IPredicate PREDICATE
$EQUIVALENT$.
| Constructor Detail |
|---|
public RuleHeadEqualityRewriter()
public RuleHeadEqualityRewriter(boolean checkForOccurrence,
boolean useUnsafeRules)
checkForOccurence, the rewriter checks for occurrences of
rules with rule head equality and rewrites given rules only if rules with
rule head equality are present.
checkForOccurrence - If set to true this rewriter
creates new rules for given rules if and only if given rules
contain rules with rule head equality. If set to
false this rewriter will create new rules no
matter what.useUnsafeRules - If set to true this rewriter creates
unsafe rules. If set to false this rewriter will
only create safe rules, and therefore may be incomplete.| Method Detail |
|---|
protected static ILiteral createLiteral(ITerm x,
ITerm y)
x and ?Y is y.
x - The first term.y - The second term.
protected static ILiteral createLiteral(boolean isPositive,
ITerm x,
ITerm y)
x and ?Y is y.
isPositive - true if the literal is positive,
false otherwise.x - The first term.y - The second term.
protected static ILiteral createLiteral(ITuple tuple)
throws IllegalArgumentException
tuple - The tuple.
IllegalArgumentException - If the size of the tuple is not 2.
protected static ILiteral createLiteral(boolean isPositive,
ITuple tuple)
throws IllegalArgumentException
isPositive - true if the literal is positive,
false otherwise.tuple - The tuple.
IllegalArgumentException - If the size of the tuple is not 2.public Collection<IRule> rewrite(Collection<IRule> rules)
checkForOccurence. Note that the specified
collection of rules is not added to the resulting collection.
rules - The rules for which new rules should be created.
public Collection<IRule> rewrite(Collection<IRule> rules,
IFacts facts)
checkForOccurence. Note that the
specified collection of rules is not added to the resulting
collection.
rules - The rules for which new rules should be created.facts - The facts for which new rules should be created.
public Collection<IRule> rewrite(IPredicate predicate)
predicate - The predicate.
protected Collection<IRule> rewritePredicates(Collection<IPredicate> predicates)
predicates - The collection of predicates.
public Collection<IRule> rewrite(IRule rule)
rule - The rule.
protected Set<IPredicate> extractPredicatesFromRules(Collection<IRule> rules)
rules - The collection of rules.
protected Collection<IRule> createEqualityRules()
Creates the necessary equality rules, that is:
equivalent(?X, ?X).equivalent(?X, ?Y) :- ?X = ?Y.equivalent(?Y, ?X) :- equivalent(?X, ?Y).equivalent(?X, ?Z) :- equivalent(?X, ?Y), equivalent(?Y, ?Z).
public List<IRule> process(List<IRule> rules,
IFacts facts)
IRuleHeadEqualityPreProcessor
process in interface IRuleHeadEqualityPreProcessorrules - The rule to pre-process.facts - The facts to pre-process.
public static List<IRule> replaceHead(List<IRule> rules)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||