Exemple #1
0
 /**
  *   Prepares everything for SparqlEngine-usage
  *   Loads the files, creates instances for SparqlEngine and
  *   Dataset...
  *
  *   @return array First value is the sparql engine, second the dataset
  */
 function _prepareSparql()
 {
     require_once RDFAPI_INCLUDE_DIR . 'sparql/SparqlEngine.php';
     require_once RDFAPI_INCLUDE_DIR . 'dataset/DatasetMem.php';
     $dataset = new DatasetMem();
     $dataset->setDefaultGraph($this);
     return array(SparqlEngine::factory($this), $dataset);
 }
 /**
  * tests functions on dataset level
  */
 function testDatatset()
 {
     $_SESSION['test'] = 'Dataset operations tests';
     $quad1 = new Quad(new Resource('http://graph1'), new Resource('http://subject1'), new Resource('http://predicate1'), new Resource('http://object1'));
     $quad2 = new Quad(new Resource('http://graph2'), new Resource('http://subject2'), new Resource('http://predicate2'), new Literal('http://object2'));
     $quad3 = new Quad(new Resource('http://graph3'), new Resource('http://subject3'), new Resource('http://predicate3'), new BlankNode('http://object3'));
     $dataset = new DatasetMem('Dataset1');
     $dataset2 = new DatasetMem('Dataset2');
     $dataset2->addQuad($quad1);
     $dataset2->addQuad($quad2);
     $dataset->addQuad($quad3);
     $dataset->addAll($dataset2);
     $it = $dataset->findInNamedGraphs(null, null, null, null);
     $i = 0;
     while ($it->valid()) {
         $i++;
         $it->next();
     }
     $this->assertEqual(3, $i);
     $this->assertEqual(3, $dataset->countQuads());
     $this->assertTrue($dataset->containsQuad($quad1->getGraphName(), $quad1->getSubject(), $quad1->getPredicate(), $quad1->getObject()));
     $this->assertTrue($dataset->containsQuad($quad2->getGraphName(), $quad2->getSubject(), $quad2->getPredicate(), $quad2->getObject()));
     $this->assertTrue($dataset->containsQuad($quad3->getGraphName(), $quad3->getSubject(), $quad3->getPredicate(), $quad3->getObject()));
     $dataset->removeQuad($quad3);
     $this->assertEqual(2, $dataset->countQuads());
     $this->assertTrue($dataset->containsQuad($quad1->getGraphName(), $quad1->getSubject(), $quad1->getPredicate(), $quad1->getObject()));
     $this->assertTrue($dataset->containsQuad($quad2->getGraphName(), $quad2->getSubject(), $quad2->getPredicate(), $quad2->getObject()));
     $this->assertFalse($dataset->containsQuad($quad3->getGraphName(), $quad3->getSubject(), $quad3->getPredicate(), $quad3->getObject()));
 }
Exemple #3
0
 /**
  * Performs a SPARQL query against a model. The model is converted to
  * an RDF Dataset. The result can be retrived in SPARQL Query Results XML Format or
  * as an array containing the variables an their bindings.
  *
  * @param  String $query      the sparql query string
  * @param  String $resultform the result form ('xml' for SPARQL Query Results XML Format)
  * @return String/array       
  */
 function sparqlQuery($query, $resultform = false)
 {
     include_once RDFAPI_INCLUDE_DIR . PACKAGE_SPARQL;
     include_once RDFAPI_INCLUDE_DIR . PACKAGE_DATASET;
     $dataset = new DatasetMem();
     $dataset->setDefaultGraph($this);
     $parser = new SparqlParser();
     $q = $parser->parse($query);
     $eng = new SparqlEngine();
     return $eng->queryModel($dataset, $q, $resultform);
 }