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 object $graph an EasyRDF SPARQL graph instance. |
||
| 38 | * @param object $model a Model instance. |
||
| 39 | */ |
||
| 40 | public function __construct($endpoint, $graph, $model) { |
||
| 41 | $this->graph = $graph; |
||
| 42 | $this->model = $model; |
||
| 43 | |||
| 44 | // create the EasyRDF SPARQL client instance to use |
||
| 45 | $this->initializeHttpClient(); |
||
| 46 | $this->client = new EasyRdf_Sparql_Client($endpoint); |
||
| 47 | |||
| 48 | // set graphClause so that it can be used by all queries |
||
| 49 | if ($this->isDefaultEndpoint()) // default endpoint; query any graph (and catch it in a variable) |
||
| 50 | { |
||
| 51 | $this->graphClause = "GRAPH $graph"; |
||
| 52 | } elseif ($graph) // query a specific graph |
||
| 53 | { |
||
| 54 | $this->graphClause = "GRAPH <$graph>"; |
||
| 55 | } else // query the default graph |
||
| 56 | { |
||
| 57 | $this->graphClause = ""; |
||
| 58 | } |
||
| 59 | |||
| 60 | } |
||
| 61 | |||
| 62 | |||
| 63 | /** |
||
| 64 | * Generates FROM clauses for the queries |
||
| 65 | * @param Vocabulary[]|null $vocabs |
||
| 66 | * @return string |
||
| 67 | */ |
||
| 68 | protected function generateFromClause($vocabs=null) { |
||
| 69 | $graphs = array(); |
||
| 70 | $clause = ''; |
||
| 71 | if (!$vocabs) { |
||
| 72 | return $this->graph !== '?graph' ? "FROM <$this->graph>" : ''; |
||
| 73 | } |
||
| 74 | foreach($vocabs as $vocab) { |
||
| 75 | $graph = $vocab->getGraph(); |
||
| 76 | if (!in_array($graph, $graphs)) { |
||
| 77 | array_push($graphs, $graph); |
||
| 78 | } |
||
| 79 | } |
||
| 80 | foreach ($graphs as $graph) { |
||
| 81 | $clause .= "FROM NAMED <$graph> "; |
||
| 82 | } |
||
| 83 | return $clause; |
||
| 84 | } |
||
| 85 | |||
| 86 | protected function initializeHttpClient() { |
||
| 87 | // configure the HTTP client used by EasyRdf_Sparql_Client |
||
| 88 | $httpclient = EasyRdf_Http::getDefaultHttpClient(); |
||
| 89 | $httpclient->setConfig(array('timeout' => $this->model->getConfig()->getSparqlTimeout())); |
||
| 90 | |||
| 91 | // if special cache control (typically no-cache) was requested by the |
||
| 92 | // client, set the same type of cache control headers also in subsequent |
||
| 93 | // in the SPARQL requests (this is useful for performance testing) |
||
| 94 | // @codeCoverageIgnoreStart |
||
| 95 | $cacheControl = filter_input(INPUT_SERVER, 'HTTP_CACHE_CONTROL', FILTER_SANITIZE_STRING); |
||
| 96 | $pragma = filter_input(INPUT_SERVER, 'HTTP_PRAGMA', FILTER_SANITIZE_STRING); |
||
| 97 | if ($cacheControl !== null || $pragma !== null) { |
||
| 98 | $val = $pragma !== null ? $pragma : $cacheControl; |
||
| 99 | $httpclient->setHeaders('Cache-Control', $val); |
||
| 100 | } |
||
| 101 | // @codeCoverageIgnoreEnd |
||
| 102 | |||
| 103 | EasyRdf_Http::setDefaultHttpClient($httpclient); // actually redundant.. |
||
| 104 | } |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Return true if this is the default SPARQL endpoint, used as the facade to query |
||
| 108 | * all vocabularies. |
||
| 109 | */ |
||
| 110 | |||
| 111 | protected function isDefaultEndpoint() { |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Returns the graph instance |
||
| 117 | * @return object EasyRDF graph instance. |
||
| 118 | */ |
||
| 119 | public function getGraph() { |
||
| 120 | return $this->graph; |
||
| 121 | } |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Shorten a URI |
||
| 125 | * @param string $uri URI to shorten |
||
| 126 | * @return string shortened URI, or original URI if it cannot be shortened |
||
| 127 | */ |
||
| 128 | private function shortenUri($uri) { |
||
| 129 | if (!array_key_exists($uri, $this->qnamecache)) { |
||
| 130 | $res = new EasyRdf_Resource($uri); |
||
| 131 | $qname = $res->shorten(); // returns null on failure |
||
| 132 | $this->qnamecache[$uri] = ($qname !== null) ? $qname : $uri; |
||
| 133 | } |
||
| 134 | return $this->qnamecache[$uri]; |
||
| 135 | } |
||
| 136 | |||
| 137 | |||
| 138 | /** |
||
| 139 | * Generates the sparql query for retrieving concept and collection counts in a vocabulary. |
||
| 140 | * @return string sparql query |
||
| 141 | */ |
||
| 142 | private function generateCountConceptsQuery($array, $group) { |
||
| 143 | $fcl = $this->generateFromClause(); |
||
| 144 | $optional = $array ? "UNION { ?type rdfs:subClassOf* <$array> }" : ''; |
||
| 145 | $optional .= $group ? "UNION { ?type rdfs:subClassOf* <$group> }" : ''; |
||
| 146 | $query = <<<EOQ |
||
| 147 | SELECT (COUNT(?conc) as ?c) ?type ?typelabel $fcl WHERE { |
||
| 148 | { ?conc a ?type . |
||
| 149 | { ?type rdfs:subClassOf* skos:Concept . } UNION { ?type rdfs:subClassOf* skos:Collection . } $optional } |
||
| 150 | OPTIONAL { ?type rdfs:label ?typelabel . } |
||
| 151 | } |
||
| 152 | GROUP BY ?type ?typelabel |
||
| 153 | EOQ; |
||
| 154 | return $query; |
||
| 155 | } |
||
| 156 | |||
| 157 | /** |
||
| 158 | * Used for transforming the concept count query results. |
||
| 159 | * @param EasyRdf_Sparql_Result $result query results to be transformed |
||
| 160 | * @param string $lang language of labels |
||
| 161 | * @return Array containing the label counts |
||
| 162 | */ |
||
| 163 | private function transformCountConceptsResults($result, $lang) { |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Used for counting number of concepts and collections in a vocabulary. |
||
| 181 | * @param string $lang language of labels |
||
| 182 | * @return int number of concepts in this vocabulary |
||
| 183 | */ |
||
| 184 | public function countConcepts($lang = null, $array = null, $group = null) { |
||
| 185 | $query = $this->generateCountConceptsQuery($array, $group); |
||
| 186 | $result = $this->client->query($query); |
||
| 187 | return $this->transformCountConceptsResults($result, $lang); |
||
| 188 | } |
||
| 189 | |||
| 190 | /** |
||
| 191 | * @param array $langs Languages to query for |
||
| 192 | * @param string[] $props property names |
||
| 193 | * @return string sparql query |
||
| 194 | */ |
||
| 195 | private function generateCountLangConceptsQuery($langs, $classes, $props) { |
||
| 196 | $gcl = $this->graphClause; |
||
| 197 | $classes = ($classes) ? $classes : array('http://www.w3.org/2004/02/skos/core#Concept'); |
||
| 198 | |||
| 199 | $values = $this->formatValues('?type', $classes, 'uri'); |
||
| 200 | $valuesLang = $this->formatValues('?lang', $langs, 'literal'); |
||
| 201 | $valuesProp = $this->formatValues('?prop', $props, null); |
||
| 202 | |||
| 203 | $query = <<<EOQ |
||
| 204 | SELECT ?lang ?prop |
||
| 205 | (COUNT(?label) as ?count) |
||
| 206 | WHERE { |
||
| 207 | $gcl { |
||
| 208 | ?conc a ?type . |
||
| 209 | ?conc ?prop ?label . |
||
| 210 | FILTER (langMatches(lang(?label), ?lang)) |
||
| 211 | $valuesLang |
||
| 212 | $valuesProp |
||
| 213 | } |
||
| 214 | $values |
||
| 215 | } |
||
| 216 | GROUP BY ?lang ?prop ?type |
||
| 217 | EOQ; |
||
| 218 | return $query; |
||
| 219 | } |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Transforms the CountLangConcepts results into an array of label counts. |
||
| 223 | * @param EasyRdf_Sparql_Result $result query results to be transformed |
||
| 224 | * @param array $langs Languages to query for |
||
| 225 | * @param string[] $props property names |
||
| 226 | */ |
||
| 227 | private function transformCountLangConceptsResults($result, $langs, $props) { |
||
| 228 | $ret = array(); |
||
| 229 | // set default count to zero; overridden below if query found labels |
||
| 230 | foreach ($langs as $lang) { |
||
| 231 | foreach ($props as $prop) { |
||
| 232 | $ret[$lang][$prop] = 0; |
||
| 233 | } |
||
| 234 | } |
||
| 235 | foreach ($result as $row) { |
||
| 236 | if (isset($row->lang) && isset($row->prop) && isset($row->count)) { |
||
| 237 | $ret[$row->lang->getValue()][$row->prop->shorten()] += |
||
| 238 | $row->count->getValue(); |
||
| 239 | } |
||
| 240 | |||
| 241 | } |
||
| 242 | ksort($ret); |
||
| 243 | return $ret; |
||
| 244 | } |
||
| 245 | |||
| 246 | /** |
||
| 247 | * Counts the number of concepts in a easyRDF graph with a specific language. |
||
| 248 | * @param array $langs Languages to query for |
||
| 249 | * @return Array containing count of concepts for each language and property. |
||
| 250 | */ |
||
| 251 | public function countLangConcepts($langs, $classes = null) { |
||
| 252 | $props = array('skos:prefLabel', 'skos:altLabel', 'skos:hiddenLabel'); |
||
| 253 | $query = $this->generateCountLangConceptsQuery($langs, $classes, $props); |
||
| 254 | // Count the number of terms in each language |
||
| 255 | $result = $this->client->query($query); |
||
| 256 | return $this->transformCountLangConceptsResults($result, $langs, $props); |
||
| 257 | } |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Formats a VALUES clause (SPARQL 1.1) which states that the variable should be bound to one |
||
| 261 | * of the constants given. |
||
| 262 | * @param string $varname variable name, e.g. "?uri" |
||
| 263 | * @param array $values the values |
||
| 264 | * @param string $type type of values: "uri", "literal" or null (determines quoting style) |
||
| 265 | */ |
||
| 266 | protected function formatValues($varname, $values, $type = null) { |
||
| 267 | $constants = array(); |
||
| 268 | foreach ($values as $val) { |
||
| 269 | if ($type == 'uri') { |
||
| 270 | $val = "<$val>"; |
||
| 271 | } |
||
| 272 | |||
| 273 | if ($type == 'literal') { |
||
| 274 | $val = "'$val'"; |
||
| 275 | } |
||
| 276 | |||
| 277 | $constants[] = "($val)"; |
||
| 278 | } |
||
| 279 | $values = implode(" ", $constants); |
||
| 280 | |||
| 281 | return "VALUES ($varname) { $values }"; |
||
| 282 | } |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Filters multiple instances of the same vocabulary from the input array. |
||
| 286 | * @param \Vocabulary[]|null $vocabs array of Vocabulary objects |
||
| 287 | * @return \Vocabulary[] |
||
| 288 | */ |
||
| 289 | private function filterDuplicateVocabs($vocabs) { |
||
| 290 | // filtering duplicates |
||
| 291 | $uniqueVocabs = array(); |
||
| 292 | if ($vocabs !== null && sizeof($vocabs) > 0) { |
||
| 293 | foreach ($vocabs as $voc) { |
||
| 294 | $uniqueVocabs[$voc->getId()] = $voc; |
||
| 295 | } |
||
| 296 | } |
||
| 297 | |||
| 298 | return $uniqueVocabs; |
||
| 299 | } |
||
| 300 | |||
| 301 | /** |
||
| 302 | * Generates a sparql query for one or more concept URIs |
||
| 303 | * @param mixed $uris concept URI (string) or array of URIs |
||
| 304 | * @param string|null $arrayClass the URI for thesaurus array class, or null if not used |
||
| 305 | * @param \Vocabulary[]|null $vocabs array of Vocabulary objects |
||
| 306 | * @return string sparql query |
||
| 307 | */ |
||
| 308 | private function generateConceptInfoQuery($uris, $arrayClass, $vocabs) { |
||
| 309 | $gcl = $this->graphClause; |
||
| 310 | $fcl = empty($vocabs) ? '' : $this->generateFromClause($vocabs); |
||
| 311 | $values = $this->formatValues('?uri', $uris, 'uri'); |
||
| 312 | $uniqueVocabs = $this->filterDuplicateVocabs($vocabs); |
||
| 313 | $valuesGraph = empty($vocabs) ? $this->formatValuesGraph($uniqueVocabs) : ''; |
||
| 314 | |||
| 315 | if ($arrayClass === null) { |
||
| 316 | $construct = $optional = ""; |
||
| 317 | } else { |
||
| 318 | // add information that can be used to format narrower concepts by |
||
| 319 | // the array they belong to ("milk by source animal" use case) |
||
| 320 | $construct = "\n ?x skos:member ?o . ?x skos:prefLabel ?xl . ?x a <$arrayClass> ."; |
||
| 321 | $optional = "\n OPTIONAL { |
||
| 322 | ?x skos:member ?o . |
||
| 323 | ?x a <$arrayClass> . |
||
| 324 | ?x skos:prefLabel ?xl . |
||
| 325 | FILTER NOT EXISTS { |
||
| 326 | ?x skos:member ?other . |
||
| 327 | FILTER NOT EXISTS { ?other skos:broader ?uri } |
||
| 328 | } |
||
| 329 | }"; |
||
| 330 | } |
||
| 331 | $query = <<<EOQ |
||
| 332 | CONSTRUCT { |
||
| 333 | ?s ?p ?uri . |
||
| 334 | ?sp ?uri ?op . |
||
| 335 | ?uri ?p ?o . |
||
| 336 | ?p rdfs:label ?proplabel . |
||
| 337 | ?p rdfs:subPropertyOf ?pp . |
||
| 338 | ?pp rdfs:label ?plabel . |
||
| 339 | ?o a ?ot . |
||
| 340 | ?o skos:prefLabel ?opl . |
||
| 341 | ?o rdfs:label ?ol . |
||
| 342 | ?o rdf:value ?ov . |
||
| 343 | ?o skos:notation ?on . |
||
| 344 | ?o ?oprop ?oval . |
||
| 345 | ?o ?xlprop ?xlval . |
||
| 346 | ?directgroup skos:member ?uri . |
||
| 347 | ?parent skos:member ?group . |
||
| 348 | ?group skos:prefLabel ?grouplabel . |
||
| 349 | ?b1 rdf:first ?item . |
||
| 350 | ?b1 rdf:rest ?b2 . |
||
| 351 | ?item a ?it . |
||
| 352 | ?item skos:prefLabel ?il . |
||
| 353 | ?group a ?grouptype . $construct |
||
| 354 | } $fcl WHERE { |
||
| 355 | $gcl { |
||
| 356 | { |
||
| 357 | ?s ?p ?uri . |
||
| 358 | FILTER(!isBlank(?s)) |
||
| 359 | FILTER(?p != skos:inScheme) |
||
| 360 | } |
||
| 361 | UNION |
||
| 362 | { ?sp ?uri ?op . } |
||
| 363 | UNION |
||
| 364 | { |
||
| 365 | ?directgroup skos:member ?uri . |
||
| 366 | ?group skos:member+ ?uri . |
||
| 367 | ?group skos:prefLabel ?grouplabel . |
||
| 368 | ?group a ?grouptype . |
||
| 369 | OPTIONAL { ?parent skos:member ?group } |
||
| 370 | } |
||
| 371 | UNION |
||
| 372 | { |
||
| 373 | ?uri ?p ?o . |
||
| 374 | OPTIONAL { |
||
| 375 | ?o rdf:rest* ?b1 . |
||
| 376 | ?b1 rdf:first ?item . |
||
| 377 | ?b1 rdf:rest ?b2 . |
||
| 378 | OPTIONAL { ?item a ?it . } |
||
| 379 | OPTIONAL { ?item skos:prefLabel ?il . } |
||
| 380 | } |
||
| 381 | OPTIONAL { |
||
| 382 | { ?p rdfs:label ?proplabel . } |
||
| 383 | UNION |
||
| 384 | { ?p rdfs:subPropertyOf ?pp . } |
||
| 385 | UNION |
||
| 386 | { ?o a ?ot . } |
||
| 387 | UNION |
||
| 388 | { ?o skos:prefLabel ?opl . } |
||
| 389 | UNION |
||
| 390 | { ?o rdfs:label ?ol . } |
||
| 391 | UNION |
||
| 392 | { ?o rdf:value ?ov . |
||
| 393 | OPTIONAL { ?o ?oprop ?oval . } |
||
| 394 | } |
||
| 395 | UNION |
||
| 396 | { ?o skos:notation ?on . } |
||
| 397 | UNION |
||
| 398 | { ?o a skosxl:Label . |
||
| 399 | ?o ?xlprop ?xlval } |
||
| 400 | } $optional |
||
| 401 | } |
||
| 402 | } |
||
| 403 | $values |
||
| 404 | } |
||
| 405 | $valuesGraph |
||
| 406 | EOQ; |
||
| 407 | return $query; |
||
| 408 | } |
||
| 409 | |||
| 410 | /** |
||
| 411 | * Transforms ConceptInfo query results into an array of Concept objects |
||
| 412 | * @param EasyRdf_Graph $result query results to be transformed |
||
| 413 | * @param array $uris concept URIs |
||
| 414 | * @param \Vocabulary[] $vocabs array of Vocabulary object |
||
| 415 | * @param string|null $clang content language |
||
| 416 | * @return mixed query result graph (EasyRdf_Graph), or array of Concept objects |
||
| 417 | */ |
||
| 418 | private function transformConceptInfoResults($result, $uris, $vocabs, $clang) { |
||
| 427 | |||
| 428 | /** |
||
| 429 | * Returns information (as a graph) for one or more concept URIs |
||
| 430 | * @param mixed $uris concept URI (string) or array of URIs |
||
| 431 | * @param string|null $arrayClass the URI for thesaurus array class, or null if not used |
||
| 432 | * @param \Vocabulary[]|null $vocabs vocabularies to target |
||
| 433 | * @return \Concept[] |
||
| 434 | */ |
||
| 435 | public function queryConceptInfoGraph($uris, $arrayClass = null, $vocabs = array()) { |
||
| 436 | // if just a single URI is given, put it in an array regardless |
||
| 437 | if (!is_array($uris)) { |
||
| 438 | $uris = array($uris); |
||
| 439 | } |
||
| 440 | |||
| 441 | $query = $this->generateConceptInfoQuery($uris, $arrayClass, $vocabs); |
||
| 442 | $result = $this->client->query($query); |
||
| 443 | return $result; |
||
| 444 | } |
||
| 445 | |||
| 446 | /** |
||
| 447 | * Returns information (as an array of Concept objects) for one or more concept URIs |
||
| 448 | * @param mixed $uris concept URI (string) or array of URIs |
||
| 449 | * @param string|null $arrayClass the URI for thesaurus array class, or null if not used |
||
| 450 | * @param \Vocabulary[] $vocabs vocabularies to target |
||
| 451 | * @param string|null $clang content language |
||
| 452 | * @return EasyRdf_Graph |
||
| 453 | */ |
||
| 454 | public function queryConceptInfo($uris, $arrayClass = null, $vocabs = array(), $clang = null) { |
||
| 455 | // if just a single URI is given, put it in an array regardless |
||
| 456 | if (!is_array($uris)) { |
||
| 457 | $uris = array($uris); |
||
| 458 | } |
||
| 459 | $result = $this->queryConceptInfoGraph($uris, $arrayClass, $vocabs); |
||
| 460 | if ($result->isEmpty()) { |
||
| 461 | return; |
||
| 462 | } |
||
| 463 | return $this->transformConceptInfoResults($result, $uris, $vocabs, $clang); |
||
| 464 | } |
||
| 465 | |||
| 466 | /** |
||
| 467 | * Generates the sparql query for queryTypes |
||
| 468 | * @param string $lang |
||
| 469 | * @return string sparql query |
||
| 470 | */ |
||
| 471 | private function generateQueryTypesQuery($lang) { |
||
| 472 | $fcl = $this->generateFromClause(); |
||
| 473 | $query = <<<EOQ |
||
| 474 | SELECT DISTINCT ?type ?label ?superclass $fcl |
||
| 475 | WHERE { |
||
| 476 | { |
||
| 477 | { BIND( skos:Concept as ?type ) } |
||
| 478 | UNION |
||
| 479 | { BIND( skos:Collection as ?type ) } |
||
| 480 | UNION |
||
| 481 | { BIND( isothes:ConceptGroup as ?type ) } |
||
| 482 | UNION |
||
| 483 | { BIND( isothes:ThesaurusArray as ?type ) } |
||
| 484 | UNION |
||
| 485 | { ?type rdfs:subClassOf/rdfs:subClassOf* skos:Concept . } |
||
| 486 | UNION |
||
| 487 | { ?type rdfs:subClassOf/rdfs:subClassOf* skos:Collection . } |
||
| 488 | } |
||
| 489 | OPTIONAL { |
||
| 490 | ?type rdfs:label ?label . |
||
| 491 | FILTER(langMatches(lang(?label), '$lang')) |
||
| 492 | } |
||
| 493 | OPTIONAL { |
||
| 494 | ?type rdfs:subClassOf ?superclass . |
||
| 495 | } |
||
| 496 | FILTER EXISTS { |
||
| 497 | ?s a ?type . |
||
| 498 | ?s skos:prefLabel ?prefLabel . |
||
| 499 | } |
||
| 500 | } |
||
| 501 | EOQ; |
||
| 502 | return $query; |
||
| 503 | } |
||
| 504 | |||
| 505 | /** |
||
| 506 | * Transforms the results into an array format. |
||
| 507 | * @param EasyRdf_Sparql_Result $result |
||
| 508 | * @return array Array with URIs (string) as key and array of (label, superclassURI) as value |
||
| 509 | */ |
||
| 510 | View Code Duplication | private function transformQueryTypesResults($result) { |
|
| 526 | |||
| 527 | /** |
||
| 528 | * Retrieve information about types from the endpoint |
||
| 529 | * @param string $lang |
||
| 530 | * @return array Array with URIs (string) as key and array of (label, superclassURI) as value |
||
| 531 | */ |
||
| 532 | public function queryTypes($lang) { |
||
| 537 | |||
| 538 | /** |
||
| 539 | * Generates the concept scheme query. |
||
| 540 | * @param string $conceptscheme concept scheme URI |
||
| 541 | * @return string sparql query |
||
| 542 | */ |
||
| 543 | private function generateQueryConceptSchemeQuery($conceptscheme) { |
||
| 544 | $fcl = $this->generateFromClause(); |
||
| 545 | $query = <<<EOQ |
||
| 546 | CONSTRUCT { |
||
| 547 | <$conceptscheme> ?property ?value . |
||
| 548 | } $fcl WHERE { |
||
| 549 | <$conceptscheme> ?property ?value . |
||
| 550 | FILTER (?property != skos:hasTopConcept) |
||
| 551 | } |
||
| 552 | EOQ; |
||
| 553 | return $query; |
||
| 554 | } |
||
| 555 | |||
| 556 | /** |
||
| 557 | * Retrieves conceptScheme information from the endpoint. |
||
| 558 | * @param string $conceptscheme concept scheme URI |
||
| 559 | * @return EasyRDF_Graph query result graph |
||
| 560 | */ |
||
| 561 | public function queryConceptScheme($conceptscheme) { |
||
| 562 | $query = $this->generateQueryConceptSchemeQuery($conceptscheme); |
||
| 563 | return $this->client->query($query); |
||
| 564 | } |
||
| 565 | |||
| 566 | /** |
||
| 567 | * Generates the queryConceptSchemes sparql query. |
||
| 568 | * @param string $lang language of labels |
||
| 569 | * @return string sparql query |
||
| 570 | */ |
||
| 571 | private function generateQueryConceptSchemesQuery($lang) { |
||
| 572 | $fcl = $this->generateFromClause(); |
||
| 573 | $query = <<<EOQ |
||
| 574 | SELECT ?cs ?label ?preflabel ?title $fcl |
||
| 575 | WHERE { |
||
| 576 | ?cs a skos:ConceptScheme . |
||
| 577 | OPTIONAL { |
||
| 578 | ?cs rdfs:label ?label . |
||
| 579 | FILTER(langMatches(lang(?label), '$lang')) |
||
| 580 | } |
||
| 581 | OPTIONAL { |
||
| 582 | ?cs skos:prefLabel ?preflabel . |
||
| 583 | FILTER(langMatches(lang(?preflabel), '$lang')) |
||
| 584 | } |
||
| 585 | OPTIONAL { |
||
| 586 | { ?cs dc11:title ?title } |
||
| 587 | UNION |
||
| 588 | { ?cs dc:title ?title } |
||
| 589 | FILTER(langMatches(lang(?title), '$lang')) |
||
| 590 | } |
||
| 591 | } ORDER BY ?cs |
||
| 592 | EOQ; |
||
| 593 | return $query; |
||
| 594 | } |
||
| 595 | |||
| 596 | /** |
||
| 597 | * Transforms the queryConceptScheme results into an array format. |
||
| 598 | * @param EasyRdf_Sparql_Result $result |
||
| 599 | * @return array |
||
| 600 | */ |
||
| 601 | private function transformQueryConceptSchemesResults($result) { |
||
| 621 | |||
| 622 | /** |
||
| 623 | * return a list of skos:ConceptScheme instances in the given graph |
||
| 624 | * @param string $lang language of labels |
||
| 625 | * @return array Array with concept scheme URIs (string) as keys and labels (string) as values |
||
| 626 | */ |
||
| 627 | public function queryConceptSchemes($lang) { |
||
| 632 | |||
| 633 | /** |
||
| 634 | * Generate a VALUES clause for limiting the targeted graphs. |
||
| 635 | * @param Vocabulary[]|null $vocabs the vocabularies to target |
||
| 636 | * @return string[] array of graph URIs |
||
| 637 | */ |
||
| 638 | protected function getVocabGraphs($vocabs) { |
||
| 639 | if ($vocabs === null || sizeof($vocabs) == 0) { |
||
| 640 | // searching from all vocabularies - limit to known graphs |
||
| 641 | $vocabs = $this->model->getVocabularies(); |
||
| 642 | } |
||
| 643 | $graphs = array(); |
||
| 644 | foreach ($vocabs as $voc) { |
||
| 645 | $graphs[] = $voc->getGraph(); |
||
| 646 | } |
||
| 647 | return $graphs; |
||
| 648 | } |
||
| 649 | |||
| 650 | /** |
||
| 651 | * Generate a VALUES clause for limiting the targeted graphs. |
||
| 652 | * @param Vocabulary[]|null $vocabs array of Vocabulary objects to target |
||
| 653 | * @return string VALUES clause, or "" if not necessary to limit |
||
| 654 | */ |
||
| 655 | protected function formatValuesGraph($vocabs) { |
||
| 662 | |||
| 663 | /** |
||
| 664 | * Generate a FILTER clause for limiting the targeted graphs. |
||
| 665 | * @param array $vocabs array of Vocabulary objects to target |
||
| 666 | * @return string FILTER clause, or "" if not necessary to limit |
||
| 667 | */ |
||
| 668 | protected function formatFilterGraph($vocabs) { |
||
| 669 | if (!$this->isDefaultEndpoint()) { |
||
| 670 | return ""; |
||
| 671 | } |
||
| 672 | $graphs = $this->getVocabGraphs($vocabs); |
||
| 673 | $values = array(); |
||
| 674 | foreach ($graphs as $graph) { |
||
| 675 | $values[] = "<$graph>"; |
||
| 676 | } |
||
| 677 | return "FILTER (?graph IN (" . implode(',', $values) . "))"; |
||
| 678 | } |
||
| 679 | |||
| 680 | /** |
||
| 681 | * Formats combined limit and offset clauses for the sparql query |
||
| 682 | * @param int $limit maximum number of hits to retrieve; 0 for unlimited |
||
| 683 | * @param int $offset offset of results to retrieve; 0 for beginning of list |
||
| 684 | * @return string sparql query clauses |
||
| 685 | */ |
||
| 686 | protected function formatLimitAndOffset($limit, $offset) { |
||
| 701 | |||
| 702 | /** |
||
| 703 | * Formats a sparql query clause for limiting the search to specific concept types. |
||
| 704 | * @param array $types limit search to concepts of the given type(s) |
||
| 705 | * @return string sparql query clause |
||
| 706 | */ |
||
| 707 | protected function formatTypes($types) { |
||
| 718 | |||
| 719 | /** |
||
| 720 | * @param string $prop property to include in the result eg. 'broader' or 'narrower' |
||
| 721 | * @return string sparql query clause |
||
| 722 | */ |
||
| 723 | private function formatPropertyCsvClause($prop) { |
||
| 724 | # This expression creates a CSV row containing pairs of (uri,prefLabel) values. |
||
| 725 | # The REPLACE is performed for quotes (" -> "") so they don't break the CSV format. |
||
| 726 | $clause = <<<EOV |
||
| 727 | (GROUP_CONCAT(DISTINCT CONCAT( |
||
| 728 | '"', IF(isIRI(?$prop),STR(?$prop),''), '"', ',', |
||
| 729 | '"', REPLACE(IF(BOUND(?{$prop}lab),?{$prop}lab,''), '"', '""'), '"', ',', |
||
| 730 | '"', REPLACE(IF(isLiteral(?{$prop}),?{$prop},''), '"', '""'), '"' |
||
| 731 | ); separator='\\n') as ?{$prop}s) |
||
| 732 | EOV; |
||
| 733 | return $clause; |
||
| 734 | } |
||
| 735 | |||
| 736 | /** |
||
| 737 | * @return string sparql query clause |
||
| 738 | */ |
||
| 739 | private function formatPrefLabelCsvClause() { |
||
| 749 | |||
| 750 | /** |
||
| 751 | * @param string $lang language code of the returned labels |
||
| 752 | * @param array|null $fields extra fields to include in the result (array of strings). (default: null = none) |
||
| 753 | * @return string sparql query clause |
||
| 754 | */ |
||
| 755 | protected function formatExtraFields($lang, $fields) { |
||
| 756 | // extra variable expressions to request and extra fields to query for |
||
| 757 | $ret = array('extravars' => '', 'extrafields' => ''); |
||
| 758 | |||
| 759 | if ($fields === null) { |
||
| 760 | return $ret; |
||
| 761 | } |
||
| 762 | |||
| 763 | if (in_array('prefLabel', $fields)) { |
||
| 764 | $ret['extravars'] .= $this->formatPreflabelCsvClause(); |
||
| 765 | $ret['extrafields'] .= <<<EOF |
||
| 766 | OPTIONAL { |
||
| 767 | ?s skos:prefLabel ?pref . |
||
| 768 | } |
||
| 769 | EOF; |
||
| 770 | // removing the prefLabel from the fields since it has been handled separately |
||
| 771 | $fields = array_diff($fields, array('prefLabel')); |
||
| 772 | } |
||
| 773 | |||
| 774 | foreach ($fields as $field) { |
||
| 775 | $ret['extravars'] .= $this->formatPropertyCsvClause($field); |
||
| 776 | $ret['extrafields'] .= <<<EOF |
||
| 777 | OPTIONAL { |
||
| 778 | ?s skos:$field ?$field . |
||
| 779 | FILTER(!isLiteral(?$field)||langMatches(lang(?{$field}), '$lang')) |
||
| 780 | OPTIONAL { ?$field skos:prefLabel ?{$field}lab . FILTER(langMatches(lang(?{$field}lab), '$lang')) } |
||
| 781 | } |
||
| 782 | EOF; |
||
| 783 | } |
||
| 784 | |||
| 785 | return $ret; |
||
| 786 | } |
||
| 787 | |||
| 788 | /** |
||
| 789 | * Generate condition for matching labels in SPARQL |
||
| 790 | * @param string $term search term |
||
| 791 | * @param string $searchLang language code used for matching labels (null means any language) |
||
| 792 | * @return string sparql query snippet |
||
| 793 | */ |
||
| 794 | protected function generateConceptSearchQueryCondition($term, $searchLang) |
||
| 823 | |||
| 824 | |||
| 825 | /** |
||
| 826 | * Inner query for concepts using a search term. |
||
| 827 | * @param string $term search term |
||
| 828 | * @param string $lang language code of the returned labels |
||
| 829 | * @param string $searchLang language code used for matching labels (null means any language) |
||
| 830 | * @param string[] $props properties to target e.g. array('skos:prefLabel','skos:altLabel') |
||
| 831 | * @param boolean $unique restrict results to unique concepts (default: false) |
||
| 832 | * @return string sparql query |
||
| 833 | */ |
||
| 834 | protected function generateConceptSearchQueryInner($term, $lang, $searchLang, $props, $unique, $filterGraph) |
||
| 835 | { |
||
| 836 | $valuesProp = $this->formatValues('?prop', $props); |
||
| 837 | $textcond = $this->generateConceptSearchQueryCondition($term, $searchLang); |
||
| 838 | $rawterm = str_replace('*', '', $term); |
||
| 839 | |||
| 840 | // graph clause, if necessary |
||
| 841 | $graphClause = $filterGraph != '' ? 'GRAPH ?graph' : ''; |
||
| 842 | |||
| 843 | // extra conditions for label language, if specified |
||
| 844 | $labelcondLabel = ($lang) ? "LANGMATCHES(lang(?label), '$lang')" : "LANGMATCHES(lang(?label), lang(?match))"; |
||
| 845 | // if search language and UI/display language differ, must also consider case where there is no prefLabel in |
||
| 846 | // the display language; in that case, should use the label with the same language as the matched label |
||
| 894 | |||
| 895 | /** |
||
| 896 | * Query for concepts using a search term. |
||
| 897 | * @param array|null $fields extra fields to include in the result (array of strings). (default: null = none) |
||
| 898 | * @param boolean $unique restrict results to unique concepts (default: false) |
||
| 899 | * @param ConceptSearchParameters $params |
||
| 900 | * @return string sparql query |
||
| 901 | */ |
||
| 902 | protected function generateConceptSearchQuery($fields, $unique, $params) { |
||
| 976 | |||
| 977 | /** |
||
| 978 | * Transform a single concept search query results into the skosmos desired return format. |
||
| 979 | * @param $row SPARQL query result row |
||
| 980 | * @param array $vocabs array of Vocabulary objects to search; empty for global search |
||
| 981 | * @return array query result object |
||
| 982 | */ |
||
| 983 | private function transformConceptSearchResult($row, $vocabs, $fields) |
||
| 1059 | |||
| 1060 | /** |
||
| 1061 | * Transform the concept search query results into the skosmos desired return format. |
||
| 1062 | * @param EasyRdf_Sparql_Result $results |
||
| 1063 | * @param array $vocabs array of Vocabulary objects to search; empty for global search |
||
| 1064 | * @return array query result object |
||
| 1065 | */ |
||
| 1066 | private function transformConceptSearchResults($results, $vocabs, $fields) { |
||
| 1078 | |||
| 1079 | /** |
||
| 1080 | * Query for concepts using a search term. |
||
| 1081 | * @param array $vocabs array of Vocabulary objects to search; empty for global search |
||
| 1082 | * @param array $fields extra fields to include in the result (array of strings). (default: null = none) |
||
| 1083 | * @param boolean $unique restrict results to unique concepts (default: false) |
||
| 1084 | * @param ConceptSearchParameters $params |
||
| 1085 | * @return array query result object |
||
| 1086 | */ |
||
| 1087 | public function queryConcepts($vocabs, $fields = null, $unique = false, $params) { |
||
| 1092 | |||
| 1093 | /** |
||
| 1094 | * Generates sparql query clauses used for creating the alphabetical index. |
||
| 1095 | * @param string $letter the letter (or special class) to search for |
||
| 1096 | * @return array of sparql query clause strings |
||
| 1097 | */ |
||
| 1098 | private function formatFilterConditions($letter) { |
||
| 1123 | |||
| 1124 | /** |
||
| 1125 | * Generates the sparql query used for rendering the alphabetical index. |
||
| 1126 | * @param string $letter the letter (or special class) to search for |
||
| 1127 | * @param string $lang language of labels |
||
| 1128 | * @param integer $limit limits the amount of results |
||
| 1129 | * @param integer $offset offsets the result set |
||
| 1130 | * @param array|null $classes |
||
| 1131 | * @return string sparql query |
||
| 1132 | */ |
||
| 1133 | protected function generateAlphabeticalListQuery($letter, $lang, $limit, $offset, $classes) { |
||
| 1174 | |||
| 1175 | /** |
||
| 1176 | * Transforms the alphabetical list query results into an array format. |
||
| 1177 | * @param EasyRdf_Sparql_Result $results |
||
| 1178 | * @return array |
||
| 1179 | */ |
||
| 1180 | private function transformAlphabeticalListResults($results) { |
||
| 1207 | |||
| 1208 | /** |
||
| 1209 | * Query for concepts with a term starting with the given letter. Also special classes '0-9' (digits), |
||
| 1210 | * '*!' (special characters) and '*' (everything) are accepted. |
||
| 1211 | * @param string $letter the letter (or special class) to search for |
||
| 1212 | * @param string $lang language of labels |
||
| 1213 | * @param integer $limit limits the amount of results |
||
| 1214 | * @param integer $offset offsets the result set |
||
| 1215 | * @param array $classes |
||
| 1216 | */ |
||
| 1217 | public function queryConceptsAlphabetical($letter, $lang, $limit = null, $offset = null, $classes = null) { |
||
| 1222 | |||
| 1223 | /** |
||
| 1224 | * Creates the query used for finding out which letters should be displayed in the alphabetical index. |
||
| 1225 | * @param string $lang language |
||
| 1226 | * @return string sparql query |
||
| 1227 | */ |
||
| 1228 | private function generateFirstCharactersQuery($lang, $classes) { |
||
| 1242 | |||
| 1243 | /** |
||
| 1244 | * Transforms the first characters query results into an array format. |
||
| 1245 | * @param EasyRdf_Sparql_Result $result |
||
| 1246 | * @return array |
||
| 1247 | */ |
||
| 1248 | private function transformFirstCharactersResults($result) { |
||
| 1255 | |||
| 1256 | /** |
||
| 1257 | * Query for the first characters (letter or otherwise) of the labels in the particular language. |
||
| 1258 | * @param string $lang language |
||
| 1259 | * @return array array of characters |
||
| 1260 | */ |
||
| 1261 | public function queryFirstCharacters($lang, $classes = null) { |
||
| 1266 | |||
| 1267 | /** |
||
| 1268 | * @param string $uri |
||
| 1269 | * @param string $lang |
||
| 1270 | * @return string sparql query string |
||
| 1271 | */ |
||
| 1272 | private function generateLabelQuery($uri, $lang) { |
||
| 1299 | |||
| 1300 | /** |
||
| 1301 | * Query for a label (skos:prefLabel, rdfs:label, dc:title, dc11:title) of a resource. |
||
| 1302 | * @param string $uri |
||
| 1303 | * @param string $lang |
||
| 1304 | * @return array array of labels (key: lang, val: label), or null if resource doesn't exist |
||
| 1305 | */ |
||
| 1306 | public function queryLabel($uri, $lang) { |
||
| 1326 | |||
| 1327 | /** |
||
| 1328 | * Generates a sparql query for queryProperty. |
||
| 1329 | * @param string $uri |
||
| 1330 | * @param string $prop the name of the property eg. 'skos:broader'. |
||
| 1331 | * @param string $lang |
||
| 1332 | * @param boolean $anylang if you want a label even when it isn't available in the language you requested. |
||
| 1333 | * @return string sparql query |
||
| 1334 | */ |
||
| 1335 | View Code Duplication | private function generatePropertyQuery($uri, $prop, $lang, $anylang) { |
|
| 1359 | |||
| 1360 | /** |
||
| 1361 | * Transforms the sparql query result into an array or null if the concept doesn't exist. |
||
| 1362 | * @param EasyRdf_Sparql_Result $result |
||
| 1363 | * @param string $lang |
||
| 1364 | * @return array array of property values (key: URI, val: label), or null if concept doesn't exist |
||
| 1365 | */ |
||
| 1366 | private function transformPropertyQueryResults($result, $lang) { |
||
| 1391 | |||
| 1392 | /** |
||
| 1393 | * Query a single property of a concept. |
||
| 1394 | * @param string $uri |
||
| 1395 | * @param string $prop the name of the property eg. 'skos:broader'. |
||
| 1396 | * @param string $lang |
||
| 1397 | * @param boolean $anylang if you want a label even when it isn't available in the language you requested. |
||
| 1398 | * @return array array of property values (key: URI, val: label), or null if concept doesn't exist |
||
| 1399 | */ |
||
| 1400 | public function queryProperty($uri, $prop, $lang, $anylang = false) { |
||
| 1406 | |||
| 1407 | /** |
||
| 1408 | * Query a single transitive property of a concept. |
||
| 1409 | * @param string $uri |
||
| 1410 | * @param string $prop the name of the property eg. 'skos:broader'. |
||
| 1411 | * @param string $lang |
||
| 1412 | * @param integer $limit |
||
| 1413 | * @param boolean $anylang if you want a label even when it isn't available in the language you requested. |
||
| 1414 | * @return string sparql query |
||
| 1415 | */ |
||
| 1416 | private function generateTransitivePropertyQuery($uri, $props, $lang, $limit, $anylang) { |
||
| 1446 | |||
| 1447 | /** |
||
| 1448 | * Transforms the sparql query result object into an array. |
||
| 1449 | * @param EasyRdf_Sparql_Result $result |
||
| 1450 | * @param string $lang |
||
| 1451 | * @param string $fallbacklang language to use if label is not available in the preferred language |
||
| 1452 | * @return array of property values (key: URI, val: label), or null if concept doesn't exist |
||
| 1453 | */ |
||
| 1454 | private function transformTransitivePropertyResults($result, $lang, $fallbacklang) { |
||
| 1500 | |||
| 1501 | /** |
||
| 1502 | * Query a single transitive property of a concept. |
||
| 1503 | * @param string $uri |
||
| 1504 | * @param array $props the property/properties. |
||
| 1505 | * @param string $lang |
||
| 1506 | * @param string $fallbacklang language to use if label is not available in the preferred language |
||
| 1507 | * @param integer $limit |
||
| 1508 | * @param boolean $anylang if you want a label even when it isn't available in the language you requested. |
||
| 1509 | * @return array array of property values (key: URI, val: label), or null if concept doesn't exist |
||
| 1510 | */ |
||
| 1511 | public function queryTransitiveProperty($uri, $props, $lang, $limit, $anylang = false, $fallbacklang = '') { |
||
| 1516 | |||
| 1517 | /** |
||
| 1518 | * Generates the query for a concepts skos:narrowers. |
||
| 1519 | * @param string $uri |
||
| 1520 | * @param string $lang |
||
| 1521 | * @param string $fallback |
||
| 1522 | * @return string sparql query |
||
| 1523 | */ |
||
| 1524 | private function generateChildQuery($uri, $lang, $fallback, $props) { |
||
| 1553 | |||
| 1554 | /** |
||
| 1555 | * Transforms the sparql result object into an array. |
||
| 1556 | * @param EasyRdf_Sparql_Result $result |
||
| 1557 | * @param string $lang |
||
| 1558 | * @return array array of arrays describing each child concept, or null if concept doesn't exist |
||
| 1559 | */ |
||
| 1560 | private function transformNarrowerResults($result, $lang) { |
||
| 1597 | |||
| 1598 | /** |
||
| 1599 | * Query the narrower concepts of a concept. |
||
| 1600 | * @param string $uri |
||
| 1601 | * @param string $lang |
||
| 1602 | * @param string $fallback |
||
| 1603 | * @return array array of arrays describing each child concept, or null if concept doesn't exist |
||
| 1604 | */ |
||
| 1605 | public function queryChildren($uri, $lang, $fallback, $props) { |
||
| 1610 | |||
| 1611 | /** |
||
| 1612 | * Query the top concepts of a vocabulary. |
||
| 1613 | * @param string $conceptSchemes concept schemes whose top concepts to query for |
||
| 1614 | * @param string $lang language of labels |
||
| 1615 | */ |
||
| 1616 | public function queryTopConcepts($conceptSchemes, $lang) { |
||
| 1649 | |||
| 1650 | /** |
||
| 1651 | * Generates a sparql query for finding the hierarchy for a concept. |
||
| 1652 | * @param string $uri concept uri. |
||
| 1653 | * @param string $lang |
||
| 1654 | * @param string $fallback language to use if label is not available in the preferred language |
||
| 1655 | * @return string sparql query |
||
| 1656 | */ |
||
| 1657 | private function generateParentListQuery($uri, $lang, $fallback, $props) { |
||
| 1704 | |||
| 1705 | /** |
||
| 1706 | * Transforms the result into an array. |
||
| 1707 | * @param EasyRdf_Sparql_Result |
||
| 1708 | * @param string $lang |
||
| 1709 | * @return an array for the REST controller to encode. |
||
| 1710 | */ |
||
| 1711 | private function transformParentListResults($result, $lang) |
||
| 1784 | |||
| 1785 | /** |
||
| 1786 | * Query for finding the hierarchy for a concept. |
||
| 1787 | * @param string $uri concept uri. |
||
| 1788 | * @param string $lang |
||
| 1789 | * @param string $fallback language to use if label is not available in the preferred language |
||
| 1790 | * @param array $props the hierarchy property/properties to use |
||
| 1791 | * @return an array for the REST controller to encode. |
||
| 1792 | */ |
||
| 1793 | public function queryParentList($uri, $lang, $fallback, $props) { |
||
| 1798 | |||
| 1799 | /** |
||
| 1800 | * return a list of concept group instances, sorted by label |
||
| 1801 | * @param string $groupClass URI of concept group class |
||
| 1802 | * @param string $lang language of labels to return |
||
| 1803 | * @return string sparql query |
||
| 1804 | */ |
||
| 1805 | private function generateConceptGroupsQuery($groupClass, $lang) { |
||
| 1824 | |||
| 1825 | /** |
||
| 1826 | * Transforms the sparql query result into an array. |
||
| 1827 | * @param EasyRdf_Sparql_Result $result |
||
| 1828 | * @return array |
||
| 1829 | */ |
||
| 1830 | private function transformConceptGroupsResults($result) { |
||
| 1858 | |||
| 1859 | /** |
||
| 1860 | * return a list of concept group instances, sorted by label |
||
| 1861 | * @param string $groupClass URI of concept group class |
||
| 1862 | * @param string $lang language of labels to return |
||
| 1863 | * @return array Result array with group URI as key and group label as value |
||
| 1864 | */ |
||
| 1865 | public function listConceptGroups($groupClass, $lang) { |
||
| 1870 | |||
| 1871 | /** |
||
| 1872 | * Generates the sparql query for listConceptGroupContents |
||
| 1873 | * @param string $groupClass URI of concept group class |
||
| 1874 | * @param string $group URI of the concept group instance |
||
| 1875 | * @param string $lang language of labels to return |
||
| 1876 | * @return string sparql query |
||
| 1877 | */ |
||
| 1878 | private function generateConceptGroupContentsQuery($groupClass, $group, $lang) { |
||
| 1898 | |||
| 1899 | /** |
||
| 1900 | * Transforms the sparql query result into an array. |
||
| 1901 | * @param EasyRdf_Sparql_Result $result |
||
| 1902 | * @param string $lang language of labels to return |
||
| 1903 | * @return array |
||
| 1904 | */ |
||
| 1905 | private function transformConceptGroupContentsResults($result, $lang) { |
||
| 1939 | |||
| 1940 | /** |
||
| 1941 | * return a list of concepts in a concept group |
||
| 1942 | * @param string $groupClass URI of concept group class |
||
| 1943 | * @param string $group URI of the concept group instance |
||
| 1944 | * @param string $lang language of labels to return |
||
| 1945 | * @return array Result array with concept URI as key and concept label as value |
||
| 1946 | */ |
||
| 1947 | public function listConceptGroupContents($groupClass, $group, $lang) { |
||
| 1952 | |||
| 1953 | /** |
||
| 1954 | * Generates the sparql query for queryChangeList. |
||
| 1955 | * @param string $lang language of labels to return. |
||
| 1956 | * @param int $offset offset of results to retrieve; 0 for beginning of list |
||
| 1957 | * @return string sparql query |
||
| 1958 | */ |
||
| 1959 | View Code Duplication | private function generateChangeListQuery($lang, $offset, $prop) { |
|
| 1976 | |||
| 1977 | /** |
||
| 1978 | * Transforms the sparql query result into an array. |
||
| 1979 | * @param EasyRdf_Sparql_Result $result |
||
| 1980 | * @return array |
||
| 1981 | */ |
||
| 1982 | View Code Duplication | private function transformChangeListResults($result) { |
|
| 1998 | |||
| 1999 | /** |
||
| 2000 | * return a list of recently changed or entirely new concepts |
||
| 2001 | * @param string $lang language of labels to return |
||
| 2002 | * @param int $offset offset of results to retrieve; 0 for beginning of list |
||
| 2003 | * @return array Result array |
||
| 2004 | */ |
||
| 2005 | public function queryChangeList($lang, $offset, $prop) { |
||
| 2010 | } |
||
| 2011 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.