org.semanticweb.kaon2.api.reasoner
Interface Query


public interface Query

Represents a conjunctive DL-safe query over an ontology. Query objects are not thread-safe; however, you may simultaneously use different query objects on different threads.


Nested Class Summary
static class Query.UntypedPredicate
          Models a predicate whose type is not known.
 
Method Summary
 boolean afterLast()
          Returns true if the current stream is after the last tuple.
 void close()
          Closes the evaluation of the query.
 void dispose()
          Should be callend when the query is not used any more in order to free resources.
 void doNotSortResults()
          Cancels any sorting of the result.
 void executeStoreResults(Ontology resultOntology)
          Executes the query by evaluating the construct pattern and by storing the result into supplied ontology.
 Literal[] getConstructPattern()
          Returns the construct pattern of the query.
 Variable[] getDistinguishedVariables()
          Returns the distinguished variables of the query.
 int getNumberOfTuples()
          Returns the number of tuples in the result.
 Literal[] getQueryLiterals()
          Returns the literals of the query.
 Reasoner getReasoner()
          Returns the reasoner that created the query.
 void interrupt()
          Equivalent to getReasoner().interrupt().
 void next()
          Moves the cursor of the stream to the next position.
 void open()
          Starts the evaluation of the query.
 void setDistinct(boolean distinct)
          Ensures that duplicates are removed from the query result.
 void setLimit(int limit)
          Sets the limit on the number of results returned.
 void setOffset(int offset)
          Sets the number of tuples that are skipped after the query is executed.
 void sortResults(int[] sortedPositions)
          Ensures that the results are sorted.
 void sortResults(int[] sortedPositions, java.util.Comparator[] comparators)
          Ensures that the results are sorted.
 java.lang.Object[] tupleBuffer()
          Returns the buffer containing the current tuple of the operator.
 

Method Detail

dispose

void dispose()
Should be callend when the query is not used any more in order to free resources.


getReasoner

Reasoner getReasoner()
Returns the reasoner that created the query.

Returns:
the reasoner that created the query

getQueryLiterals

Literal[] getQueryLiterals()
Returns the literals of the query.

Returns:
the literals of the query

getDistinguishedVariables

Variable[] getDistinguishedVariables()
Returns the distinguished variables of the query. These are the variables that are returned by the query.

Returns:
the distinguished variables of the query

getConstructPattern

Literal[] getConstructPattern()
Returns the construct pattern of the query.

Returns:
the construct pattern of the query

interrupt

void interrupt()
               throws KAON2Exception
Equivalent to getReasoner().interrupt(). This method is thread-safe.

Throws:
KAON2Exception - thrown if there is an error

setDistinct

void setDistinct(boolean distinct)
                 throws KAON2Exception
Ensures that duplicates are removed from the query result.

Parameters:
distinct - if true, duplicate tuples are removed from the query result
Throws:
KAON2Exception - thrown if there is an error in evaluation

sortResults

void sortResults(int[] sortedPositions,
                 java.util.Comparator[] comparators)
                 throws KAON2Exception
Ensures that the results are sorted. This method cancels the effects of distinctness.

Parameters:
sortedPositions - the positions which are sorted
comparators - the comparators for positions
Throws:
KAON2Exception - thrown if there is an error in evaluation

sortResults

void sortResults(int[] sortedPositions)
                 throws KAON2Exception
Ensures that the results are sorted. Each position is sorted in the natural order.

Parameters:
sortedPositions - the positions which are sorted
Throws:
KAON2Exception - thrown if there is an error in evaluation

doNotSortResults

void doNotSortResults()
                      throws KAON2Exception
Cancels any sorting of the result.

Throws:
KAON2Exception - thrown if there is an error in evaluation

setLimit

void setLimit(int limit)
              throws KAON2Exception
Sets the limit on the number of results returned.

Parameters:
limit - the limit on the number of results returned (-1 cancels any limit)
Throws:
KAON2Exception - thrown if there is an error in evaluation

setOffset

void setOffset(int offset)
               throws KAON2Exception
Sets the number of tuples that are skipped after the query is executed.

Parameters:
offset - the offset (0 cancels any offset)
Throws:
KAON2Exception - thrown if there is an error in evaluation

executeStoreResults

void executeStoreResults(Ontology resultOntology)
                         throws KAON2Exception,
                                java.lang.InterruptedException
Executes the query by evaluating the construct pattern and by storing the result into supplied ontology.

Parameters:
resultOntology - the ontology receiving results
Throws:
KAON2Exception - thrown if there is an error in evaluation
java.lang.InterruptedException - thrown if query evaluation is interrupted

open

void open()
          throws KAON2Exception,
                 java.lang.InterruptedException
Starts the evaluation of the query. Each successful call to this method should be paired with a call to close(); otherwise, one runs a risk of a resource leak.

Throws:
KAON2Exception - thrown if there is an error in evaluation
java.lang.InterruptedException - thrown if query evaluation is interrupted

getNumberOfTuples

int getNumberOfTuples()
                      throws KAON2Exception
Returns the number of tuples in the result. If the query has not been opened, the result is undefined.

Returns:
the number of tuples in the result
Throws:
KAON2Exception - thrown if there is an error

close

void close()
           throws KAON2Exception
Closes the evaluation of the query.

Throws:
KAON2Exception - thrown if there is an error in evaluation

tupleBuffer

java.lang.Object[] tupleBuffer()
                               throws KAON2Exception
Returns the buffer containing the current tuple of the operator. This buffer is owned by the tuple stream, and shouldn't be used otherwise.

Returns:
the tuple buffer
Throws:
KAON2Exception - thrown if there is an error

afterLast

boolean afterLast()
                  throws KAON2Exception
Returns true if the current stream is after the last tuple.

Returns:
true if the stream is after the last tuple
Throws:
KAON2Exception - thrown if there is an error

next

void next()
          throws KAON2Exception,
                 java.lang.InterruptedException
Moves the cursor of the stream to the next position. If the tuple stream is at the end this method call has no effect.

Throws:
KAON2Exception - thrown if there is an error
java.lang.InterruptedException - thrown if query evaluation is interrupted