public class Rule<E> extends Object implements IRule<E>
| Modifier and Type | Field and Description |
|---|---|
protected static boolean |
DEBUG |
protected static boolean |
INFO |
protected static org.apache.log4j.Logger |
log |
| Constructor and Description |
|---|
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) |
Rule(String name,
IPredicate head,
IPredicate[] tail,
IQueryOptions queryOptions,
IConstraint[] constraints,
IBindingSet constants,
IRuleTaskFactory taskFactory,
IVariable[] requiredVars)
Fully specified ctor.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
int |
getRequiredVariableCount()
The #of distinct required variables declared by the rule.
|
Iterator<IVariable> |
getRequiredVariables()
The required variables declared by the rule in no particular order.
|
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)
|
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()
|
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)). |
protected static final transient org.apache.log4j.Logger log
protected static final transient boolean INFO
protected static final transient boolean DEBUG
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 constraints 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 constraints 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)
public Rule(String name, IPredicate head, IPredicate[] tail, IQueryOptions queryOptions, IConstraint[] constraints, IBindingSet constants, IRuleTaskFactory taskFactory, IVariable[] requiredVars)
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).requiredVars - Optional set of required variables. If null,
all variables are assumed to be required.protected static Var var(String name)
Vars (delegates to Var.var(String)).Var.var(String)public final int getVariableCount()
IRulegetVariableCount in interface IRule<E>public final Iterator<IVariable> getVariables()
IRulegetVariables in interface IRule<E>public final int getRequiredVariableCount()
IRulegetRequiredVariableCount in interface IRule<E>public final Iterator<IVariable> getRequiredVariables()
IRulegetRequiredVariables 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.public final IPredicate getTail(int index)
IRulepublic final IQueryOptions getQueryOptions()
IStepgetQueryOptions in interface ISteppublic final int getConstraintCount()
IRulegetConstraintCount in interface IRule<E>public final IConstraint getConstraint(int index)
IRulegetConstraint in interface IRule<E>index - The index.public final Iterator<IConstraint> getConstraints()
IRulegetConstraints 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()
IRulepublic String toString()
IRulepublic String toString(IBindingSet bindingSet)
IRulepublic IRule<E> specialize(IBindingSet bindingSet, IConstraint[] constraints)
IRulespecialize 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)
IRulespecialize 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)
IRulegetVariableCount 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)
IRuleisFullyBound 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)
IRuleisFullyBound in interface IRule<E>bindingSet - The bindings.public boolean isConsistent(IBindingSet bindingSet)
IRuleisConsistent 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.Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.