|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.bigdata.relation.rule.Rule<E>
public class Rule<E>
Default impl.
| Field Summary | |
|---|---|
protected static boolean |
DEBUG
|
protected static boolean |
INFO
|
protected static org.apache.log4j.Logger |
log
|
| Constructor Summary | |
|---|---|
Rule(String name,
IPredicate head,
IPredicate[] tail,
IConstraint[] constraints)
Rule ctor. |
|
Rule(String name,
IPredicate head,
IPredicate[] tail,
IQueryOptions queryOptions,
IConstraint[] constraints)
Rule ctor. |
|
Rule(String name,
IPredicate head,
IPredicate[] tail,
IQueryOptions queryOptions,
IConstraint[] constraints,
IBindingSet constants,
IRuleTaskFactory taskFactory)
Fully specified ctor. |
|
| Method Summary | |
|---|---|
IBindingSet |
getConstants()
Returns any variables that were bound to constants when an IRule
was specialized. |
IConstraint |
getConstraint(int index)
Return the constraint at the given index. |
int |
getConstraintCount()
The #of constraints on the legal states for bindings of the variables declared by rule. |
Iterator<IConstraint> |
getConstraints()
The optional constraints. |
IPredicate |
getHead()
The head of the rule -or- null iff there is no head for
this rule. |
String |
getName()
The name of the rule. |
IQueryOptions |
getQueryOptions()
Return additional constraints that must be imposed during query evaluation. |
Set<IVariable> |
getSharedVars(int index1,
int index2)
Return the variables in common for two IPredicates. |
static Set<IVariable> |
getSharedVars(IPredicate p1,
IPredicate p2)
Return the variables in common for two IPredicates. |
Iterator<IPredicate> |
getTail()
Iterator visits the IPredicates in the body (ala tail) of the
rule. |
IPredicate |
getTail(int index)
Return the predicate at the given index from the tail of the rule. |
int |
getTailCount()
The #of IPredicates in the body (aka tail) of the rule. |
IRuleTaskFactory |
getTaskFactory()
An optional IRuleTaskFactory that will be used in place of the
default IRuleTaskFactory to evaluate this rule (optional) |
int |
getVariableCount()
The #of distinct variables declared by the rule. |
int |
getVariableCount(int index,
IBindingSet bindingSet)
The #of arguments in the selected predicate that are variables (vs constants) with the given the bindings. |
Iterator<IVariable> |
getVariables()
The variables declared by the rule in no particular order. |
boolean |
isConsistent(IBindingSet bindingSet)
Return true unless the IBindingSet violates a
IConstraint declared for this Rule. |
boolean |
isDeclared(IVariable var)
Return true iff the rule declares this variable. |
boolean |
isFullyBound(IBindingSet bindingSet)
If the rule is fully bound for the given bindings. |
boolean |
isFullyBound(int index,
IBindingSet bindingSet)
Return true iff the selected predicate is fully bound. |
boolean |
isRule()
true iff the step is an IRule and
false iff the step is an IProgram. |
IRule<E> |
specialize(IBindingSet bindingSet,
IConstraint[] constraints)
Specialize a rule - the name of the new rule will be derived from the name of the old rule with an appended single quote to indicate that it is a derived variant. |
IRule<E> |
specialize(String name,
IBindingSet bindingSet,
IConstraint[] constraints)
Specialize a rule by binding zero or more variables and adding zero or more constraints. |
String |
toString()
Externalizes the rule displaying variable names and constants. |
String |
toString(IBindingSet bindingSet)
Externalizes the rule displaying variable names, their bindings, and constants. |
protected static Var |
var(String name)
Singleton factory for Vars (delegates to Var.var(String)). |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected static final transient org.apache.log4j.Logger log
protected static final transient boolean INFO
protected static final transient boolean DEBUG
| Constructor Detail |
|---|
public Rule(String name,
IPredicate head,
IPredicate[] tail,
IConstraint[] constraints)
name - A label for the rule.head - The subset of bindings that are selected by the rule.tail - The tail (aka body) of the rule.constraints - An array of constaints on the legal states of the bindings
materialized for the rule.
IllegalArgumentException - if the name is null.
IllegalArgumentException - if the head is null.
IllegalArgumentException - if the tail is null.
IllegalArgumentException - if any element of the tail is null.
IllegalArgumentException - if any element of the optional constraints is
null.
IllegalArgumentException - if the tail is empty.
IllegalArgumentException - if the head declares any variables that are not
declared in the tail.
public Rule(String name,
IPredicate head,
IPredicate[] tail,
IQueryOptions queryOptions,
IConstraint[] constraints)
name - A label for the rule.head - The subset of bindings that are selected by the rule.tail - The tail (aka body) of the rule.queryOptions - Options that effect evaluation of the rule as a query.constraints - An array of constaints on the legal states of the bindings
materialized for the rule.
IllegalArgumentException - if the name is null.
IllegalArgumentException - if the head is null.
IllegalArgumentException - if the tail is null.
IllegalArgumentException - if any element of the tail is null.
IllegalArgumentException - if any element of the optional constraints is
null.
IllegalArgumentException - if the tail is empty.
IllegalArgumentException - if the head declares any variables that are not
declared in the tail.
public Rule(String name,
IPredicate head,
IPredicate[] tail,
IQueryOptions queryOptions,
IConstraint[] constraints,
IBindingSet constants,
IRuleTaskFactory taskFactory)
name - The name of the rule.head - The head of the rule. This is optional for rules that will be
evaluated using ActionEnum.Query but required for
rules that will be evaluated using a mutation
ActionEnum.tail - The predicates in the tail of the rule.queryOptions - Additional constraints on the evaluate of a rule as a query
(required, but see QueryOptions.NONE).constraints - The constraints on the rule (optional).constants - Bindings for variables that are bound as constants for the
rule (optional).taskFactory - Optional override for rule evaluation (MAY be
null).| Method Detail |
|---|
protected static Var var(String name)
Vars (delegates to Var.var(String)).
Var.var(String)Var.var(String) as the latter MAY be replaced by
per-rule-instance variables rather than globally canonical
variables
the only problem with this is that we need to access the variables in a bindingset by name after high-level query since the rule may not be available to the caller, e.g., the match rule uses dynamically generated rules that are not visible to the caller who only sees the binding sets.
public final int getVariableCount()
IRule
getVariableCount in interface IRule<E>public final Iterator<IVariable> getVariables()
IRule
getVariables in interface IRule<E>public final int getTailCount()
IRuleIPredicates in the body (aka tail) of the rule.
getTailCount in interface IRule<E>public final IPredicate getHead()
IRulenull iff there is no head for
this rule. Note that rules that are executed as queries DO NOT need to
specify a head. However, rules that will be executed as mutation
operations (insert or delete) MUST specify the head as it determines the
IRelation on which the rule will write.
getHead in interface IRule<E>ActionEnumpublic final Iterator<IPredicate> getTail()
IRuleIPredicates in the body (ala tail) of the
rule.
getTail in interface IRule<E>public final IPredicate getTail(int index)
IRule
getTail in interface IRule<E>index - The index.
public final IQueryOptions getQueryOptions()
IStep
getQueryOptions in interface ISteppublic final int getConstraintCount()
IRule
getConstraintCount in interface IRule<E>public final IConstraint getConstraint(int index)
IRule
getConstraint in interface IRule<E>index - The index.
public final Iterator<IConstraint> getConstraints()
IRule
getConstraints in interface IRule<E>public final IBindingSet getConstants()
IRuleIRule
was specialized.
Note: IJoinNexus.newBindingSet(IRule) MUST apply the constants
before returning the bindings to the caller.
getConstants in interface IRule<E>public final String getName()
IRule
getName in interface IRule<E>getName in interface ISteppublic String toString()
IRule
toString in interface IRule<E>toString in interface ISteptoString in class Objectpublic String toString(IBindingSet bindingSet)
IRule
toString in interface IRule<E>bindingSet - When non-null, the current variable bindings
will be displayed. Otherwise, the names of variables will be
displayed rather than their bindings.
public IRule<E> specialize(IBindingSet bindingSet,
IConstraint[] constraints)
IRule
specialize in interface IRule<E>bindingSet - Bindings for zero or more free variables in this rule. The
rule will be rewritten such that the variable is replaced by
the binding throughout the rule. An attempt to bind a variable
not declared by the rule will be ignored.constraints - An array of additional constraints to be imposed on the rule
(optional).
public IRule<E> specialize(String name,
IBindingSet bindingSet,
IConstraint[] constraints)
IRule
specialize in interface IRule<E>bindingSet - Bindings for zero or more free variables in this rule. The
rule will be rewritten such that the variable is replaced by
the binding throughout the rule. An attempt to bind a variable
not declared by the rule will be ignored.constraints - An array of additional constraints to be imposed on the rule
(optional).
public Set<IVariable> getSharedVars(int index1,
int index2)
IRuleIPredicates.
getSharedVars in interface IRule<E>index1 - The index of a predicate in the #tail.index2 - The index of a different predicate in the #tail.
null iff there are no
variables in common.
public static Set<IVariable> getSharedVars(IPredicate p1,
IPredicate p2)
IPredicates.
p1 - A predicate.p2 - A different predicate.
null iff there are no
variables in common.
IllegalArgumentException - if the two predicates are the same reference.
public int getVariableCount(int index,
IBindingSet bindingSet)
IRule
getVariableCount in interface IRule<E>index - The index of a predicate declared the tail
of the IRule.bindingSet - The bindings under which the variable count will be obtained
(any variables in the predicate that are bound in the binding
set will be treated as constants for the purposes of this
method).
public boolean isFullyBound(int index,
IBindingSet bindingSet)
IRule
isFullyBound in interface IRule<E>index - The index of a predicate declared the tail
of the IRule.bindingSet - The variable bindings.
public boolean isFullyBound(IBindingSet bindingSet)
IRule
isFullyBound in interface IRule<E>bindingSet - The bindings.
public boolean isConsistent(IBindingSet bindingSet)
IRuletrue unless the IBindingSet violates a
IConstraint declared for this Rule.
isConsistent in interface IRule<E>bindingSet - The binding set.
true unless a constraint is violated by the
bindings.public boolean isDeclared(IVariable var)
IRuletrue iff the rule declares this variable.
isDeclared in interface IRule<E>var - Some variable.
public IRuleTaskFactory getTaskFactory()
IRuleIRuleTaskFactory that will be used in place of the
default IRuleTaskFactory to evaluate this rule (optional)
getTaskFactory in interface IRule<E>null unless custom evaluation is desired.public final boolean isRule()
ISteptrue iff the step is an IRule and
false iff the step is an IProgram.
isRule in interface IStep
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||