Semantic MediaWiki and related extensions
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector Class Reference
Collaboration diagram for SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector:
Collaboration graph
[legend]

Public Member Functions

 __construct (RepositoryClient $repositoryClient, HttpRequest $httpRequest)
 
 getRepositoryClient ()
 
 getDefaultGraph ()
 
 ping ($endpointType=self::EP_TYPE_QUERY)
 
 select ($vars, $where, $options=array(), $extraNamespaces=array())
 
 getSparqlForSelect ($vars, $where, $options=array(), $extraNamespaces=array())
 
 ask ($where, $extraNamespaces=array())
 
 getSparqlForAsk ($where, $extraNamespaces=array())
 
 selectCount ($variable, $where, $options=array(), $extraNamespaces=array())
 
 delete ($deletePattern, $where, $extraNamespaces=array())
 
 deleteContentByValue ($propertyName, $objectName, $extraNamespaces=array())
 
 deleteAll ()
 
 insertDelete ($insertPattern, $deletePattern, $where, $extraNamespaces=array())
 
 insertData ($triples, $extraNamespaces=array())
 
 deleteData ($triples, $extraNamespaces=array())
 
 doQuery ($sparql)
 
 doUpdate ($sparql)
 
 doHttpPost ($payload)
 
 setConnectionTimeoutInSeconds ($timeout=10)
 

Static Public Member Functions

static getPrefixString ($extraNamespaces=array(), $forSparql=true)
 

Public Attributes

const EP_TYPE_QUERY = 1
 
const EP_TYPE_UPDATE = 2
 
const EP_TYPE_DATA = 4
 

Protected Member Functions

 mapHttpRequestError ($endpoint, $sparql)
 

Protected Attributes

 $repositoryClient
 
 $httpRequest
 

Detailed Description

Basic database connector for exchanging data via SPARQL.

GNU GPL v2+

Since
1.6
Author
Markus Krötzsch

Constructor & Destructor Documentation

SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector::__construct ( RepositoryClient  $repositoryClient,
HttpRequest  $httpRequest 
)
Note
It is suggested to use the RepositoryConnectionProvider to create a valid instance
Since
2.2
Parameters
RepositoryClient$repositoryClient
HttpRequest$httpRequest

Member Function Documentation

SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector::ask (   $where,
  $extraNamespaces = array() 
)

ASK wrapper. The function declares the standard namespaces wiki, swivt, rdf, owl, rdfs, property, xsd, so these do not have to be included in $extraNamespaces.

Parameters
$wherestring WHERE part of the query, without surrounding { }
$extraNamespacesarray (associative) of namespaceId => namespaceUri
Returns
RepositoryResult

Implements SMW\SPARQLStore\RepositoryConnection.

SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector::delete (   $deletePattern,
  $where,
  $extraNamespaces = array() 
)

DELETE wrapper. The function declares the standard namespaces wiki, swivt, rdf, owl, rdfs, property, xsd, so these do not have to be included in $extraNamespaces.

Parameters
$deletePatternstring CONSTRUCT pattern of tripples to delete
$wherestring condition for data to delete
$extraNamespacesarray (associative) of namespaceId => namespaceUri
Returns
boolean stating whether the operations succeeded

Implements SMW\SPARQLStore\RepositoryConnection.

SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector::deleteAll ( )

Convenience method for deleting all triples of the entire store

Returns
boolean
SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector::deleteContentByValue (   $propertyName,
  $objectName,
  $extraNamespaces = array() 
)

Convenience method for deleting all triples that have a subject that occurs in a triple with the given property and object. This is used in SMW to delete subobjects with all their data. Some RDF stores fail on complex delete queries, hence a wrapper function is provided to allow more pedestrian implementations.

The function declares the standard namespaces wiki, swivt, rdf, owl, rdfs, property, xsd, so these do not have to be included in $extraNamespaces.

Parameters
$propertyNamestring Turtle name of marking property
$objectNamestring Turtle name of marking object/value
$extraNamespacesarray (associative) of namespaceId => namespaceUri
Returns
boolean stating whether the operations succeeded
SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector::deleteData (   $triples,
  $extraNamespaces = array() 
)

DELETE DATA wrapper. The function declares the standard namespaces wiki, swivt, rdf, owl, rdfs, property, xsd, so these do not have to be included in $extraNamespaces.

Parameters
$triplesstring of triples to delete
$extraNamespacesarray (associative) of namespaceId => namespaceUri
Returns
boolean stating whether the operations succeeded
SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector::doHttpPost (   $payload)

Execute a HTTP-based SPARQL POST request according to http://www.w3.org/2009/sparql/docs/http-rdf-update/. The method throws exceptions based on GenericHttpDatabaseConnector::mapHttpRequestError(). If errors occur and this method does not throw anything, then an empty result with an error code is returned.

Note
This protocol is not part of the SPARQL standard and may not be supported by all stores. To avoid using it, simply do not provide a data endpoint URL when configuring the SPARQL database. If used, the protocol might lead to a better performance since there is less parsing required to fetch the data from the request.
Some stores (e.g. 4Store) support another mode of posting data that may be implemented in a special database handler.
Parameters
$payloadstring Turtle serialization of data to send
Returns
boolean

Implements SMW\SPARQLStore\RepositoryConnection.

SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector::doQuery (   $sparql)

Execute a SPARQL query and return an RepositoryResult object that contains the results. The method throws exceptions based on GenericHttpDatabaseConnector::mapHttpRequestError(). If errors occur and this method does not throw anything, then an empty result with an error code is returned.

Note
This function sets the graph that is to be used as part of the request. Queries should not include additional graph information.
Parameters
$sparqlstring with the complete SPARQL query (SELECT or ASK)
Returns
RepositoryResult

Implements SMW\SPARQLStore\RepositoryConnection.

SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector::doUpdate (   $sparql)

Execute a SPARQL update and return a boolean to indicate if the operations was successful. The method throws exceptions based on GenericHttpDatabaseConnector::mapHttpRequestError(). If errors occur and this method does not throw anything, then false is returned.

Note
When this is written, it is not clear if the update protocol supports a default-graph-uri parameter. Hence the target graph for all updates is generally encoded in the query string and not fixed when sending the query. Direct callers to this function must include the graph information in the queries that they build.
Parameters
$sparqlstring with the complete SPARQL update query (INSERT or DELETE)
Returns
boolean

Implements SMW\SPARQLStore\RepositoryConnection.

SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector::getDefaultGraph ( )

Get the URI of the default graph that this database connector is using, or the empty string if none is used (no graph related statements in queries/updates).

Returns
string graph UIR or empty
static SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector::getPrefixString (   $extraNamespaces = array(),
  $forSparql = true 
)
static

Create the standard PREFIX declarations for SPARQL or Turtle, possibly with additional namespaces involved.

Parameters
$extraNamespacesarray (associative) of namespaceId => namespaceUri
$forSparqlboolean true to use SPARQL prefix syntax, false to use Turtle prefix syntax
Returns
string
SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector::getRepositoryClient ( )
SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector::getSparqlForAsk (   $where,
  $extraNamespaces = array() 
)

Build the SPARQL query that is used by GenericHttpDatabaseConnector::ask(). The function declares the standard namespaces wiki, swivt, rdf, owl, rdfs, property, xsd, so these do not have to be included in $extraNamespaces.

Parameters
$wherestring WHERE part of the query, without surrounding { }
$extraNamespacesarray (associative) of namespaceId => namespaceUri
Returns
string SPARQL query
SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector::getSparqlForSelect (   $vars,
  $where,
  $options = array(),
  $extraNamespaces = array() 
)

Build the SPARQL query that is used by GenericHttpDatabaseConnector::select(). The function declares the standard namespaces wiki, swivt, rdf, owl, rdfs, property, xsd, so these do not have to be included in $extraNamespaces.

Parameters
$wherestring WHERE part of the query, without surrounding { }
$extraNamespacesarray (associative) of namespaceId => namespaceUri
Returns
string SPARQL query
SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector::insertData (   $triples,
  $extraNamespaces = array() 
)

INSERT DATA wrapper. The function declares the standard namespaces wiki, swivt, rdf, owl, rdfs, property, xsd, so these do not have to be included in $extraNamespaces.

Parameters
$triplesstring of triples to insert
$extraNamespacesarray (associative) of namespaceId => namespaceUri
Returns
boolean stating whether the operations succeeded
SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector::insertDelete (   $insertPattern,
  $deletePattern,
  $where,
  $extraNamespaces = array() 
)

INSERT DELETE wrapper. The function declares the standard namespaces wiki, swivt, rdf, owl, rdfs, property, xsd, so these do not have to be included in $extraNamespaces.

Parameters
$insertPatternstring CONSTRUCT pattern of tripples to insert
$deletePatternstring CONSTRUCT pattern of tripples to delete
$wherestring condition for data to delete
$extraNamespacesarray (associative) of namespaceId => namespaceUri
Returns
boolean stating whether the operations succeeded
SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector::mapHttpRequestError (   $endpoint,
  $sparql 
)
protected
Parameters
$endpointstring URL of endpoint that was used
$sparqlstring query that caused the problem
SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector::ping (   $endpointType = self::EP_TYPE_QUERY)

Check if the database can be contacted.

Todo:
SPARQL endpoints sometimes return errors if no (valid) query is posted. The current implementation tries to catch this, but this might not be entirely correct. Especially, the SPARQL 1.1 HTTP error codes for Update are not defined yet (April 15 2011).
Parameters
$pingQueryEndpointboolean true if the query endpoint should be pinged, false if the update endpoint should be pinged
Returns
boolean to indicate success
SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector::select (   $vars,
  $where,
  $options = array(),
  $extraNamespaces = array() 
)

SELECT wrapper. The function declares the standard namespaces wiki, swivt, rdf, owl, rdfs, property, xsd, so these do not have to be included in $extraNamespaces.

Parameters
$varsmixed array or string, field name(s) to be retrieved, can be '*'
$wherestring WHERE part of the query, without surrounding { }
$optionsarray (associative) of options, e.g. array( 'LIMIT' => '10' )
$extraNamespacesarray (associative) of namespaceId => namespaceUri
Returns
RepositoryResult

Implements SMW\SPARQLStore\RepositoryConnection.

SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector::selectCount (   $variable,
  $where,
  $options = array(),
  $extraNamespaces = array() 
)

SELECT wrapper for counting results. The function declares the standard namespaces wiki, swivt, rdf, owl, rdfs, property, xsd, so these do not have to be included in $extraNamespaces.

Parameters
$variablestring variable name or '*'
$wherestring WHERE part of the query, without surrounding { }
$optionsarray (associative) of options, e.g. array('LIMIT' => '10')
$extraNamespacesarray (associative) of namespaceId => namespaceUri
Returns
RepositoryResult
SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector::setConnectionTimeoutInSeconds (   $timeout = 10)
Since
2.0
Parameters
integer$timeout
Returns
SparqlDatabase

Member Data Documentation

SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector::$httpRequest
protected
SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector::$repositoryClient
protected
const SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector::EP_TYPE_DATA = 4

Flag denoting endpoints being capable of SPARQL HTTP graph management

const SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector::EP_TYPE_QUERY = 1

Flag denoting endpoints being capable of querying

const SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector::EP_TYPE_UPDATE = 2

Flag denoting endpoints being capable of updating


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