com.bigdata.rdf.spo
Class SPOPredicate

java.lang.Object
  extended by com.bigdata.rdf.spo.SPOPredicate
All Implemented Interfaces:
IPredicate<ISPO>, Serializable, Cloneable

public class SPOPredicate
extends Object
implements IPredicate<ISPO>

A predicate that is a triple with one or more variables. While the general case allows a predicate to have an arbitrary name, for RDFS reasoning we are only concerned with predicates of the form triple(s,p,o).

Version:
$Id: SPOPredicate.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson
See Also:
Serialized Form

Constructor Summary
protected SPOPredicate(SPOPredicate src, int partitionId)
          Copy constructor sets the index partition identifier.
protected SPOPredicate(SPOPredicate src, String[] relationName)
          Copy constructor overrides the relation name(s).
  SPOPredicate(String[] relationName, int partitionId, IVariableOrConstant<Long> s, IVariableOrConstant<Long> p, IVariableOrConstant<Long> o, IVariableOrConstant<Long> c, boolean optional, IElementFilter<ISPO> constraint, ISolutionExpander<ISPO> expander)
          Fully specified ctor.
  SPOPredicate(String[] relationName, IVariableOrConstant<Long> s, IVariableOrConstant<Long> p, IVariableOrConstant<Long> o)
          Partly specified ctor.
  SPOPredicate(String relationName, IVariableOrConstant<Long> s, IVariableOrConstant<Long> p, IVariableOrConstant<Long> o)
          Partly specified ctor.
  SPOPredicate(String relationName, IVariableOrConstant<Long> s, IVariableOrConstant<Long> p, IVariableOrConstant<Long> o, boolean optional)
          Partly specified ctor.
  SPOPredicate(String relationName, IVariableOrConstant<Long> s, IVariableOrConstant<Long> p, IVariableOrConstant<Long> o, boolean optional, ISolutionExpander<ISPO> expander)
          Partly specified ctor.
  SPOPredicate(String relationName, IVariableOrConstant<Long> s, IVariableOrConstant<Long> p, IVariableOrConstant<Long> o, ISolutionExpander<ISPO> expander)
          Partly specified ctor.
  SPOPredicate(String relationName, IVariableOrConstant<Long> s, IVariableOrConstant<Long> p, IVariableOrConstant<Long> o, IVariableOrConstant<Long> c)
          Partly specified ctor.
 
Method Summary
 int arity()
          The arity is 3 unless the context position was given (as either a variable or bound to a constant) in which case it is 4.
 SPOPredicate asBound(IBindingSet bindingSet)
          A copy of this IPredicate in which zero or more variables have been bound to constants using the given IBindingSet.
 SPOPredicate asBound(IVariable<Long> var, IConstant<Long> val)
          Return a new instance in which all occurrences of the variable in the predicate have been replaced by the specified constant.
 IVariableOrConstant<Long> c()
           
 boolean equals(Object other)
          Compares the bindings of two predicates for equality.
 IVariableOrConstant<Long> get(int index)
          Return the variable or constant at the specified index.
 IConstant<Long> get(ISPO spo, int index)
          Return the asBound value at the specified index for the given element.
 IElementFilter<ISPO> getConstraint()
          An optional constraint on the visitable elements.
 String getOnlyRelationName()
          Resource identifier (aka namespace) identifies the IRelation associated with this IPredicate.
 int getPartitionId()
          The index partition identifier and -1 if no partition identifier was specified.
 int getRelationCount()
          The #of elements in the relation view.
 String getRelationName(int index)
          Return the ith element of the relation view.
 ISolutionExpander<ISPO> getSolutionExpander()
          Returns the object that may be used to selectively override the evaluation of the predicate.
 int getVariableCount()
          The #of arguments in the predicate that are variables (the context position iff it is non-null).
 int getVariableCount(IKeyOrder<ISPO> keyOrder)
          The #of arguments in the predicate required for the specified IKeyOrder which are unbound.
 int hashCode()
          The hash code is defined as
 boolean isFullyBound()
          Deprecated. by isFullyBound(IKeyOrder)
 boolean isFullyBound(IKeyOrder<ISPO> keyOrder)
          Figure out if all positions in the predicate which are required to form the key for this access path are bound in the predicate.
 boolean isOptional()
          true iff the predicate is optional when evaluated as the right-hand side of a join.
 IVariableOrConstant<Long> o()
           
 IVariableOrConstant<Long> p()
           
 IVariableOrConstant<Long> s()
           
 SPOPredicate setC(IConstant<Long> c)
          Constrain the predicate by setting the context position.
 SPOPredicate setConstraint(IElementFilter<ISPO> newConstraint)
          Constrain the predicate by layering on another constraint (the existing constraint, if any, is combined with the new constraint).
 SPOPredicate setPartitionId(int partitionId)
          Sets the index partition identifier constraint.
 SPOPredicate setRelationName(String[] relationName)
          A copy of this IPredicate in which the relationName(s) replace the existing set of relation name(s).
 String toString()
          Representation of the predicate without variable bindings.
 String toString(IBindingSet bindingSet)
          Representation of the predicate with variable bindings.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SPOPredicate

public SPOPredicate(String relationName,
                    IVariableOrConstant<Long> s,
                    IVariableOrConstant<Long> p,
                    IVariableOrConstant<Long> o)
Partly specified ctor. The context will be null. The predicate is NOT optional. No constraint is specified. No expander is specified.

Parameters:
relationName -
s -
p -
o -

SPOPredicate

public SPOPredicate(String relationName,
                    IVariableOrConstant<Long> s,
                    IVariableOrConstant<Long> p,
                    IVariableOrConstant<Long> o,
                    IVariableOrConstant<Long> c)
Partly specified ctor. The predicate is NOT optional. No constraint is specified. No expander is specified.

Parameters:
relationName -
s -
p -
o -
c -

SPOPredicate

public SPOPredicate(String[] relationName,
                    IVariableOrConstant<Long> s,
                    IVariableOrConstant<Long> p,
                    IVariableOrConstant<Long> o)
Partly specified ctor. The context will be null. The predicate is NOT optional. No constraint is specified. No expander is specified.

Parameters:
relationName -
s -
p -
o -

SPOPredicate

public SPOPredicate(String relationName,
                    IVariableOrConstant<Long> s,
                    IVariableOrConstant<Long> p,
                    IVariableOrConstant<Long> o,
                    boolean optional)
Partly specified ctor. The context will be null. No constraint is specified. No expander is specified.

Parameters:
relationName -
s -
p -
o -
optional -

SPOPredicate

public SPOPredicate(String relationName,
                    IVariableOrConstant<Long> s,
                    IVariableOrConstant<Long> p,
                    IVariableOrConstant<Long> o,
                    ISolutionExpander<ISPO> expander)
Partly specified ctor. The context will be null. No constraint is specified. No expander is specified.

Parameters:
relationName -
s -
p -
o -
expander - MAY be null.

SPOPredicate

public SPOPredicate(String relationName,
                    IVariableOrConstant<Long> s,
                    IVariableOrConstant<Long> p,
                    IVariableOrConstant<Long> o,
                    boolean optional,
                    ISolutionExpander<ISPO> expander)
Partly specified ctor. The context will be null. No constraint is specified.

Parameters:
relationName -
s -
p -
o -
optional -
expander - MAY be null.

SPOPredicate

public SPOPredicate(String[] relationName,
                    int partitionId,
                    IVariableOrConstant<Long> s,
                    IVariableOrConstant<Long> p,
                    IVariableOrConstant<Long> o,
                    IVariableOrConstant<Long> c,
                    boolean optional,
                    IElementFilter<ISPO> constraint,
                    ISolutionExpander<ISPO> expander)
Fully specified ctor.

Parameters:
relationName -
partitionId -
s -
p -
o -
c - MAY be null.
optional -
constraint - MAY be null.
expander - MAY be null.

SPOPredicate

protected SPOPredicate(SPOPredicate src,
                       String[] relationName)
Copy constructor overrides the relation name(s).

Parameters:
relationName - The new relation name(s).

SPOPredicate

protected SPOPredicate(SPOPredicate src,
                       int partitionId)
Copy constructor sets the index partition identifier.

Parameters:
partitionId - The index partition identifier.
Throws:
IllegalArgumentException - if the index partition identified is a negative integer.
IllegalStateException - if the index partition identifier was already specified.
Method Detail

getOnlyRelationName

public String getOnlyRelationName()
Description copied from interface: IPredicate
Resource identifier (aka namespace) identifies the IRelation associated with this IPredicate.

This is more or less ignored when the IRule is executed as a query.

When the IRule is executed as an ActionEnum.Insert or ActionEnum.Delete then this identifies the target IMutableRelation on which the computed ISolutions will be written.

Specified by:
getOnlyRelationName in interface IPredicate<ISPO>

getRelationName

public String getRelationName(int index)
Description copied from interface: IPredicate
Return the ith element of the relation view. The view is an ordered array of resource identifiers that describes the view for the relation.

Specified by:
getRelationName in interface IPredicate<ISPO>
Parameters:
index - The index into the array of relation names in the view.

getRelationCount

public final int getRelationCount()
Description copied from interface: IPredicate
The #of elements in the relation view.

Specified by:
getRelationCount in interface IPredicate<ISPO>

getPartitionId

public final int getPartitionId()
Description copied from interface: IPredicate
The index partition identifier and -1 if no partition identifier was specified.

Note: The ability to specify an index partition identifier for a predicate is provided in support of scale-out JOIN strategies. The AbstractAccessPath and the JoinMasterTask are both aware of this property. The JoinMasterTask sets the partition identifier in order to request an access path backed by the name of the local index object on a DataService rather than the name of the scale-out index.

The index partition can not be specified until a choice has been made concerning which IAccessPath to use for a predicate without an index partition constraint. The IAccessPath choice is therefore made by the IEvaluationPlan using the scale-out index view and an AbstractScaleOutFederation.locatorScan(String, long, byte[], byte[], boolean) is used to identify the index partitions on which the IAccessPath will read. The index partition is then set on a constrained IPredicate for each target index partition and the JOINs are then distributed to the DataServices on which those index partitions reside.

Specified by:
getPartitionId in interface IPredicate<ISPO>
Returns:
The index partition identifier -or- -1 if the predicate is not locked to a specific index partition.
See Also:
PartitionLocator, AbstractAccessPath, JoinMasterTask

arity

public final int arity()
The arity is 3 unless the context position was given (as either a variable or bound to a constant) in which case it is 4.

Specified by:
arity in interface IPredicate<ISPO>

setC

public SPOPredicate setC(IConstant<Long> c)
Constrain the predicate by setting the context position. If the context position on the SPOPredicate is non-null, then you must use asBound(IBindingSet) to replace all occurrences of the variable appearing in the context position of the predicate with the desired constant. If the context position is already bound the a constant, then you can not modify it (you can only increase the constraint, not change the constraint).

Throws:
IllegalStateException - unless the context position on the SPOPredicate is null.

setConstraint

public SPOPredicate setConstraint(IElementFilter<ISPO> newConstraint)
Constrain the predicate by layering on another constraint (the existing constraint, if any, is combined with the new constraint).


get

public final IVariableOrConstant<Long> get(int index)
Description copied from interface: IPredicate
Return the variable or constant at the specified index.

Specified by:
get in interface IPredicate<ISPO>
Parameters:
index - The index.
Returns:
The variable or constant at the specified index.

get

public final IConstant<Long> get(ISPO spo,
                                 int index)
Description copied from interface: IPredicate
Return the asBound value at the specified index for the given element. This method does not consider the bindings of the predicate instance.

Note: there is no general means available to implement this method of an awareness of the internal structure of the element type. General purpose record types, such as GOM or relation records, can generally implement this method in the context of the "schema" imposed by the predicate.

Specified by:
get in interface IPredicate<ISPO>
Parameters:
spo - The element.
index - The index.
Returns:
The value.

s

public final IVariableOrConstant<Long> s()

p

public final IVariableOrConstant<Long> p()

o

public final IVariableOrConstant<Long> o()

c

public final IVariableOrConstant<Long> c()

isFullyBound

public final boolean isFullyBound()
Deprecated. by isFullyBound(IKeyOrder)

Return true iff the {s,p,o} arguments of the predicate are bound (vs variables) - the context position is considered iff it is non-null.

Specified by:
isFullyBound in interface IPredicate<ISPO>

getVariableCount

public final int getVariableCount()
The #of arguments in the predicate that are variables (the context position iff it is non-null).

Specified by:
getVariableCount in interface IPredicate<ISPO>
See Also:
IPredicate.getVariableCount(IKeyOrder)

isFullyBound

public boolean isFullyBound(IKeyOrder<ISPO> keyOrder)
Description copied from interface: IPredicate
Figure out if all positions in the predicate which are required to form the key for this access path are bound in the predicate.

Note: This is more correct than IPredicate.isFullyBound() since the latter does not know which the slots in the predicate are required for the specified key order.

Specified by:
isFullyBound in interface IPredicate<ISPO>

getVariableCount

public int getVariableCount(IKeyOrder<ISPO> keyOrder)
Description copied from interface: IPredicate
The #of arguments in the predicate required for the specified IKeyOrder which are unbound.

Specified by:
getVariableCount in interface IPredicate<ISPO>
Parameters:
keyOrder - The key order.
Returns:
The #of unbound arguments for that IKeyOrder.

asBound

public SPOPredicate asBound(IVariable<Long> var,
                            IConstant<Long> val)
Return a new instance in which all occurrences of the variable in the predicate have been replaced by the specified constant.

Parameters:
var - The variable.
val - The constant.
Returns:
A new instance of the predicate in which all occurrences of the variable have been replaced by the constant.
Throws:
IllegalArgumentException - if either argument is null.

asBound

public SPOPredicate asBound(IBindingSet bindingSet)
Description copied from interface: IPredicate
A copy of this IPredicate in which zero or more variables have been bound to constants using the given IBindingSet.

Specified by:
asBound in interface IPredicate<ISPO>

setRelationName

public SPOPredicate setRelationName(String[] relationName)
Description copied from interface: IPredicate
A copy of this IPredicate in which the relationName(s) replace the existing set of relation name(s).

Specified by:
setRelationName in interface IPredicate<ISPO>
Parameters:
relationName - The relation name(s).

setPartitionId

public SPOPredicate setPartitionId(int partitionId)
Description copied from interface: IPredicate
Sets the index partition identifier constraint.

Specified by:
setPartitionId in interface IPredicate<ISPO>
Parameters:
partitionId - The index partition identifier.
Returns:
The constrained IPredicate.

toString

public String toString()
Description copied from interface: IPredicate
Representation of the predicate without variable bindings.

Specified by:
toString in interface IPredicate<ISPO>
Overrides:
toString in class Object

toString

public String toString(IBindingSet bindingSet)
Description copied from interface: IPredicate
Representation of the predicate with variable bindings.

Specified by:
toString in interface IPredicate<ISPO>
Parameters:
bindingSet - The variable bindings

isOptional

public final boolean isOptional()
Description copied from interface: IPredicate
true iff the predicate is optional when evaluated as the right-hand side of a join. An optional predicate will match once after all matches in the data have been exhausted. By default, the match will NOT bind any variables that have been determined to be bound by the predicate based on the computed IEvaluationPlan.

For mutation, some IRelations may require that all variables appearing in the head are bound. This and similar constraints can be enforced using IConstraints on the IRule.

More control over the behavior of optionals may be gained through the use of an ISolutionExpander pattern.

Specified by:
isOptional in interface IPredicate<ISPO>
Returns:
true iff this predicate is optional when evaluating a JOIN.

getConstraint

public final IElementFilter<ISPO> getConstraint()
Description copied from interface: IPredicate
An optional constraint on the visitable elements.

Specified by:
getConstraint in interface IPredicate<ISPO>

getSolutionExpander

public final ISolutionExpander<ISPO> getSolutionExpander()
Description copied from interface: IPredicate
Returns the object that may be used to selectively override the evaluation of the predicate.

Specified by:
getSolutionExpander in interface IPredicate<ISPO>
Returns:
The ISolutionExpander.

equals

public boolean equals(Object other)
Description copied from interface: IPredicate
Compares the bindings of two predicates for equality.

Specified by:
equals in interface IPredicate<ISPO>
Overrides:
equals in class Object
Parameters:
other - Another predicate.
Returns:
true iff the predicate have the same arity and their ordered bindings are the same. when both predicates have a variable at a given index, the names of the variables must be the same.

hashCode

public int hashCode()
Description copied from interface: IPredicate
The hash code is defined as
 get(0).hashCode()*31ˆ(n-1) + get(1).hashCode()*31ˆ(n-2) + ... + get(n-1).hashCode()
 
using int arithmetic, where n is the IPredicate.arity() of the predicate, and ^ indicates exponentiation.

Note: This is similar to how String.hashCode() is defined.

Specified by:
hashCode in interface IPredicate<ISPO>
Overrides:
hashCode in class Object


Copyright © 2006-2009 SYSTAP, LLC. All Rights Reserved.