com.bigdata.rdf.spo
Class SPO

java.lang.Object
  extended by com.bigdata.rdf.spo.SPO
All Implemented Interfaces:
ISPO, Comparable<SPO>

public class SPO
extends Object
implements ISPO, Comparable<SPO>

Represents a triple, triple+SID, or quad. When used to represent a triple, the statement identifier MAY be set on the triple after the object has been instantiated. When used to represent a quad, the context position SHOULD be treated as immutable and setStatementIdentifier(long) will reject arguments if they can not be validated as statement identifiers (based on their bit pattern).

Version:
$Id: SPO.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson

Field Summary
 long o
          The term identifier for the object position.
 long p
          The term identifier for the predicate position.
 long s
          The term identifier for the subject position.
 
Fields inherited from interface com.bigdata.rdf.spo.ISPO
NULL
 
Constructor Summary
SPO(BigdataResource s, BigdataURI p, BigdataValue o, StatementEnum type)
          Construct a triple from BigdataValues and the specified statement type.
SPO(BigdataStatement stmt)
          Construct a triple/quad from a BigdataStatement.
SPO(IConstant<Long> s, IConstant<Long> p, IConstant<Long> o, StatementEnum type)
          Variant to create an SPO from constants (used by the unit tests).
SPO(IPredicate<ISPO> predicate)
          Variant to create an SPO from a predicate - the StatementEnum and statement identifier are not specified.
SPO(long s, long p, long o)
          Triple constructor for a statement whose type is NOT known.
SPO(long s, long p, long o, byte[] val)
          Constructor used when you know the {s,p,o} and have done a lookup in the index to determine whether or not the statement exists, its StatementEnum type, and its statement identifier (if assigned).
SPO(long s, long p, long o, long c)
          Quads constructor.
SPO(long s, long p, long o, long c, StatementEnum type)
          Quads constructor with StatementEnum.
SPO(long s, long p, long o, StatementEnum type)
          Construct a triple.
 
Method Summary
 long c()
          The term identifier for the SID/context position (slot 3) -or- ISPO.NULL.
 int compareTo(SPO stmt2)
          Imposes s:p:o ordering based on termIds.
static ISPO decodeValue(ISPO spo, byte[] val)
          Sets the statement type and optionally the statement identifier by decoding the value associated with the key one of the statement indices.
 boolean equals(ISPO stmt2)
          True iff the ISPOs are the same object or if the same term identifiers are assigned for the subject, predicate and object positions, and the same StatementEnum are the same.
 boolean equals(Object o)
           
 long get(int index)
          Return the s,p,o, or c value corresponding to the given index.
 long getStatementIdentifier()
          The statement identifier (optional).
 StatementEnum getStatementType()
          Whether the statement is StatementEnum.Explicit, StatementEnum.Inferred or an StatementEnum.Axiom.
 int hashCode()
          Hash code for the (s,p,o) per Sesame's Statement.hashCode().
 boolean hasStatementIdentifier()
          true IFF AbstractTripleStore.isStatement(long) returns true for ISPO.c().
 boolean hasStatementType()
          Return true iff the statement type is known.
 boolean isAxiom()
          Return true IFF the SPO is marked as StatementEnum.Axiom.
 boolean isExplicit()
          Return true IFF the SPO is marked as StatementEnum.Explicit.
 boolean isFullyBound()
          Return true iff all position (s,p,o) are non-ISPO.NULL.
 boolean isInferred()
          Return true IFF the SPO is marked as StatementEnum.Inferred.
 boolean isOverride()
          When true the statement will be written onto the database with exactly its current ISPO.getStatementType() (default false).
 long o()
          The term identifier for the object position (slot 2) -or- ISPO.NULL.
 long p()
          The term identifier for the predicate position (slot 1) -or- ISPO.NULL.
 long s()
          The term identifier for the subject position (slot 0) -or- ISPO.NULL.
 byte[] serializeValue(ByteArrayBuffer buf)
          Return the byte[] that would be written into a statement index for this ISPO, including the optional StatementEnum.MASK_OVERRIDE bit.
static byte[] serializeValue(ByteArrayBuffer buf, boolean override, StatementEnum type, long c)
          Return the byte[] that would be written into a statement index for this SPO, including the optional StatementEnum.MASK_OVERRIDE bit.
 void setOverride(boolean override)
          Set the override flag.
 void setStatementIdentifier(long sid)
          Set the statement identifier.
 void setStatementType(StatementEnum type)
          Set the statement type for this statement.
 String toString()
          Return a representation of the statement using the term identifiers (the identifiers are NOT resolved to terms).
 String toString(IRawTripleStore store)
          Resolves the term identifiers to terms against the store and returns a representation of the statement using IRawTripleStore.toString(long, long, long).
static String toString(long id)
          Represents the term identifier together with its type (literal, bnode, uri, or statement identifier).
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

s

public final long s
The term identifier for the subject position.


p

public final long p
The term identifier for the predicate position.


o

public final long o
The term identifier for the object position.

Constructor Detail

SPO

public SPO(long s,
           long p,
           long o)
Triple constructor for a statement whose type is NOT known.

Note: This is primarily used when you want to discover the type of the statement.

See Also:
AbstractTripleStore#bulkCompleteStatements(ISPOIterator)

SPO

public SPO(long s,
           long p,
           long o,
           long c)
Quads constructor.

Parameters:
s -
p -
o -
c -

SPO

public SPO(long s,
           long p,
           long o,
           StatementEnum type)
Construct a triple.

Note: When the statement is StatementEnum.Inferred you MUST also construct the appropriate Justification.

Parameters:
s -
p -
o -
type - The statement type.

SPO

public SPO(long s,
           long p,
           long o,
           long c,
           StatementEnum type)
Quads constructor with StatementEnum.

Parameters:
s -
p -
o -
c -
type -

SPO

public SPO(long s,
           long p,
           long o,
           byte[] val)
Constructor used when you know the {s,p,o} and have done a lookup in the index to determine whether or not the statement exists, its StatementEnum type, and its statement identifier (if assigned).

Parameters:
s -
p -
o -
val -

SPO

public SPO(IConstant<Long> s,
           IConstant<Long> p,
           IConstant<Long> o,
           StatementEnum type)
Variant to create an SPO from constants (used by the unit tests).

Parameters:
s -
p -
o -
type -

SPO

public SPO(IPredicate<ISPO> predicate)
Variant to create an SPO from a predicate - the StatementEnum and statement identifier are not specified. This may be used as a convenience to extract the {s, p, o, c} from an IPredicate or from an IAccessPath when the predicate is not known to be an SPOPredicate or the IAccessPath is not known to be an SPOAccessPath.

Parameters:
predicate - The predicate.

SPO

public SPO(BigdataResource s,
           BigdataURI p,
           BigdataValue o,
           StatementEnum type)
Construct a triple from BigdataValues and the specified statement type.

Parameters:
s -
p -
o -
type -

SPO

public SPO(BigdataStatement stmt)
Construct a triple/quad from a BigdataStatement. The term identifiers and statement type information available on the BigdataStatement will be used to initialize the SPO.

Parameters:
stmt - The statement.
Method Detail

get

public final long get(int index)
Description copied from interface: ISPO
Return the s,p,o, or c value corresponding to the given index.

Specified by:
get in interface ISPO
Parameters:
index - The legal values are: s=0, p=1, o=2, c=3.

s

public final long s()
Description copied from interface: ISPO
The term identifier for the subject position (slot 0) -or- ISPO.NULL.

Specified by:
s in interface ISPO

p

public final long p()
Description copied from interface: ISPO
The term identifier for the predicate position (slot 1) -or- ISPO.NULL.

Specified by:
p in interface ISPO

o

public final long o()
Description copied from interface: ISPO
The term identifier for the object position (slot 2) -or- ISPO.NULL.

Specified by:
o in interface ISPO

c

public final long c()
Description copied from interface: ISPO
The term identifier for the SID/context position (slot 3) -or- ISPO.NULL. The semantics of the returned value depend on the database mode. For triples, it is unused. For triples+SIDs, it is the statement identifier as assigned by the lexicon. For quads, it is the context (aka named graph) and ISPO.NULL iff the context was not bound.

Specified by:
c in interface ISPO
See Also:
AbstractTripleStore.Options#STATEMENT_IDENTIFIERS, AbstractTripleStore.Options#QUADS

setStatementIdentifier

public final void setStatementIdentifier(long sid)
Set the statement identifier.

Specified by:
setStatementIdentifier in interface ISPO
Parameters:
sid - The statement identifier.
Throws:
IllegalArgumentException - if id is ISPO.NULL.
IllegalStateException - if the statement identifier is already set.

getStatementIdentifier

public final long getStatementIdentifier()
Description copied from interface: ISPO
The statement identifier (optional). This has nearly identical semantics to ISPO.c(), but will throw an exception if the 4th position is not bound.

Statement identifiers are a unique per-triple identifier assigned when a statement is first asserted against the database and are are defined iff AbstractTripleStore.Options#STATEMENT_IDENTIFIERS was specified.

Specified by:
getStatementIdentifier in interface ISPO

hasStatementIdentifier

public final boolean hasStatementIdentifier()
Description copied from interface: ISPO
true IFF AbstractTripleStore.isStatement(long) returns true for ISPO.c().

Specified by:
hasStatementIdentifier in interface ISPO

setOverride

public void setOverride(boolean override)
Description copied from interface: ISPO
Set the override flag.

Specified by:
setOverride in interface ISPO
Parameters:
override - the new value.

isOverride

public boolean isOverride()
Description copied from interface: ISPO
When true the statement will be written onto the database with exactly its current ISPO.getStatementType() (default false).

Note: This feature is used by TruthMaintenance when we need to downgrade an ISPO from "Explicit" to "Inferred". Normally, a statement is automatically upgraded from "Inferred" to "Explicit" so without ISPO.setOverride(boolean) you could not downgrade the StatementEnum in the database without first deleting the statement (which would also delete its justifications).

Specified by:
isOverride in interface ISPO

decodeValue

public static ISPO decodeValue(ISPO spo,
                               byte[] val)
Sets the statement type and optionally the statement identifier by decoding the value associated with the key one of the statement indices.

Parameters:
val - The value associated with the key one of the statement indices.
Returns:
The spo.

serializeValue

public byte[] serializeValue(ByteArrayBuffer buf)
Description copied from interface: ISPO
Return the byte[] that would be written into a statement index for this ISPO, including the optional StatementEnum.MASK_OVERRIDE bit. If the ISPO.hasStatementIdentifier() would return true, then the SID will be included in the returned byte[]. Note that ISPO.hasStatementIdentifier() is defined in terms of the bit pattern of the SID identifiers and therefore will be true ONLY for a statement identifier and NOT for an RDF Value identifier.

Specified by:
serializeValue in interface ISPO
Parameters:
buf - A buffer supplied by the caller. The buffer will be reset before the value is written on the buffer.
Returns:
The value that would be written into a statement index for this ISPO.

serializeValue

public static byte[] serializeValue(ByteArrayBuffer buf,
                                    boolean override,
                                    StatementEnum type,
                                    long c)
Return the byte[] that would be written into a statement index for this SPO, including the optional StatementEnum.MASK_OVERRIDE bit. If the statement identifier is non-ISPO.NULL then it will be included in the returned byte[].

Parameters:
buf - A buffer supplied by the caller. The buffer will be reset before the value is written on the buffer.
override - true iff you want the StatementEnum.MASK_OVERRIDE bit set (this is only set when serializing values for a remote procedure that will write on the index, it is never set in the index itself).
type - The StatementEnum.
c - The term identifier associated with the context position. This will be included in the returned byte[] value IFF AbstractTripleStore.isStatement(long) returns true for c AND the type is StatementEnum.Explicit.
Returns:
The value that would be written into a statement index for this SPO.

isExplicit

public final boolean isExplicit()
Return true IFF the SPO is marked as StatementEnum.Explicit.

Specified by:
isExplicit in interface ISPO

isInferred

public final boolean isInferred()
Return true IFF the SPO is marked as StatementEnum.Inferred.

Specified by:
isInferred in interface ISPO

isAxiom

public final boolean isAxiom()
Return true IFF the SPO is marked as StatementEnum.Axiom.

Specified by:
isAxiom in interface ISPO

hashCode

public int hashCode()
Hash code for the (s,p,o) per Sesame's Statement.hashCode(). It DOES NOT consider the context position.

Overrides:
hashCode in class Object

compareTo

public int compareTo(SPO stmt2)
Imposes s:p:o ordering based on termIds.

Note: By design, this does NOT differentiate between statements with the different StatementEnum values. FIXME quads : compare [c]?

Specified by:
compareTo in interface Comparable<SPO>

equals

public boolean equals(Object o)
Overrides:
equals in class Object

equals

public boolean equals(ISPO stmt2)
True iff the ISPOs are the same object or if the same term identifiers are assigned for the subject, predicate and object positions, and the same StatementEnum are the same.

Note: This is NOT the same test as BigdataStatementImpl.equals(Object) since the latter is implemented per the Statement interface. FIXME quads : compare [c]?


toString

public String toString()
Return a representation of the statement using the term identifiers (the identifiers are NOT resolved to terms).

Overrides:
toString in class Object
See Also:
ITripleStore#toString(long, long, long)

toString

public static String toString(long id)
Represents the term identifier together with its type (literal, bnode, uri, or statement identifier).

Parameters:
id - The term identifier.
Returns:

toString

public String toString(IRawTripleStore store)
Resolves the term identifiers to terms against the store and returns a representation of the statement using IRawTripleStore.toString(long, long, long).

Specified by:
toString in interface ISPO
Parameters:
store - The store (optional). When non-null the store will be used to resolve term identifiers to terms.
Returns:
The externalized representation of the statement.

isFullyBound

public final boolean isFullyBound()
Description copied from interface: ISPO
Return true iff all position (s,p,o) are non-ISPO.NULL.

Note: SPOs are sometimes used to represent triple patterns, e.g., in the tail of a Justification. This method will return true if the "triple pattern" is fully bound and false if there are any unbound positions.

Note: BigdataStatements are not fully bound when they are instantiated during parsing until their term identifiers have been resolved against a database's lexicon. FIXME quads : this method might need to be aware of the database mode, e.g., pass in [boolean quads]. if its semantics are restricted to whether the triple pattern is fully bound, then clarify that here.

Specified by:
isFullyBound in interface ISPO

getStatementType

public final StatementEnum getStatementType()
Description copied from interface: ISPO
Whether the statement is StatementEnum.Explicit, StatementEnum.Inferred or an StatementEnum.Axiom.

Specified by:
getStatementType in interface ISPO
Returns:
The StatementEnum type -or- null if the statement type has not been specified.

setStatementType

public final void setStatementType(StatementEnum type)
Description copied from interface: ISPO
Set the statement type for this statement.

Specified by:
setStatementType in interface ISPO
Parameters:
type - The statement type.

hasStatementType

public final boolean hasStatementType()
Description copied from interface: ISPO
Return true iff the statement type is known. true iff the statement type is known for this statement.

Specified by:
hasStatementType in interface ISPO


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