Conditions | 2 |
Paths | 9 |
Total Lines | 43 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
7 | public function resolve(int $timeout): ?EasyRdf\Resource |
||
8 | { |
||
9 | try { |
||
10 | // unregister the legacy "json" format as it causes problems with CONSTRUCT requests |
||
11 | EasyRdf\Format::unregister('json'); |
||
12 | // change the timeout setting for external requests |
||
13 | $httpclient = EasyRdf\Http::getDefaultHttpClient(); |
||
14 | $httpclient->setConfig(array('timeout' => $timeout, 'useragent' => 'Skosmos')); |
||
15 | $httpclient->setHeaders('Accept', 'text/turtle'); |
||
16 | EasyRdf\Http::setDefaultHttpClient($httpclient); |
||
17 | |||
18 | $uri = $this->uri; |
||
19 | $query = <<<EOQ |
||
20 | PREFIX wd: <http://www.wikidata.org/entity/> |
||
21 | PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> |
||
22 | PREFIX schema: <http://schema.org/> |
||
23 | |||
24 | CONSTRUCT { |
||
25 | <$uri> rdfs:label ?label . |
||
26 | ?link schema:about <$uri> ; |
||
27 | a ?linktype ; |
||
28 | schema:isPartOf ?whole ; |
||
29 | schema:inLanguage ?lang . |
||
30 | } |
||
31 | WHERE |
||
32 | { |
||
33 | { <$uri> rdfs:label ?label } |
||
34 | UNION |
||
35 | { |
||
36 | ?link schema:about <$uri> ; |
||
37 | a ?linktype ; |
||
38 | schema:isPartOf ?whole ; |
||
39 | schema:inLanguage ?lang . |
||
40 | } |
||
41 | } |
||
42 | EOQ; |
||
43 | |||
44 | $client = new EasyRdf\Sparql\Client(self::WDQS_ENDPOINT); |
||
45 | $graph = $client->query($query); |
||
46 | return $graph->resource($this->uri); |
||
47 | } catch (Exception $e) { |
||
48 | $this->model->getLogger()->info("WDQS resolution failed for <{$this->uri}>: $e"); |
||
49 | return null; |
||
50 | } |
||
53 |