You are here

public function EasyRdf_Sparql_Client::countTriples in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/easyrdf/easyrdf/lib/EasyRdf/Sparql/Client.php \EasyRdf_Sparql_Client::countTriples()

Count the number of triples in a SPARQL 1.1 endpoint

Performs a SELECT query to estriblish the total number of triples.

Counts total number of triples by default but a conditional triple pattern can be given to count of a subset of all triples.

Parameters

string $condition Triple-pattern condition for the count query:

Return value

integer The number of triples

File

vendor/easyrdf/easyrdf/lib/EasyRdf/Sparql/Client.php, line 133

Class

EasyRdf_Sparql_Client
Class for making SPARQL queries using the SPARQL 1.1 Protocol

Code

public function countTriples($condition = '?s ?p ?o') {

  // SELECT (COUNT(*) AS ?count)
  // WHERE {
  //   {?s ?p ?o}
  //   UNION
  //   {GRAPH ?g {?s ?p ?o}}
  // }
  $result = $this
    ->query('SELECT (COUNT(*) AS ?count) {' . $condition . '}');
  return $result[0]->count
    ->getValue();
}