com.bigdata.rdf.inf
Class BackchainTypeResourceIterator

java.lang.Object
  extended by com.bigdata.rdf.inf.BackchainTypeResourceIterator
All Implemented Interfaces:
IChunkedIterator<ISPO>, IChunkedOrderedIterator<ISPO>, ICloseableIterator<ISPO>, Iterator<ISPO>

public class BackchainTypeResourceIterator
extends Object
implements IChunkedOrderedIterator<ISPO>

Provides backward chaining for (x rdf:type rdfs:Resource).

Note: You only need to do this on read from a high level query language since the rest of the RDFS rules will run correctly without the (x rdf:type rdfs:Resource) entailments being present. Further, you only need to do this when the InferenceEngine was instructed to NOT store the (x rdf:type rdfs:Resource) entailments.

Note: This iterator will NOT generate an inferred (x rdf:type rdfs:Resource) entailment iff there is an explicit statement (x rdf:type rdfs:Resource) in the database.

Version:
$Id: BackchainTypeResourceIterator.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson
See Also:
InferenceEngine, InferenceEngine.Options

Nested Class Summary
static class BackchainTypeResourceIterator.PushbackFilter<E>
          Filterator style construct that allows push back of a single visited element.
static class BackchainTypeResourceIterator.PushbackIterator<E>
          Implementation class for BackchainTypeResourceIterator.PushbackFilter.
 
Field Summary
protected static org.apache.log4j.Logger log
           
protected static long NULL
           
 
Fields inherited from interface com.bigdata.striterator.IChunkedIterator
DEFAULT_CHUNK_SIZE
 
Method Summary
 void close()
          Closes the iterator, releasing any associated resources.
 IKeyOrder<ISPO> getKeyOrder()
          The natural order in which elements are being visited.
 boolean hasNext()
           
static IChunkedOrderedIterator<ISPO> newInstance(IChunkedOrderedIterator<ISPO> _src, IAccessPath<ISPO> accessPath, AbstractTripleStore db, long rdfType, long rdfsResource)
          Returns a suitably configured BackchainTypeResourceIterator -or- src iff the accessPath does not require the materialization of (x rdf:type rdfs:Resource) entailments.
 ISPO next()
          Visits all SPOs visited by the source iterator and then begins to backchain ( x rdf:type: rdfs:Resource ) statements.
 ISPO[] nextChunk()
          Note: This method preserves the IKeyOrder of the source iterator iff it is reported by getKeyOrder().
 ISPO[] nextChunk(IKeyOrder<ISPO> keyOrder)
          Return the next "chunk" of elements.
 void remove()
          Note: You can not "remove" the backchained entailments.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final org.apache.log4j.Logger log

NULL

protected static final transient long NULL
See Also:
Constant Field Values
Method Detail

newInstance

public static IChunkedOrderedIterator<ISPO> newInstance(IChunkedOrderedIterator<ISPO> _src,
                                                        IAccessPath<ISPO> accessPath,
                                                        AbstractTripleStore db,
                                                        long rdfType,
                                                        long rdfsResource)
Returns a suitably configured BackchainTypeResourceIterator -or- src iff the accessPath does not require the materialization of (x rdf:type rdfs:Resource) entailments.

Parameters:
_src - The source iterator. nextChunk() will sort statements into the IKeyOrder reported by this iterator (as long as the IKeyOrder is non-null).
accessPath - The IAccessPath from which the src iterator was derived. Note that src is NOT necessarily equivalent to IAccessPath.iterator() since it MAY have been layered already to backchain other entailments, e.g., owl:sameAs.
db - The database from which we will read the distinct subject identifiers from its SPORelation. This parameter is used iff this is an all unbound triple pattern.
rdfType - The term identifier that corresponds to rdf:Type for the database.
rdfsResource - The term identifier that corresponds to rdf:Resource for the database.
Returns:
The backchain iterator -or- the src iterator iff the accessPath does not require the materialization of (x rdf:type rdfs:Resource) entailments.

getKeyOrder

public IKeyOrder<ISPO> getKeyOrder()
Description copied from interface: IChunkedOrderedIterator
The natural order in which elements are being visited.

Specified by:
getKeyOrder in interface IChunkedOrderedIterator<ISPO>
Returns:
The natural order in which the elements are being visited -or- null if not known.

close

public void close()
Description copied from interface: ICloseableIterator
Closes the iterator, releasing any associated resources. This method MAY be invoked safely if the iterator is already closed.

Note: Implementations that support Iterator.remove() MUST NOT eagerly close the iterator when it is exhausted since that would make it impossible to remove the last visited statement. Instead they MUST wait for an explicit ICloseableIterator.close() by the application.

Specified by:
close in interface ICloseableIterator<ISPO>

hasNext

public boolean hasNext()
Specified by:
hasNext in interface Iterator<ISPO>

next

public ISPO next()
Visits all SPOs visited by the source iterator and then begins to backchain ( x rdf:type: rdfs:Resource ) statements.

The "backchain" scans two iterators: an IChunkedOrderedIterator on ( ? rdf:type rdfs:Resource ) that reads on the database (this tells us whether we have an explicit (x rdf:type rdfs:Resource) in the database for a given subject) and iterator that reads on the term identifiers for the distinct resources in the database (this bounds the #of backchained statements that we will emit).

For each value visited by the resourceIds iterator we examine the statement iterator. If the next value that would be visited by the statement iterator is an explicit statement for the current subject, then we emit the explicit statement. Otherwise we emit an inferred statement.

Specified by:
next in interface IChunkedIterator<ISPO>
Specified by:
next in interface Iterator<ISPO>

nextChunk

public ISPO[] nextChunk()
Note: This method preserves the IKeyOrder of the source iterator iff it is reported by getKeyOrder(). Otherwise chunks read from the source iterator will be in whatever order that iterator is using while chunks containing backchained entailments will be in SPOKeyOrder.POS order.

Note: In order to ensure that a consistent ordering is always used within a chunk the backchained entailments will always begin on a chunk boundary.

Specified by:
nextChunk in interface IChunkedIterator<ISPO>
Returns:
The next chunk.

nextChunk

public ISPO[] nextChunk(IKeyOrder<ISPO> keyOrder)
Description copied from interface: IChunkedOrderedIterator
Return the next "chunk" of elements. The elements will be in the specified order. If IChunkedOrderedIterator.getKeyOrder() would return non-null and the request order corresponds to the value that would be returned by IChunkedOrderedIterator.getKeyOrder() then the elements in the next chunk are NOT sorted. Otherwise the elements in the next chunk are sorted before they are returned. The size of the chunk is up to the implementation.

Specified by:
nextChunk in interface IChunkedOrderedIterator<ISPO>
Parameters:
keyOrder - The natural order for the elements in the chunk.
Returns:
The next chunk of elements in the specified order.

remove

public void remove()
Note: You can not "remove" the backchained entailments. If the last statement visited by next() is "explicit" then the request is delegated to the source iterator.

Specified by:
remove in interface IChunkedIterator<ISPO>
Specified by:
remove in interface Iterator<ISPO>


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