Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like GenericSparql often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use GenericSparql, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
6 | class GenericSparql { |
||
7 | /** |
||
8 | * A SPARQL Client eg. an EasyRDF instance. |
||
9 | * @property EasyRdf\Sparql\Client $client |
||
10 | */ |
||
11 | protected $client; |
||
12 | /** |
||
13 | * Graph uri. |
||
14 | * @property string $graph |
||
15 | */ |
||
16 | protected $graph; |
||
17 | /** |
||
18 | * A SPARQL query graph part template. |
||
19 | * @property string $graph |
||
20 | */ |
||
21 | protected $graphClause; |
||
22 | /** |
||
23 | * Model instance. |
||
24 | * @property Model $model |
||
25 | */ |
||
26 | protected $model; |
||
27 | |||
28 | /** |
||
29 | * Cache used to avoid expensive shorten() calls |
||
30 | * @property array $qnamecache |
||
31 | */ |
||
32 | private $qnamecache = array(); |
||
33 | |||
34 | /** |
||
35 | * Requires the following three parameters. |
||
36 | * @param string $endpoint SPARQL endpoint address. |
||
37 | * @param string|null $graph Which graph to query: Either an URI, the special value "?graph" |
||
38 | * to use the default graph, or NULL to not use a GRAPH clause. |
||
39 | * @param object $model a Model instance. |
||
40 | */ |
||
41 | public function __construct($endpoint, $graph, $model) { |
||
42 | $this->graph = $graph; |
||
43 | $this->model = $model; |
||
44 | |||
45 | // create the EasyRDF SPARQL client instance to use |
||
46 | $this->initializeHttpClient(); |
||
47 | $this->client = new EasyRdf\Sparql\Client($endpoint); |
||
48 | |||
49 | // set graphClause so that it can be used by all queries |
||
50 | if ($this->isDefaultEndpoint()) // default endpoint; query any graph (and catch it in a variable) |
||
51 | { |
||
52 | $this->graphClause = "GRAPH $graph"; |
||
53 | } elseif ($graph !== null) // query a specific graph |
||
54 | { |
||
55 | $this->graphClause = "GRAPH <$graph>"; |
||
56 | } else // query the default graph |
||
57 | { |
||
58 | $this->graphClause = ""; |
||
59 | } |
||
60 | |||
61 | } |
||
62 | |||
63 | /** |
||
64 | * Returns prefix-definitions for a query |
||
65 | * |
||
66 | * @param string $query |
||
67 | * @return string |
||
68 | */ |
||
69 | protected function generateQueryPrefixes($query) |
||
70 | { |
||
71 | // Check for undefined prefixes |
||
72 | $prefixes = ''; |
||
73 | foreach (EasyRdf\RdfNamespace::namespaces() as $prefix => $uri) { |
||
74 | if (strpos($query, "{$prefix}:") !== false and |
||
75 | strpos($query, "PREFIX {$prefix}:") === false |
||
76 | ) { |
||
77 | $prefixes .= "PREFIX {$prefix}: <{$uri}>\n"; |
||
78 | } |
||
79 | } |
||
80 | return $prefixes; |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * Execute the SPARQL query using the SPARQL client, logging it as well. |
||
85 | * @param string $query SPARQL query to perform |
||
86 | * @return Result|\EasyRdf\Graph query result |
||
87 | */ |
||
88 | protected function query($query) { |
||
89 | $queryId = sprintf("%05d", rand(0, 99999)); |
||
90 | $logger = $this->model->getLogger(); |
||
91 | $logger->info("[qid $queryId] SPARQL query:\n" . $this->generateQueryPrefixes($query) . "\n$query\n"); |
||
92 | $starttime = microtime(true); |
||
93 | $result = $this->client->query($query); |
||
94 | $elapsed = intval(round((microtime(true) - $starttime) * 1000)); |
||
95 | if(method_exists($result, 'numRows')) { |
||
96 | $numRows = $result->numRows(); |
||
|
|||
97 | $logger->info("[qid $queryId] result: $numRows rows returned in $elapsed ms"); |
||
98 | } else { // graph result |
||
99 | $numTriples = $result->countTriples(); |
||
100 | $logger->info("[qid $queryId] result: $numTriples triples returned in $elapsed ms"); |
||
101 | } |
||
102 | return $result; |
||
103 | } |
||
104 | |||
105 | |||
106 | /** |
||
107 | * Generates FROM clauses for the queries |
||
108 | * @param Vocabulary[]|null $vocabs |
||
109 | * @return string |
||
110 | */ |
||
111 | protected function generateFromClause($vocabs=null) { |
||
112 | $clause = ''; |
||
113 | if (!$vocabs) { |
||
114 | return $this->graph !== '?graph' && $this->graph !== NULL ? "FROM <$this->graph>" : ''; |
||
115 | } |
||
116 | $graphs = $this->getVocabGraphs($vocabs); |
||
117 | foreach ($graphs as $graph) { |
||
118 | $clause .= "FROM NAMED <$graph> "; |
||
119 | } |
||
120 | return $clause; |
||
121 | } |
||
122 | |||
123 | protected function initializeHttpClient() { |
||
124 | // configure the HTTP client used by EasyRdf\Sparql\Client |
||
125 | $httpclient = EasyRdf\Http::getDefaultHttpClient(); |
||
126 | $httpclient->setConfig(array('timeout' => $this->model->getConfig()->getSparqlTimeout())); |
||
127 | |||
128 | // if special cache control (typically no-cache) was requested by the |
||
129 | // client, set the same type of cache control headers also in subsequent |
||
130 | // in the SPARQL requests (this is useful for performance testing) |
||
131 | // @codeCoverageIgnoreStart |
||
132 | $cacheControl = filter_input(INPUT_SERVER, 'HTTP_CACHE_CONTROL', FILTER_SANITIZE_STRING); |
||
133 | $pragma = filter_input(INPUT_SERVER, 'HTTP_PRAGMA', FILTER_SANITIZE_STRING); |
||
134 | if ($cacheControl !== null || $pragma !== null) { |
||
135 | $val = $pragma !== null ? $pragma : $cacheControl; |
||
136 | $httpclient->setHeaders('Cache-Control', $val); |
||
137 | } |
||
138 | // @codeCoverageIgnoreEnd |
||
139 | |||
140 | EasyRdf\Http::setDefaultHttpClient($httpclient); // actually redundant.. |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * Return true if this is the default SPARQL endpoint, used as the facade to query |
||
145 | * all vocabularies. |
||
146 | */ |
||
147 | |||
148 | protected function isDefaultEndpoint() { |
||
149 | return !is_null($this->graph) && $this->graph[0] == '?'; |
||
150 | } |
||
151 | |||
152 | /** |
||
153 | * Returns the graph instance |
||
154 | * @return object EasyRDF graph instance. |
||
155 | */ |
||
156 | public function getGraph() { |
||
157 | return $this->graph; |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * Shorten a URI |
||
162 | * @param string $uri URI to shorten |
||
163 | * @return string shortened URI, or original URI if it cannot be shortened |
||
164 | */ |
||
165 | private function shortenUri($uri) { |
||
166 | if (!array_key_exists($uri, $this->qnamecache)) { |
||
167 | $res = new EasyRdf\Resource($uri); |
||
168 | $qname = $res->shorten(); // returns null on failure |
||
169 | $this->qnamecache[$uri] = ($qname !== null) ? $qname : $uri; |
||
170 | } |
||
171 | return $this->qnamecache[$uri]; |
||
172 | } |
||
173 | |||
174 | |||
175 | /** |
||
176 | * Generates the sparql query for retrieving concept and collection counts in a vocabulary. |
||
177 | * @return string sparql query |
||
178 | */ |
||
179 | private function generateCountConceptsQuery($array, $group) { |
||
180 | $fcl = $this->generateFromClause(); |
||
181 | $optional = $array ? "UNION { ?type rdfs:subClassOf* <$array> }" : ''; |
||
182 | $optional .= $group ? "UNION { ?type rdfs:subClassOf* <$group> }" : ''; |
||
183 | $query = <<<EOQ |
||
184 | SELECT (COUNT(?conc) as ?c) ?type ?typelabel $fcl WHERE { |
||
185 | { ?conc a ?type . |
||
186 | { ?type rdfs:subClassOf* skos:Concept . } UNION { ?type rdfs:subClassOf* skos:Collection . } $optional } |
||
187 | OPTIONAL { ?type rdfs:label ?typelabel . } |
||
188 | } |
||
189 | GROUP BY ?type ?typelabel |
||
190 | EOQ; |
||
191 | return $query; |
||
192 | } |
||
193 | |||
194 | /** |
||
195 | * Used for transforming the concept count query results. |
||
196 | * @param EasyRdf\Sparql\Result $result query results to be transformed |
||
197 | * @param string $lang language of labels |
||
198 | * @return Array containing the label counts |
||
199 | */ |
||
200 | private function transformCountConceptsResults($result, $lang) { |
||
201 | $ret = array(); |
||
202 | foreach ($result as $row) { |
||
203 | if (!isset($row->type)) { |
||
204 | continue; |
||
205 | } |
||
206 | $ret[$row->type->getUri()]['type'] = $row->type->getUri(); |
||
207 | $ret[$row->type->getUri()]['count'] = $row->c->getValue(); |
||
208 | if (isset($row->typelabel) && $row->typelabel->getLang() === $lang) { |
||
209 | $ret[$row->type->getUri()]['label'] = $row->typelabel->getValue(); |
||
210 | } |
||
211 | |||
212 | } |
||
213 | return $ret; |
||
214 | } |
||
215 | |||
216 | /** |
||
217 | * Used for counting number of concepts and collections in a vocabulary. |
||
218 | * @param string $lang language of labels |
||
219 | * @return int number of concepts in this vocabulary |
||
220 | */ |
||
221 | public function countConcepts($lang = null, $array = null, $group = null) { |
||
222 | $query = $this->generateCountConceptsQuery($array, $group); |
||
223 | $result = $this->query($query); |
||
224 | return $this->transformCountConceptsResults($result, $lang); |
||
225 | } |
||
226 | |||
227 | /** |
||
228 | * @param array $langs Languages to query for |
||
229 | * @param string[] $props property names |
||
230 | * @return string sparql query |
||
231 | */ |
||
232 | private function generateCountLangConceptsQuery($langs, $classes, $props) { |
||
233 | $gcl = $this->graphClause; |
||
234 | $classes = ($classes) ? $classes : array('http://www.w3.org/2004/02/skos/core#Concept'); |
||
235 | |||
236 | $quote_string = function($val) { return "'$val'"; }; |
||
237 | $quoted_values = array_map($quote_string, $langs); |
||
238 | $langFilter = "FILTER(?lang IN (" . implode(',', $quoted_values) . "))"; |
||
239 | |||
240 | $values = $this->formatValues('?type', $classes, 'uri'); |
||
241 | $valuesProp = $this->formatValues('?prop', $props, null); |
||
242 | |||
243 | $query = <<<EOQ |
||
244 | SELECT ?lang ?prop |
||
245 | (COUNT(?label) as ?count) |
||
246 | WHERE { |
||
247 | $gcl { |
||
248 | $values |
||
249 | $valuesProp |
||
250 | ?conc a ?type . |
||
251 | ?conc ?prop ?label . |
||
252 | BIND(LANG(?label) AS ?lang) |
||
253 | $langFilter |
||
254 | } |
||
255 | } |
||
256 | GROUP BY ?lang ?prop ?type |
||
257 | EOQ; |
||
258 | return $query; |
||
259 | } |
||
260 | |||
261 | /** |
||
262 | * Transforms the CountLangConcepts results into an array of label counts. |
||
263 | * @param EasyRdf\Sparql\Result $result query results to be transformed |
||
264 | * @param array $langs Languages to query for |
||
265 | * @param string[] $props property names |
||
266 | */ |
||
267 | private function transformCountLangConceptsResults($result, $langs, $props) { |
||
268 | $ret = array(); |
||
269 | // set default count to zero; overridden below if query found labels |
||
270 | foreach ($langs as $lang) { |
||
271 | foreach ($props as $prop) { |
||
272 | $ret[$lang][$prop] = 0; |
||
273 | } |
||
274 | } |
||
275 | foreach ($result as $row) { |
||
276 | if (isset($row->lang) && isset($row->prop) && isset($row->count)) { |
||
277 | $ret[$row->lang->getValue()][$row->prop->shorten()] += |
||
278 | $row->count->getValue(); |
||
279 | } |
||
280 | |||
281 | } |
||
282 | ksort($ret); |
||
283 | return $ret; |
||
284 | } |
||
285 | |||
286 | /** |
||
287 | * Counts the number of concepts in a easyRDF graph with a specific language. |
||
288 | * @param array $langs Languages to query for |
||
289 | * @return Array containing count of concepts for each language and property. |
||
290 | */ |
||
291 | public function countLangConcepts($langs, $classes = null) { |
||
292 | $props = array('skos:prefLabel', 'skos:altLabel', 'skos:hiddenLabel'); |
||
293 | $query = $this->generateCountLangConceptsQuery($langs, $classes, $props); |
||
294 | // Count the number of terms in each language |
||
295 | $result = $this->query($query); |
||
296 | return $this->transformCountLangConceptsResults($result, $langs, $props); |
||
297 | } |
||
298 | |||
299 | /** |
||
300 | * Formats a VALUES clause (SPARQL 1.1) which states that the variable should be bound to one |
||
301 | * of the constants given. |
||
302 | * @param string $varname variable name, e.g. "?uri" |
||
303 | * @param array $values the values |
||
304 | * @param string $type type of values: "uri", "literal" or null (determines quoting style) |
||
305 | */ |
||
306 | protected function formatValues($varname, $values, $type = null) { |
||
307 | $constants = array(); |
||
308 | foreach ($values as $val) { |
||
309 | if ($type == 'uri') { |
||
310 | $val = "<$val>"; |
||
311 | } |
||
312 | |||
313 | if ($type == 'literal') { |
||
314 | $val = "'$val'"; |
||
315 | } |
||
316 | |||
317 | $constants[] = "($val)"; |
||
318 | } |
||
319 | $values = implode(" ", $constants); |
||
320 | |||
321 | return "VALUES ($varname) { $values }"; |
||
322 | } |
||
323 | |||
324 | /** |
||
325 | * Filters multiple instances of the same vocabulary from the input array. |
||
326 | * @param \Vocabulary[]|null $vocabs array of Vocabulary objects |
||
327 | * @return \Vocabulary[] |
||
328 | */ |
||
329 | private function filterDuplicateVocabs($vocabs) { |
||
330 | // filtering duplicates |
||
331 | $uniqueVocabs = array(); |
||
332 | if ($vocabs !== null && sizeof($vocabs) > 0) { |
||
333 | foreach ($vocabs as $voc) { |
||
334 | $uniqueVocabs[$voc->getId()] = $voc; |
||
335 | } |
||
336 | } |
||
337 | |||
338 | return $uniqueVocabs; |
||
339 | } |
||
340 | |||
341 | /** |
||
342 | * Generates a sparql query for one or more concept URIs |
||
343 | * @param mixed $uris concept URI (string) or array of URIs |
||
344 | * @param string|null $arrayClass the URI for thesaurus array class, or null if not used |
||
345 | * @param \Vocabulary[]|null $vocabs array of Vocabulary objects |
||
346 | * @return string sparql query |
||
347 | */ |
||
348 | private function generateConceptInfoQuery($uris, $arrayClass, $vocabs) { |
||
349 | $gcl = $this->graphClause; |
||
350 | $fcl = empty($vocabs) ? '' : $this->generateFromClause($vocabs); |
||
351 | $values = $this->formatValues('?uri', $uris, 'uri'); |
||
352 | $uniqueVocabs = $this->filterDuplicateVocabs($vocabs); |
||
353 | $valuesGraph = empty($vocabs) ? $this->formatValuesGraph($uniqueVocabs) : ''; |
||
354 | |||
355 | if ($arrayClass === null) { |
||
356 | $construct = $optional = ""; |
||
357 | } else { |
||
358 | // add information that can be used to format narrower concepts by |
||
359 | // the array they belong to ("milk by source animal" use case) |
||
360 | $construct = "\n ?x skos:member ?o . ?x skos:prefLabel ?xl . ?x a <$arrayClass> ."; |
||
361 | $optional = "\n OPTIONAL { |
||
362 | ?x skos:member ?o . |
||
363 | ?x a <$arrayClass> . |
||
364 | ?x skos:prefLabel ?xl . |
||
365 | FILTER NOT EXISTS { |
||
366 | ?x skos:member ?other . |
||
367 | MINUS { ?other skos:broader ?uri } |
||
368 | } |
||
369 | }"; |
||
370 | } |
||
371 | $query = <<<EOQ |
||
372 | CONSTRUCT { |
||
373 | ?s ?p ?uri . |
||
374 | ?sp ?uri ?op . |
||
375 | ?uri ?p ?o . |
||
376 | ?p rdfs:label ?proplabel . |
||
377 | ?p rdfs:subPropertyOf ?pp . |
||
378 | ?pp rdfs:label ?plabel . |
||
379 | ?o a ?ot . |
||
380 | ?o skos:prefLabel ?opl . |
||
381 | ?o rdfs:label ?ol . |
||
382 | ?o rdf:value ?ov . |
||
383 | ?o skos:notation ?on . |
||
384 | ?o ?oprop ?oval . |
||
385 | ?o ?xlprop ?xlval . |
||
386 | ?directgroup skos:member ?uri . |
||
387 | ?parent skos:member ?group . |
||
388 | ?group skos:prefLabel ?grouplabel . |
||
389 | ?b1 rdf:first ?item . |
||
390 | ?b1 rdf:rest ?b2 . |
||
391 | ?item a ?it . |
||
392 | ?item skos:prefLabel ?il . |
||
393 | ?group a ?grouptype . $construct |
||
394 | } $fcl WHERE { |
||
395 | $values |
||
396 | $gcl { |
||
397 | { |
||
398 | ?s ?p ?uri . |
||
399 | FILTER(!isBlank(?s)) |
||
400 | FILTER(?p != skos:inScheme) |
||
401 | } |
||
402 | UNION |
||
403 | { ?sp ?uri ?op . } |
||
404 | UNION |
||
405 | { |
||
406 | ?directgroup skos:member ?uri . |
||
407 | ?group skos:member+ ?uri . |
||
408 | ?group skos:prefLabel ?grouplabel . |
||
409 | ?group a ?grouptype . |
||
410 | OPTIONAL { ?parent skos:member ?group } |
||
411 | } |
||
412 | UNION |
||
413 | { |
||
414 | ?uri ?p ?o . |
||
415 | OPTIONAL { |
||
416 | ?o rdf:rest* ?b1 . |
||
417 | ?b1 rdf:first ?item . |
||
418 | ?b1 rdf:rest ?b2 . |
||
419 | OPTIONAL { ?item a ?it . } |
||
420 | OPTIONAL { ?item skos:prefLabel ?il . } |
||
421 | } |
||
422 | OPTIONAL { |
||
423 | { ?p rdfs:label ?proplabel . } |
||
424 | UNION |
||
425 | { ?p rdfs:subPropertyOf ?pp . } |
||
426 | } |
||
427 | OPTIONAL { |
||
428 | { ?o a ?ot . } |
||
429 | UNION |
||
430 | { ?o skos:prefLabel ?opl . } |
||
431 | UNION |
||
432 | { ?o rdfs:label ?ol . } |
||
433 | UNION |
||
434 | { ?o rdf:value ?ov . |
||
435 | OPTIONAL { ?o ?oprop ?oval . } |
||
436 | } |
||
437 | UNION |
||
438 | { ?o skos:notation ?on . } |
||
439 | UNION |
||
440 | { ?o a skosxl:Label . |
||
441 | ?o ?xlprop ?xlval } |
||
442 | } $optional |
||
443 | } |
||
444 | } |
||
445 | } |
||
446 | $valuesGraph |
||
447 | EOQ; |
||
448 | return $query; |
||
449 | } |
||
450 | |||
451 | /** |
||
452 | * Transforms ConceptInfo query results into an array of Concept objects |
||
453 | * @param EasyRdf\Graph $result query results to be transformed |
||
454 | * @param array $uris concept URIs |
||
455 | * @param \Vocabulary[] $vocabs array of Vocabulary object |
||
456 | * @param string|null $clang content language |
||
457 | * @return Concept[] array of Concept objects |
||
458 | */ |
||
459 | private function transformConceptInfoResults($result, $uris, $vocabs, $clang) { |
||
460 | $conceptArray = array(); |
||
461 | foreach ($uris as $index => $uri) { |
||
462 | $conc = $result->resource($uri); |
||
463 | $vocab = (isset($vocabs) && sizeof($vocabs) == 1) ? $vocabs[0] : $vocabs[$index]; |
||
464 | $conceptArray[] = new Concept($this->model, $vocab, $conc, $result, $clang); |
||
465 | } |
||
466 | return $conceptArray; |
||
467 | } |
||
468 | |||
469 | /** |
||
470 | * Returns information (as a graph) for one or more concept URIs |
||
471 | * @param mixed $uris concept URI (string) or array of URIs |
||
472 | * @param string|null $arrayClass the URI for thesaurus array class, or null if not used |
||
473 | * @param \Vocabulary[]|null $vocabs vocabularies to target |
||
474 | * @return \EasyRdf\Graph |
||
475 | */ |
||
476 | public function queryConceptInfoGraph($uris, $arrayClass = null, $vocabs = array()) { |
||
477 | // if just a single URI is given, put it in an array regardless |
||
478 | if (!is_array($uris)) { |
||
479 | $uris = array($uris); |
||
480 | } |
||
481 | |||
482 | $query = $this->generateConceptInfoQuery($uris, $arrayClass, $vocabs); |
||
483 | $result = $this->query($query); |
||
484 | return $result; |
||
485 | } |
||
486 | |||
487 | /** |
||
488 | * Returns information (as an array of Concept objects) for one or more concept URIs |
||
489 | * @param mixed $uris concept URI (string) or array of URIs |
||
490 | * @param string|null $arrayClass the URI for thesaurus array class, or null if not used |
||
491 | * @param \Vocabulary[] $vocabs vocabularies to target |
||
492 | * @param string|null $clang content language |
||
493 | * @return Concept[] |
||
494 | */ |
||
495 | public function queryConceptInfo($uris, $arrayClass = null, $vocabs = array(), $clang = null) { |
||
496 | // if just a single URI is given, put it in an array regardless |
||
497 | if (!is_array($uris)) { |
||
498 | $uris = array($uris); |
||
499 | } |
||
500 | $result = $this->queryConceptInfoGraph($uris, $arrayClass, $vocabs); |
||
501 | if ($result->isEmpty()) { |
||
502 | return []; |
||
503 | } |
||
504 | return $this->transformConceptInfoResults($result, $uris, $vocabs, $clang); |
||
505 | } |
||
506 | |||
507 | /** |
||
508 | * Generates the sparql query for queryTypes |
||
509 | * @param string $lang |
||
510 | * @return string sparql query |
||
511 | */ |
||
512 | private function generateQueryTypesQuery($lang) { |
||
513 | $fcl = $this->generateFromClause(); |
||
514 | $query = <<<EOQ |
||
515 | SELECT DISTINCT ?type ?label ?superclass $fcl |
||
516 | WHERE { |
||
517 | { |
||
518 | { BIND( skos:Concept as ?type ) } |
||
519 | UNION |
||
520 | { BIND( skos:Collection as ?type ) } |
||
521 | UNION |
||
522 | { BIND( isothes:ConceptGroup as ?type ) } |
||
523 | UNION |
||
524 | { BIND( isothes:ThesaurusArray as ?type ) } |
||
525 | UNION |
||
526 | { ?type rdfs:subClassOf/rdfs:subClassOf* skos:Concept . } |
||
527 | UNION |
||
528 | { ?type rdfs:subClassOf/rdfs:subClassOf* skos:Collection . } |
||
529 | } |
||
530 | OPTIONAL { |
||
531 | ?type rdfs:label ?label . |
||
532 | FILTER(langMatches(lang(?label), '$lang')) |
||
533 | } |
||
534 | OPTIONAL { |
||
535 | ?type rdfs:subClassOf ?superclass . |
||
536 | } |
||
537 | FILTER EXISTS { |
||
538 | ?s a ?type . |
||
539 | ?s skos:prefLabel ?prefLabel . |
||
540 | } |
||
541 | } |
||
542 | EOQ; |
||
543 | return $query; |
||
544 | } |
||
545 | |||
546 | /** |
||
547 | * Transforms the results into an array format. |
||
548 | * @param EasyRdf\Sparql\Result $result |
||
549 | * @return array Array with URIs (string) as key and array of (label, superclassURI) as value |
||
550 | */ |
||
551 | View Code Duplication | private function transformQueryTypesResults($result) { |
|
552 | $ret = array(); |
||
553 | foreach ($result as $row) { |
||
554 | $type = array(); |
||
555 | if (isset($row->label)) { |
||
556 | $type['label'] = $row->label->getValue(); |
||
557 | } |
||
558 | |||
559 | if (isset($row->superclass)) { |
||
560 | $type['superclass'] = $row->superclass->getUri(); |
||
561 | } |
||
562 | |||
563 | $ret[$row->type->getURI()] = $type; |
||
564 | } |
||
565 | return $ret; |
||
566 | } |
||
567 | |||
568 | /** |
||
569 | * Retrieve information about types from the endpoint |
||
570 | * @param string $lang |
||
571 | * @return array Array with URIs (string) as key and array of (label, superclassURI) as value |
||
572 | */ |
||
573 | public function queryTypes($lang) { |
||
574 | $query = $this->generateQueryTypesQuery($lang); |
||
575 | $result = $this->query($query); |
||
576 | return $this->transformQueryTypesResults($result); |
||
577 | } |
||
578 | |||
579 | /** |
||
580 | * Generates the concept scheme query. |
||
581 | * @param string $conceptscheme concept scheme URI |
||
582 | * @return string sparql query |
||
583 | */ |
||
584 | private function generateQueryConceptSchemeQuery($conceptscheme) { |
||
585 | $fcl = $this->generateFromClause(); |
||
586 | $query = <<<EOQ |
||
587 | CONSTRUCT { |
||
588 | <$conceptscheme> ?property ?value . |
||
589 | } $fcl WHERE { |
||
590 | <$conceptscheme> ?property ?value . |
||
591 | FILTER (?property != skos:hasTopConcept) |
||
592 | } |
||
593 | EOQ; |
||
594 | return $query; |
||
595 | } |
||
596 | |||
597 | /** |
||
598 | * Retrieves conceptScheme information from the endpoint. |
||
599 | * @param string $conceptscheme concept scheme URI |
||
600 | * @return EasyRDF_Graph query result graph |
||
601 | */ |
||
602 | public function queryConceptScheme($conceptscheme) { |
||
603 | $query = $this->generateQueryConceptSchemeQuery($conceptscheme); |
||
604 | return $this->query($query); |
||
605 | } |
||
606 | |||
607 | /** |
||
608 | * Generates the queryConceptSchemes sparql query. |
||
609 | * @param string $lang language of labels |
||
610 | * @return string sparql query |
||
611 | */ |
||
612 | private function generateQueryConceptSchemesQuery($lang) { |
||
613 | $fcl = $this->generateFromClause(); |
||
614 | $query = <<<EOQ |
||
615 | SELECT ?cs ?label ?preflabel ?title ?domain ?domainLabel $fcl |
||
616 | WHERE { |
||
617 | ?cs a skos:ConceptScheme . |
||
618 | OPTIONAL{ |
||
619 | ?cs dcterms:subject ?domain. |
||
620 | ?domain skos:prefLabel ?domainLabel. |
||
621 | FILTER(langMatches(lang(?domainLabel), '$lang')) |
||
622 | } |
||
623 | OPTIONAL { |
||
624 | ?cs rdfs:label ?label . |
||
625 | FILTER(langMatches(lang(?label), '$lang')) |
||
626 | } |
||
627 | OPTIONAL { |
||
628 | ?cs skos:prefLabel ?preflabel . |
||
629 | FILTER(langMatches(lang(?preflabel), '$lang')) |
||
630 | } |
||
631 | OPTIONAL { |
||
632 | { ?cs dc11:title ?title } |
||
633 | UNION |
||
634 | { ?cs dc:title ?title } |
||
635 | FILTER(langMatches(lang(?title), '$lang')) |
||
636 | } |
||
637 | } |
||
638 | ORDER BY ?cs |
||
639 | EOQ; |
||
640 | return $query; |
||
641 | } |
||
642 | |||
643 | /** |
||
644 | * Transforms the queryConceptScheme results into an array format. |
||
645 | * @param EasyRdf\Sparql\Result $result |
||
646 | * @return array |
||
647 | */ |
||
648 | private function transformQueryConceptSchemesResults($result) { |
||
649 | $ret = array(); |
||
650 | foreach ($result as $row) { |
||
651 | $conceptscheme = array(); |
||
652 | if (isset($row->label)) { |
||
653 | $conceptscheme['label'] = $row->label->getValue(); |
||
654 | } |
||
655 | |||
656 | if (isset($row->preflabel)) { |
||
657 | $conceptscheme['prefLabel'] = $row->preflabel->getValue(); |
||
658 | } |
||
659 | |||
660 | if (isset($row->title)) { |
||
661 | $conceptscheme['title'] = $row->title->getValue(); |
||
662 | } |
||
663 | // add dct:subject and their labels in the result |
||
664 | if(isset($row->domain) && isset($row->domainLabel)){ |
||
665 | $conceptscheme['subject']['uri']=$row->domain->getURI(); |
||
666 | $conceptscheme['subject']['prefLabel']=$row->domainLabel->getValue(); |
||
667 | } |
||
668 | |||
669 | $ret[$row->cs->getURI()] = $conceptscheme; |
||
670 | } |
||
671 | return $ret; |
||
672 | } |
||
673 | |||
674 | /** |
||
675 | * return a list of skos:ConceptScheme instances in the given graph |
||
676 | * @param string $lang language of labels |
||
677 | * @return array Array with concept scheme URIs (string) as keys and labels (string) as values |
||
678 | */ |
||
679 | public function queryConceptSchemes($lang) { |
||
680 | $query = $this->generateQueryConceptSchemesQuery($lang); |
||
681 | $result = $this->query($query); |
||
682 | return $this->transformQueryConceptSchemesResults($result); |
||
683 | } |
||
684 | |||
685 | /** |
||
686 | * Generate a VALUES clause for limiting the targeted graphs. |
||
687 | * @param Vocabulary[]|null $vocabs the vocabularies to target |
||
688 | * @return string[] array of graph URIs |
||
689 | */ |
||
690 | protected function getVocabGraphs($vocabs) { |
||
691 | if ($vocabs === null || sizeof($vocabs) == 0) { |
||
692 | // searching from all vocabularies - limit to known graphs |
||
693 | $vocabs = $this->model->getVocabularies(); |
||
694 | } |
||
695 | $graphs = array(); |
||
696 | foreach ($vocabs as $voc) { |
||
697 | $graph = $voc->getGraph(); |
||
698 | if (!is_null($graph) && !in_array($graph, $graphs)) { |
||
699 | $graphs[] = $graph; |
||
700 | } |
||
701 | } |
||
702 | return $graphs; |
||
703 | } |
||
704 | |||
705 | /** |
||
706 | * Generate a VALUES clause for limiting the targeted graphs. |
||
707 | * @param Vocabulary[]|null $vocabs array of Vocabulary objects to target |
||
708 | * @return string VALUES clause, or "" if not necessary to limit |
||
709 | */ |
||
710 | protected function formatValuesGraph($vocabs) { |
||
717 | |||
718 | /** |
||
719 | * Generate a FILTER clause for limiting the targeted graphs. |
||
720 | * @param array $vocabs array of Vocabulary objects to target |
||
721 | * @return string FILTER clause, or "" if not necessary to limit |
||
722 | */ |
||
723 | protected function formatFilterGraph($vocabs) { |
||
724 | if (!$this->isDefaultEndpoint()) { |
||
725 | return ""; |
||
726 | } |
||
727 | $graphs = $this->getVocabGraphs($vocabs); |
||
728 | $values = array(); |
||
729 | foreach ($graphs as $graph) { |
||
730 | $values[] = "<$graph>"; |
||
731 | } |
||
732 | if (count($values)) { |
||
733 | return "FILTER (?graph IN (" . implode(',', $values) . "))"; |
||
734 | } |
||
735 | } |
||
736 | |||
737 | /** |
||
738 | * Formats combined limit and offset clauses for the sparql query |
||
739 | * @param int $limit maximum number of hits to retrieve; 0 for unlimited |
||
740 | * @param int $offset offset of results to retrieve; 0 for beginning of list |
||
741 | * @return string sparql query clauses |
||
742 | */ |
||
743 | protected function formatLimitAndOffset($limit, $offset) { |
||
744 | $limit = ($limit) ? 'LIMIT ' . $limit : ''; |
||
745 | $offset = ($offset) ? 'OFFSET ' . $offset : ''; |
||
746 | // eliminating whitespace and line changes when the conditions aren't needed. |
||
747 | $limitandoffset = ''; |
||
758 | |||
759 | /** |
||
760 | * Formats a sparql query clause for limiting the search to specific concept types. |
||
761 | * @param array $types limit search to concepts of the given type(s) |
||
762 | * @return string sparql query clause |
||
763 | */ |
||
764 | protected function formatTypes($types) { |
||
775 | |||
776 | /** |
||
777 | * @param string $prop property to include in the result eg. 'broader' or 'narrower' |
||
778 | * @return string sparql query clause |
||
779 | */ |
||
780 | private function formatPropertyCsvClause($prop) { |
||
792 | |||
793 | /** |
||
794 | * @return string sparql query clause |
||
795 | */ |
||
796 | private function formatPrefLabelCsvClause() { |
||
806 | |||
807 | /** |
||
808 | * @param string $lang language code of the returned labels |
||
809 | * @param array|null $fields extra fields to include in the result (array of strings). (default: null = none) |
||
810 | * @return string sparql query clause |
||
811 | */ |
||
812 | protected function formatExtraFields($lang, $fields) { |
||
844 | |||
845 | /** |
||
846 | * Generate condition for matching labels in SPARQL |
||
847 | * @param string $term search term |
||
848 | * @param string $searchLang language code used for matching labels (null means any language) |
||
849 | * @return string sparql query snippet |
||
850 | */ |
||
851 | protected function generateConceptSearchQueryCondition($term, $searchLang) |
||
880 | |||
881 | |||
882 | /** |
||
883 | * Inner query for concepts using a search term. |
||
884 | * @param string $term search term |
||
885 | * @param string $lang language code of the returned labels |
||
886 | * @param string $searchLang language code used for matching labels (null means any language) |
||
887 | * @param string[] $props properties to target e.g. array('skos:prefLabel','skos:altLabel') |
||
888 | * @param boolean $unique restrict results to unique concepts (default: false) |
||
889 | * @return string sparql query |
||
890 | */ |
||
891 | protected function generateConceptSearchQueryInner($term, $lang, $searchLang, $props, $unique, $filterGraph) |
||
953 | |||
954 | /** |
||
955 | * Query for concepts using a search term. |
||
956 | * @param array|null $fields extra fields to include in the result (array of strings). (default: null = none) |
||
957 | * @param boolean $unique restrict results to unique concepts (default: false) |
||
958 | * @param boolean $showDeprecated whether to include deprecated concepts in search results (default: false) |
||
959 | * @param ConceptSearchParameters $params |
||
960 | * @return string sparql query |
||
961 | */ |
||
962 | protected function generateConceptSearchQuery($fields, $unique, $params, $showDeprecated = false) { |
||
1042 | |||
1043 | /** |
||
1044 | * Transform a single concept search query results into the skosmos desired return format. |
||
1045 | * @param $row SPARQL query result row |
||
1046 | * @param array $vocabs array of Vocabulary objects to search; empty for global search |
||
1047 | * @return array query result object |
||
1048 | */ |
||
1049 | private function transformConceptSearchResult($row, $vocabs, $fields) |
||
1125 | |||
1126 | /** |
||
1127 | * Transform the concept search query results into the skosmos desired return format. |
||
1128 | * @param EasyRdf\Sparql\Result $results |
||
1129 | * @param array $vocabs array of Vocabulary objects to search; empty for global search |
||
1130 | * @return array query result object |
||
1131 | */ |
||
1132 | private function transformConceptSearchResults($results, $vocabs, $fields) { |
||
1144 | |||
1145 | /** |
||
1146 | * Query for concepts using a search term. |
||
1147 | * @param array $vocabs array of Vocabulary objects to search; empty for global search |
||
1148 | * @param array $fields extra fields to include in the result (array of strings). (default: null = none) |
||
1149 | * @param boolean $unique restrict results to unique concepts (default: false) |
||
1150 | * @param boolean $showDeprecated whether to include deprecated concepts in the result (default: false) |
||
1151 | * @param ConceptSearchParameters $params |
||
1152 | * @return array query result object |
||
1153 | */ |
||
1154 | public function queryConcepts($vocabs, $fields = null, $unique = false, $params, $showDeprecated = false) { |
||
1159 | |||
1160 | /** |
||
1161 | * Generates sparql query clauses used for creating the alphabetical index. |
||
1162 | * @param string $letter the letter (or special class) to search for |
||
1163 | * @return array of sparql query clause strings |
||
1164 | */ |
||
1165 | private function formatFilterConditions($letter, $lang) { |
||
1190 | |||
1191 | /** |
||
1192 | * Generates the sparql query used for rendering the alphabetical index. |
||
1193 | * @param string $letter the letter (or special class) to search for |
||
1194 | * @param string $lang language of labels |
||
1195 | * @param integer $limit limits the amount of results |
||
1196 | * @param integer $offset offsets the result set |
||
1197 | * @param array|null $classes |
||
1198 | * @param boolean $showDeprecated whether to include deprecated concepts in the result (default: false) |
||
1199 | * @param \EasyRdf\Resource|null $qualifier alphabetical list qualifier resource or null (default: null) |
||
1200 | * @return string sparql query |
||
1201 | */ |
||
1202 | protected function generateAlphabeticalListQuery($letter, $lang, $limit, $offset, $classes, $showDeprecated = false, $qualifier = null) { |
||
1246 | |||
1247 | /** |
||
1248 | * Transforms the alphabetical list query results into an array format. |
||
1249 | * @param EasyRdf\Sparql\Result $results |
||
1250 | * @return array |
||
1251 | */ |
||
1252 | private function transformAlphabeticalListResults($results) { |
||
1288 | |||
1289 | /** |
||
1290 | * Query for concepts with a term starting with the given letter. Also special classes '0-9' (digits), |
||
1291 | * '*!' (special characters) and '*' (everything) are accepted. |
||
1292 | * @param string $letter the letter (or special class) to search for |
||
1293 | * @param string $lang language of labels |
||
1294 | * @param integer $limit limits the amount of results |
||
1295 | * @param integer $offset offsets the result set |
||
1296 | * @param array $classes |
||
1297 | * @param boolean $showDeprecated whether to include deprecated concepts in the result (default: false) |
||
1298 | * @param \EasyRdf\Resource|null $qualifier alphabetical list qualifier resource or null (default: null) |
||
1299 | */ |
||
1300 | public function queryConceptsAlphabetical($letter, $lang, $limit = null, $offset = null, $classes = null, $showDeprecated = false, $qualifier = null) { |
||
1305 | |||
1306 | /** |
||
1307 | * Creates the query used for finding out which letters should be displayed in the alphabetical index. |
||
1308 | * Note that we force the datatype of the result variable otherwise Virtuoso does not properly interpret the DISTINCT and we have duplicated results |
||
1309 | * @param string $lang language |
||
1310 | * @return string sparql query |
||
1311 | */ |
||
1312 | private function generateFirstCharactersQuery($lang, $classes) { |
||
1326 | |||
1327 | /** |
||
1328 | * Transforms the first characters query results into an array format. |
||
1329 | * @param EasyRdf\Sparql\Result $result |
||
1330 | * @return array |
||
1331 | */ |
||
1332 | private function transformFirstCharactersResults($result) { |
||
1339 | |||
1340 | /** |
||
1341 | * Query for the first characters (letter or otherwise) of the labels in the particular language. |
||
1342 | * @param string $lang language |
||
1343 | * @return array array of characters |
||
1344 | */ |
||
1345 | public function queryFirstCharacters($lang, $classes = null) { |
||
1350 | |||
1351 | /** |
||
1352 | * @param string $uri |
||
1353 | * @param string $lang |
||
1354 | * @return string sparql query string |
||
1355 | */ |
||
1356 | private function generateLabelQuery($uri, $lang) { |
||
1383 | |||
1384 | /** |
||
1385 | * Query for a label (skos:prefLabel, rdfs:label, dc:title, dc11:title) of a resource. |
||
1386 | * @param string $uri |
||
1387 | * @param string $lang |
||
1388 | * @return array array of labels (key: lang, val: label), or null if resource doesn't exist |
||
1389 | */ |
||
1390 | View Code Duplication | public function queryLabel($uri, $lang) { |
|
1410 | |||
1411 | /** |
||
1412 | * Generates a SPARQL query to retrieve the super properties of a given property URI. |
||
1413 | * Note this must be executed in the graph where this information is available. |
||
1414 | * @param string $uri |
||
1415 | * @return string sparql query string |
||
1416 | */ |
||
1417 | private function generateSubPropertyOfQuery($uri) { |
||
1427 | |||
1428 | /** |
||
1429 | * Query the super properties of a provided property URI. |
||
1430 | * @param string $uri URI of a propertyes |
||
1431 | * @return array array super properties, or null if none exist |
||
1432 | */ |
||
1433 | View Code Duplication | public function querySuperProperties($uri) { |
|
1452 | |||
1453 | |||
1454 | /** |
||
1455 | * Generates a sparql query for queryNotation. |
||
1456 | * @param string $uri |
||
1457 | * @return string sparql query |
||
1458 | */ |
||
1459 | private function generateNotationQuery($uri) { |
||
1470 | |||
1471 | /** |
||
1472 | * Query for the notation of the concept (skos:notation) of a resource. |
||
1473 | * @param string $uri |
||
1474 | * @return string notation or null if it doesn't exist |
||
1475 | */ |
||
1476 | public function queryNotation($uri) { |
||
1486 | |||
1487 | /** |
||
1488 | * Generates a sparql query for queryProperty. |
||
1489 | * @param string $uri |
||
1490 | * @param string $prop the name of the property eg. 'skos:broader'. |
||
1491 | * @param string $lang |
||
1492 | * @param boolean $anylang if you want a label even when it isn't available in the language you requested. |
||
1493 | * @return string sparql query |
||
1494 | */ |
||
1495 | View Code Duplication | private function generatePropertyQuery($uri, $prop, $lang, $anylang) { |
|
1519 | |||
1520 | /** |
||
1521 | * Transforms the sparql query result into an array or null if the concept doesn't exist. |
||
1522 | * @param EasyRdf\Sparql\Result $result |
||
1523 | * @param string $lang |
||
1524 | * @return array array of property values (key: URI, val: label), or null if concept doesn't exist |
||
1525 | */ |
||
1526 | private function transformPropertyQueryResults($result, $lang) { |
||
1551 | |||
1552 | /** |
||
1553 | * Query a single property of a concept. |
||
1554 | * @param string $uri |
||
1555 | * @param string $prop the name of the property eg. 'skos:broader'. |
||
1556 | * @param string $lang |
||
1557 | * @param boolean $anylang if you want a label even when it isn't available in the language you requested. |
||
1558 | * @return array array of property values (key: URI, val: label), or null if concept doesn't exist |
||
1559 | */ |
||
1560 | public function queryProperty($uri, $prop, $lang, $anylang = false) { |
||
1566 | |||
1567 | /** |
||
1568 | * Query a single transitive property of a concept. |
||
1569 | * @param string $uri |
||
1570 | * @param array $props the name of the property eg. 'skos:broader'. |
||
1571 | * @param string $lang |
||
1572 | * @param integer $limit |
||
1573 | * @param boolean $anylang if you want a label even when it isn't available in the language you requested. |
||
1574 | * @return string sparql query |
||
1575 | */ |
||
1576 | private function generateTransitivePropertyQuery($uri, $props, $lang, $limit, $anylang) { |
||
1607 | |||
1608 | /** |
||
1609 | * Transforms the sparql query result object into an array. |
||
1610 | * @param EasyRdf\Sparql\Result $result |
||
1611 | * @param string $lang |
||
1612 | * @param string $fallbacklang language to use if label is not available in the preferred language |
||
1613 | * @return array of property values (key: URI, val: label), or null if concept doesn't exist |
||
1614 | */ |
||
1615 | private function transformTransitivePropertyResults($result, $lang, $fallbacklang) { |
||
1661 | |||
1662 | /** |
||
1663 | * Query a single transitive property of a concept. |
||
1664 | * @param string $uri |
||
1665 | * @param array $props the property/properties. |
||
1666 | * @param string $lang |
||
1667 | * @param string $fallbacklang language to use if label is not available in the preferred language |
||
1668 | * @param integer $limit |
||
1669 | * @param boolean $anylang if you want a label even when it isn't available in the language you requested. |
||
1670 | * @return array array of property values (key: URI, val: label), or null if concept doesn't exist |
||
1671 | */ |
||
1672 | public function queryTransitiveProperty($uri, $props, $lang, $limit, $anylang = false, $fallbacklang = '') { |
||
1677 | |||
1678 | /** |
||
1679 | * Generates the query for a concepts skos:narrowers. |
||
1680 | * @param string $uri |
||
1681 | * @param string $lang |
||
1682 | * @param string $fallback |
||
1683 | * @return string sparql query |
||
1684 | */ |
||
1685 | private function generateChildQuery($uri, $lang, $fallback, $props) { |
||
1714 | |||
1715 | /** |
||
1716 | * Transforms the sparql result object into an array. |
||
1717 | * @param EasyRdf\Sparql\Result $result |
||
1718 | * @param string $lang |
||
1719 | * @return array array of arrays describing each child concept, or null if concept doesn't exist |
||
1720 | */ |
||
1721 | private function transformNarrowerResults($result, $lang) { |
||
1758 | |||
1759 | /** |
||
1760 | * Query the narrower concepts of a concept. |
||
1761 | * @param string $uri |
||
1762 | * @param string $lang |
||
1763 | * @param string $fallback |
||
1764 | * @return array array of arrays describing each child concept, or null if concept doesn't exist |
||
1765 | */ |
||
1766 | public function queryChildren($uri, $lang, $fallback, $props) { |
||
1771 | |||
1772 | /** |
||
1773 | * Query the top concepts of a vocabulary. |
||
1774 | * @param string $conceptSchemes concept schemes whose top concepts to query for |
||
1775 | * @param string $lang language of labels |
||
1776 | * @param string $fallback language to use if label is not available in the preferred language |
||
1777 | */ |
||
1778 | public function queryTopConcepts($conceptSchemes, $lang, $fallback) { |
||
1824 | |||
1825 | /** |
||
1826 | * Generates a sparql query for finding the hierarchy for a concept. |
||
1827 | * A concept may be a top concept in multiple schemes, returned as a single whitespace-separated literal. |
||
1828 | * @param string $uri concept uri. |
||
1829 | * @param string $lang |
||
1830 | * @param string $fallback language to use if label is not available in the preferred language |
||
1831 | * @return string sparql query |
||
1832 | */ |
||
1833 | private function generateParentListQuery($uri, $lang, $fallback, $props) { |
||
1881 | |||
1882 | /** |
||
1883 | * Transforms the result into an array. |
||
1884 | * @param EasyRdf\Sparql\Result |
||
1885 | * @param string $lang |
||
1886 | * @return an array for the REST controller to encode. |
||
1887 | */ |
||
1888 | private function transformParentListResults($result, $lang) |
||
1964 | |||
1965 | /** |
||
1966 | * Query for finding the hierarchy for a concept. |
||
1967 | * @param string $uri concept uri. |
||
1968 | * @param string $lang |
||
1969 | * @param string $fallback language to use if label is not available in the preferred language |
||
1970 | * @param array $props the hierarchy property/properties to use |
||
1971 | * @return an array for the REST controller to encode. |
||
1972 | */ |
||
1973 | public function queryParentList($uri, $lang, $fallback, $props) { |
||
1978 | |||
1979 | /** |
||
1980 | * return a list of concept group instances, sorted by label |
||
1981 | * @param string $groupClass URI of concept group class |
||
1982 | * @param string $lang language of labels to return |
||
1983 | * @return string sparql query |
||
1984 | */ |
||
1985 | private function generateConceptGroupsQuery($groupClass, $lang) { |
||
2004 | |||
2005 | /** |
||
2006 | * Transforms the sparql query result into an array. |
||
2007 | * @param EasyRdf\Sparql\Result $result |
||
2008 | * @return array |
||
2009 | */ |
||
2010 | private function transformConceptGroupsResults($result) { |
||
2038 | |||
2039 | /** |
||
2040 | * return a list of concept group instances, sorted by label |
||
2041 | * @param string $groupClass URI of concept group class |
||
2042 | * @param string $lang language of labels to return |
||
2043 | * @return array Result array with group URI as key and group label as value |
||
2044 | */ |
||
2045 | public function listConceptGroups($groupClass, $lang) { |
||
2050 | |||
2051 | /** |
||
2052 | * Generates the sparql query for listConceptGroupContents |
||
2053 | * @param string $groupClass URI of concept group class |
||
2054 | * @param string $group URI of the concept group instance |
||
2055 | * @param string $lang language of labels to return |
||
2056 | * @param boolean $showDeprecated whether to include deprecated in the result |
||
2057 | * @return string sparql query |
||
2058 | */ |
||
2059 | private function generateConceptGroupContentsQuery($groupClass, $group, $lang, $showDeprecated = false) { |
||
2083 | |||
2084 | /** |
||
2085 | * Transforms the sparql query result into an array. |
||
2086 | * @param EasyRdf\Sparql\Result $result |
||
2087 | * @param string $lang language of labels to return |
||
2088 | * @return array |
||
2089 | */ |
||
2090 | private function transformConceptGroupContentsResults($result, $lang) { |
||
2124 | |||
2125 | /** |
||
2126 | * return a list of concepts in a concept group |
||
2127 | * @param string $groupClass URI of concept group class |
||
2128 | * @param string $group URI of the concept group instance |
||
2129 | * @param string $lang language of labels to return |
||
2130 | * @param boolean $showDeprecated whether to include deprecated concepts in search results |
||
2131 | * @return array Result array with concept URI as key and concept label as value |
||
2132 | */ |
||
2133 | public function listConceptGroupContents($groupClass, $group, $lang,$showDeprecated = false) { |
||
2138 | |||
2139 | /** |
||
2140 | * Generates the sparql query for queryChangeList. |
||
2141 | * @param string $lang language of labels to return. |
||
2142 | * @param int $offset offset of results to retrieve; 0 for beginning of list |
||
2143 | * @return string sparql query |
||
2144 | */ |
||
2145 | View Code Duplication | private function generateChangeListQuery($lang, $offset, $prop) { |
|
2162 | |||
2163 | /** |
||
2164 | * Transforms the sparql query result into an array. |
||
2165 | * @param EasyRdf\Sparql\Result $result |
||
2166 | * @return array |
||
2167 | */ |
||
2168 | View Code Duplication | private function transformChangeListResults($result) { |
|
2184 | |||
2185 | /** |
||
2186 | * return a list of recently changed or entirely new concepts |
||
2187 | * @param string $lang language of labels to return |
||
2188 | * @param int $offset offset of results to retrieve; 0 for beginning of list |
||
2189 | * @return array Result array |
||
2190 | */ |
||
2191 | public function queryChangeList($lang, $offset, $prop) { |
||
2196 | } |
||
2197 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: