This repository has been archived by the owner on Aug 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstoreinit.php
67 lines (52 loc) · 2.16 KB
/
storeinit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace SaftExample;
require("vendor/autoload.php");
use Saft\Store\Store;
use Saft\Rdf\NodeFactory;
use Saft\Rdf\StatementFactory;
use Saft\Sparql\Query\QueryFactory;
use Saft\Sparql\Result\ResultFactory;
$rule = new \Dice\Rule();
$rule->substitutions['Saft\\Rdf\\NodeFactory'] = new \Dice\Instance('Saft\\Rdf\\NodeFactoryImpl');
$rule->substitutions['Saft\\Rdf\\StatementFactory'] = new \Dice\Instance('Saft\\Rdf\\StatementFactoryImpl');
$rule->substitutions['Saft\\Sparql\\Query\\QueryFactory'] = new \Dice\Instance('Saft\\Sparql\\Query\\QueryFactoryImpl');
$rule->substitutions['Saft\\Store\\Result\\ResultFactory'] = new \Dice\Instance('Saft\\Store\\Result\\ResultFactoryImpl');
$dice = new \Dice\Dice();
$dice->addRule('*', $rule);
$params = [['dsn' => 'vos', 'username' => 'dba', 'password' => 'dba']];
$store = $dice->create("Saft\\Addition\\Virtuoso\\Store\\Virtuoso", $params);
//$parser = getParser("turtle");
//$statements = $parser->parseStreamToIterator($fileStream, "http://example.org", "turtle");
class ExampleApplication
{
private $store;
private $nf;
private $sf;
public function __construct(Store $store, NodeFactory $nf, StatementFactory $sf)
{
$this->store = $store;
$this->nf = $nf;
$this->sf = $sf;
}
public function run()
{
$graph = $this->nf->createNamedNode("http://example.org/");
$s = $this->nf->createNamedNode("http://example.org/s");
$p = $this->nf->createNamedNode("http://example.org/p");
$o = $this->nf->createNamedNode("http://example.org/x");
$any = $this->nf->createAnyPattern();
$statement = $this->sf->createStatement($s, $p, $o, $graph);
$this->store->addStatements([$statement]);
// Fetch Data
$pattern = $this->sf->createStatement($s, $p, $any, $graph);
$statements = $this->store->getMatchingStatements($pattern);
foreach ($statements as $select) {
var_dump($select);
}
// Edit Data
//$this->store->deleteMatchingStatements(…);
//$this->store->addStatements(…);
}
}
$app = $dice->create('\\SaftExample\\ExampleApplication', [$store]);
$app->run();