equal
deleted
inserted
replaced
|
1 <?php |
|
2 |
|
3 namespace CorpusParole\Repositories; |
|
4 |
|
5 use Config; |
|
6 use Log; |
|
7 use CorpusParole\Models\Document; |
|
8 |
|
9 /** |
|
10 * Implement the DocumentRepository using EasyRdf |
|
11 */ |
|
12 class RdfDocumentRepository implements DocumentRepository { |
|
13 |
|
14 private $sparqlClient; |
|
15 |
|
16 function __construct() { |
|
17 $this->sparqlClient = new \EasyRdf_Sparql_Client(Config::get('corpusparole.sesame_query_url')); |
|
18 } |
|
19 |
|
20 public function all() { |
|
21 |
|
22 $docs = $this->sparqlClient->query( |
|
23 'SELECT * WHERE {'. |
|
24 ' ?uri <http://xmlns.com/foaf/0.1/primaryTopic> ?b;'. |
|
25 '} ORDER BY ?uri' |
|
26 ); |
|
27 |
|
28 $data = []; |
|
29 |
|
30 foreach ($docs as $doc) { |
|
31 array_push($data, new Document($doc->uri->getUri())); |
|
32 } |
|
33 |
|
34 return $data; |
|
35 } |
|
36 |
|
37 public function get($id) { |
|
38 |
|
39 $doc_uri = Config::get('corpusparole.cocoon_doc_id_base_uri').$id; |
|
40 |
|
41 //$doc = $sparql->query( |
|
42 // "CONSTRUCT {". |
|
43 // " ?doc ?p ?v.". |
|
44 // "}". |
|
45 // "WHERE {". |
|
46 // " <$doc_uri> <http://xmlns.com/foaf/0.1/primaryTopic> ?doc.". |
|
47 // " ?doc ?p ?v;". |
|
48 // "}" |
|
49 //); |
|
50 |
|
51 // We want the CBD (Concise Bounded Description, cf. http://www.w3.org/Submission/CBD/) |
|
52 // WARNING: This seems to work in sesame for our dataset. |
|
53 $doc = $this->sparqlClient->query( |
|
54 'DESCRIBE ?doc '. |
|
55 'WHERE {'. |
|
56 " <$doc_uri> <http://xmlns.com/foaf/0.1/primaryTopic> ?doc;". |
|
57 '}' |
|
58 ); |
|
59 |
|
60 return new Document($doc_uri, $doc); |
|
61 |
|
62 } |
|
63 |
|
64 } |