SMWSparqlStoreQueryEngine Class Reference
[SMWStore]

Class mapping SMWQuery objects to SPARQL, and for controlling the execution of these queries to obtain suitable SMWQueryResult objects. More...

List of all members.

Public Member Functions

 __construct (SMWStore $store)
 Constructor.
 getCountQueryResult (SMWQuery $query)
 Get the output number for a query in counting mode.
 getInstanceQueryResult (SMWQuery $query)
 Get the results for a query in instance retrieval mode.
 getDebugQueryResult (SMWQuery $query)
 Get the output string for a query in debugging mode.

Public Attributes

const RESULT_VARIABLE = 'result'
 The name of the SPARQL variable that represents the query result.

Protected Member Functions

 getSparqlConditionString (SMWSparqlCondition &$sparqlCondition)
 Build the condition (WHERE) string for a given SMWSparqlCondition.
 getQueryResultFromSparqlResult (SMWSparqlResultWrapper $sparqlResultWrapper, SMWQuery $query)
 Build an SMWQueryResult object from a SMWSparqlResultWrapper.
 getSparqlCondition (SMWDescription $description)
 Get a SMWSparqlCondition object for an SMWDescription.
 buildSparqlCondition (SMWDescription $description, $joinVariable, $orderByProperty)
 Recursively create an SMWSparqlCondition from an SMWDescription.
 buildConjunctionCondition (SMWConjunction $description, $joinVariable, $orderByProperty)
 Recursively create an SMWSparqlCondition from an SMWConjunction.
 buildDisjunctionCondition (SMWDisjunction $description, $joinVariable, $orderByProperty)
 Recursively create an SMWSparqlCondition from an SMWDisjunction.
 buildPropertyCondition (SMWSomeProperty $description, $joinVariable, $orderByProperty)
 Recursively create an SMWSparqlCondition from an SMWSomeProperty.
 buildClassCondition (SMWClassDescription $description, $joinVariable, $orderByProperty)
 Create an SMWSparqlCondition from an SMWClassDescription.
 buildNamespaceCondition (SMWNamespaceDescription $description, $joinVariable, $orderByProperty)
 Create an SMWSparqlCondition from an SMWNamespaceDescription.
 buildValueCondition (SMWValueDescription $description, $joinVariable, $orderByProperty)
 Create an SMWSparqlCondition from an SMWValueDescription.
 buildTrueCondition ($joinVariable, $orderByProperty)
 Create an SMWSparqlCondition from an empty (true) description.
 getNextVariable ()
 Get a fresh unused variable name for building SPARQL conditions.
 addOrderByDataForProperty (SMWSparqlCondition &$sparqlCondition, $mainVariable, $orderByProperty, $diType=SMWDataItem::TYPE_NOTYPE)
 Extend the given SPARQL condition by a suitable order by variable, if an order by property is set.
 addOrderByData (SMWSparqlCondition &$sparqlCondition, $mainVariable, $diType)
 Extend the given SPARQL condition by a suitable order by variable, possibly adding conditions if required for the type of data.
 addMissingOrderByConditions (SMWSparqlCondition &$sparqlCondition)
 Extend the given SMWSparqlCondition with additional conditions to ensure that it can be ordered by all requested properties.
 getSparqlOptions (SMWQuery $query, SMWSparqlCondition $sparqlCondition)
 Get a SPARQL option array for the given query.

Protected Attributes

 $m_variableCounter = 0
 $m_sortkeys
 $m_store


Detailed Description

Class mapping SMWQuery objects to SPARQL, and for controlling the execution of these queries to obtain suitable SMWQueryResult objects.

Definition at line 237 of file SMW_SparqlStoreQueryEngine.php.


Constructor & Destructor Documentation

SMWSparqlStoreQueryEngine::__construct ( SMWStore store  ) 

Constructor.

Parameters:
$store SMWStore that this object will use

Definition at line 266 of file SMW_SparqlStoreQueryEngine.php.


Member Function Documentation

SMWSparqlStoreQueryEngine::getCountQueryResult ( SMWQuery query  ) 

Get the output number for a query in counting mode.

Parameters:
$query SMWQuery
Returns:
integer

Todo:
Implement error reporting for counting queries.

Definition at line 276 of file SMW_SparqlStoreQueryEngine.php.

References SMWSparqlResultWrapper::ERROR_NOERROR, getSparqlCondition(), getSparqlConditionString(), getSparqlOptions(), and smwfGetSparqlDatabase().

SMWSparqlStoreQueryEngine::getInstanceQueryResult ( SMWQuery query  ) 

Get the results for a query in instance retrieval mode.

Parameters:
$query SMWQuery
Returns:
SMWQueryResult

Definition at line 315 of file SMW_SparqlStoreQueryEngine.php.

References getQueryResultFromSparqlResult(), getSparqlCondition(), getSparqlConditionString(), getSparqlOptions(), and smwfGetSparqlDatabase().

SMWSparqlStoreQueryEngine::getDebugQueryResult ( SMWQuery query  ) 

Get the output string for a query in debugging mode.

Parameters:
$query SMWQuery
Returns:
string

Definition at line 353 of file SMW_SparqlStoreQueryEngine.php.

References SMWStore::formatDebugOutput(), getSparqlCondition(), getSparqlConditionString(), getSparqlOptions(), and smwfGetSparqlDatabase().

SMWSparqlStoreQueryEngine::getSparqlConditionString ( SMWSparqlCondition &$  sparqlCondition  )  [protected]

Build the condition (WHERE) string for a given SMWSparqlCondition.

The function also expresses the single value of SMWSparqlSingletonCondition objects in the condition, which may lead to additional namespaces for serializing its URI.

Parameters:
$sparqlCondition SMWSparqlCondition
Returns:
string

Definition at line 392 of file SMW_SparqlStoreQueryEngine.php.

References SMWSparqlCondition::getCondition(), SMWExporter::getSpecialNsResource(), SMWTurtleSerializer::getTurtleNameForExpElement(), and SMWSparqlCondition::getWeakConditionString().

Referenced by getCountQueryResult(), getDebugQueryResult(), and getInstanceQueryResult().

SMWSparqlStoreQueryEngine::getQueryResultFromSparqlResult ( SMWSparqlResultWrapper sparqlResultWrapper,
SMWQuery query 
) [protected]

Build an SMWQueryResult object from a SMWSparqlResultWrapper.

This function is used to generate instance query results, and the given result wrapper must have an according format (one result column that contains URIs of wiki pages).

Parameters:
$sparqlResultWrapper SMWSparqlResultWrapper
$query SMWQuery, SMWQueryResults hold a reference to original query
Returns:
SMWQueryResult

Definition at line 422 of file SMW_SparqlStoreQueryEngine.php.

References SMWSparqlResultWrapper::ERROR_INCOMPLETE, SMWSparqlResultWrapper::ERROR_NOERROR, and SMWExporter::findDataItemForExpElement().

Referenced by getInstanceQueryResult().

SMWSparqlStoreQueryEngine::getSparqlCondition ( SMWDescription description  )  [protected]

Get a SMWSparqlCondition object for an SMWDescription.

This conversion is implemented by a number of recursive functions, and this is the main entry point for this recursion. In particular, it resets global variables that are used for the construction.

If property value variables should be recorded for ordering results later on, the keys of the respective properties need to be given in m_sortkeys earlier.

Parameters:
$description SMWDescription
Returns:
SMWSparqlCondition

Definition at line 470 of file SMW_SparqlStoreQueryEngine.php.

References addMissingOrderByConditions(), and buildSparqlCondition().

Referenced by getCountQueryResult(), getDebugQueryResult(), and getInstanceQueryResult().

SMWSparqlStoreQueryEngine::buildSparqlCondition ( SMWDescription description,
joinVariable,
orderByProperty 
) [protected]

Recursively create an SMWSparqlCondition from an SMWDescription.

Parameters:
$description SMWDescription
$joinVariable string name of the variable that conditions will refer to
$orderByProperty mixed SMWDIProperty or null, if given then this is the property the values of which this condition will refer to, and the condition should also enable ordering by this value
Returns:
SMWSparqlCondition

TODO Implement concept queries

Definition at line 488 of file SMW_SparqlStoreQueryEngine.php.

References buildClassCondition(), buildConjunctionCondition(), buildDisjunctionCondition(), buildNamespaceCondition(), buildPropertyCondition(), buildTrueCondition(), and buildValueCondition().

Referenced by addMissingOrderByConditions(), buildConjunctionCondition(), buildDisjunctionCondition(), buildPropertyCondition(), and getSparqlCondition().

SMWSparqlStoreQueryEngine::buildConjunctionCondition ( SMWConjunction description,
joinVariable,
orderByProperty 
) [protected]

SMWSparqlStoreQueryEngine::buildDisjunctionCondition ( SMWDisjunction description,
joinVariable,
orderByProperty 
) [protected]

SMWSparqlStoreQueryEngine::buildPropertyCondition ( SMWSomeProperty description,
joinVariable,
orderByProperty 
) [protected]

SMWSparqlStoreQueryEngine::buildClassCondition ( SMWClassDescription description,
joinVariable,
orderByProperty 
) [protected]

SMWSparqlStoreQueryEngine::buildNamespaceCondition ( SMWNamespaceDescription description,
joinVariable,
orderByProperty 
) [protected]

SMWSparqlStoreQueryEngine::buildValueCondition ( SMWValueDescription description,
joinVariable,
orderByProperty 
) [protected]

SMWSparqlStoreQueryEngine::buildTrueCondition ( joinVariable,
orderByProperty 
) [protected]

Create an SMWSparqlCondition from an empty (true) description.

May still require helper conditions for ordering.

Parameters:
$joinVariable string name, see buildSparqlCondition()
$orderByProperty mixed SMWDIProperty or null, see buildSparqlCondition()
Returns:
SMWSparqlCondition

Definition at line 866 of file SMW_SparqlStoreQueryEngine.php.

References addOrderByDataForProperty().

Referenced by buildConjunctionCondition(), buildDisjunctionCondition(), buildSparqlCondition(), and buildValueCondition().

SMWSparqlStoreQueryEngine::getNextVariable (  )  [protected]

Get a fresh unused variable name for building SPARQL conditions.

Returns:
string

Definition at line 877 of file SMW_SparqlStoreQueryEngine.php.

Referenced by buildDisjunctionCondition(), and buildPropertyCondition().

SMWSparqlStoreQueryEngine::addOrderByDataForProperty ( SMWSparqlCondition &$  sparqlCondition,
mainVariable,
orderByProperty,
diType = SMWDataItem::TYPE_NOTYPE 
) [protected]

Extend the given SPARQL condition by a suitable order by variable, if an order by property is set.

Parameters:
SMWSparqlCondition $sparqlCondition condition to modify
string $mainVariable the variable that represents the value to be ordered
mixed $orderByProperty SMWDIProperty or null
integer $diType DataItem type id if known, or SMWDataItem::TYPE_NOTYPE to determine it from the property

Definition at line 890 of file SMW_SparqlStoreQueryEngine.php.

References addOrderByData(), SMWDataValueFactory::getDataItemId(), and SMWDataItem::TYPE_NOTYPE.

Referenced by buildClassCondition(), buildConjunctionCondition(), buildDisjunctionCondition(), buildNamespaceCondition(), buildPropertyCondition(), buildTrueCondition(), and buildValueCondition().

SMWSparqlStoreQueryEngine::addOrderByData ( SMWSparqlCondition &$  sparqlCondition,
mainVariable,
diType 
) [protected]

Extend the given SPARQL condition by a suitable order by variable, possibly adding conditions if required for the type of data.

Parameters:
SMWSparqlCondition $sparqlCondition condition to modify
string $mainVariable the variable that represents the value to be ordered
integer $diType DataItem type id

Definition at line 911 of file SMW_SparqlStoreQueryEngine.php.

References SMWExporter::getSpecialPropertyResource(), and SMWDataItem::TYPE_WIKIPAGE.

Referenced by addMissingOrderByConditions(), addOrderByDataForProperty(), and buildValueCondition().

SMWSparqlStoreQueryEngine::addMissingOrderByConditions ( SMWSparqlCondition &$  sparqlCondition  )  [protected]

Extend the given SMWSparqlCondition with additional conditions to ensure that it can be ordered by all requested properties.

After this operation, every key in m_sortkeys is assigned to a query variable by $sparqlCondition->orderVariables.

Parameters:
SMWSparqlCondition $sparqlCondition condition to modify

Definition at line 930 of file SMW_SparqlStoreQueryEngine.php.

References addOrderByData(), buildSparqlCondition(), SMWSparqlCondition::getWeakConditionString(), and SMWDataItem::TYPE_WIKIPAGE.

Referenced by getSparqlCondition().

SMWSparqlStoreQueryEngine::getSparqlOptions ( SMWQuery query,
SMWSparqlCondition sparqlCondition 
) [protected]

Get a SPARQL option array for the given query.

Parameters:
SMWQuery $query
SMWSparqlCondition $sparqlCondition (storing order by variable names)
Returns:
array

Definition at line 955 of file SMW_SparqlStoreQueryEngine.php.

References $smwgQRandSortingSupport, and $smwgQSortingSupport.

Referenced by getCountQueryResult(), getDebugQueryResult(), and getInstanceQueryResult().


Member Data Documentation

The name of the SPARQL variable that represents the query result.

Definition at line 240 of file SMW_SparqlStoreQueryEngine.php.

SMWSparqlStoreQueryEngine::$m_variableCounter = 0 [protected]

Definition at line 246 of file SMW_SparqlStoreQueryEngine.php.

SMWSparqlStoreQueryEngine::$m_sortkeys [protected]

Definition at line 253 of file SMW_SparqlStoreQueryEngine.php.

SMWSparqlStoreQueryEngine::$m_store [protected]

Definition at line 259 of file SMW_SparqlStoreQueryEngine.php.


The documentation for this class was generated from the following file:

Generated on Sun Mar 18 07:15:43 2012 for Semantic MediaWiki by  doxygen 1.5.6