* Virtuoso as a shortcut for Virtuoso Universal Server later on.
 */
require dirname(__FILE__) . '/../../vendor/autoload.php';
use Saft\Rdf\NamedNodeImpl;
use Saft\Rdf\NodeFactoryImpl;
use Saft\Rdf\StatementFactoryImpl;
use Saft\Rdf\StatementImpl;
use Saft\Rdf\StatementIteratorFactoryImpl;
use Saft\Sparql\Query\QueryFactoryImpl;
use Saft\Sparql\Result\ResultFactoryImpl;
/**
 * Configuration information about how to access Virtuoso.
 */
$config = array('dsn' => 'VOS', 'username' => 'dba', 'password' => 'dba');
// instantiate the store adapter which handles the communication with Virtuoso.
$virtuoso = new Saft\Addition\Virtuoso\Store\Virtuoso(new NodeFactoryImpl(), new StatementFactoryImpl(), new QueryFactoryImpl(), new ResultFactoryImpl(), new StatementIteratorFactoryImpl(), $config);
// create test graph
$virtuoso->createGraph(new NamedNodeImpl('http://saft/test'));
// add simple triple to that new graph
$virtuoso->addStatements(array(new StatementImpl(new NamedNodeImpl('http://saft/test'), new NamedNodeImpl('http://saft/test'), new NamedNodeImpl('http://saft/test'))), new NamedNodeImpl('http://saft/test'));
// ask graph forall its triples and print them out
$setIterator = $virtuoso->query('SELECT ?s FROM <http://saft/test> WHERE {?s ?p ?o}');
foreach ($setIterator as $key => $entry) {
    echo PHP_EOL . $entry['s']->getUri();
    // Saft will check the value of each binding and uses the appropriate Node type.
    // we can use getUri here, because we know that it can only be an URI, but in case
    // you dont know, you can use the following isX methods to determine the type of the
    // binding.
    if ($entry['s']->isNamed()) {
        echo PHP_EOL . 'binding s is a named node.';
        // e.g. NamedNodeImpl
Пример #2
0
<?php

/**
 * This example shows a very basic example of how to use Virtuoso store implementation. We will use
 * Virtuoso as a shortcut for Virtuoso Universal Server later on.
 */
require dirname(__FILE__) . '/../../vendor/autoload.php';
use Saft\Rdf\NodeFactoryImpl;
use Saft\Rdf\StatementFactoryImpl;
use Saft\Rdf\StatementIteratorFactoryImpl;
use Saft\Sparql\Query\QueryFactoryImpl;
use Saft\Sparql\Result\ResultFactoryImpl;
/**
 * Configuration information about how to access Virtuoso.
 */
$config = array('dsn' => 'VOS', 'username' => 'dba', 'password' => 'dba');
// instantiate the store adapter which handles the communication with Virtuoso.
$virtuoso = new Saft\Addition\Virtuoso\Store\Virtuoso(new NodeFactoryImpl(), new StatementFactoryImpl(), new QueryFactoryImpl(), new ResultFactoryImpl(), new StatementIteratorFactoryImpl(), $config);
// output a list of all available graphs
echo 'Available graphs:' . PHP_EOL;
foreach ($virtuoso->getGraphs() as $graph) {
    echo PHP_EOL . '-' . $graph->getUri() . PHP_EOL;
}
// if you dont see a graph in the output, than because there is no one, at least for the public.
// so you should take a look into the conductor and create an example graph.