@@ -88,11 +88,11 @@ discard block |
||
88 | 88 | protected function query($query) { |
89 | 89 | $queryId = sprintf("%05d", rand(0, 99999)); |
90 | 90 | $logger = $this->model->getLogger(); |
91 | - $logger->info("[qid $queryId] SPARQL query:\n" . $this->generateQueryPrefixes($query) . "\n$query\n"); |
|
91 | + $logger->info("[qid $queryId] SPARQL query:\n".$this->generateQueryPrefixes($query)."\n$query\n"); |
|
92 | 92 | $starttime = microtime(true); |
93 | 93 | $result = $this->client->query($query); |
94 | 94 | $elapsed = intval(round((microtime(true) - $starttime) * 1000)); |
95 | - if(method_exists($result, 'numRows')) { |
|
95 | + if (method_exists($result, 'numRows')) { |
|
96 | 96 | $numRows = $result->numRows(); |
97 | 97 | $logger->info("[qid $queryId] result: $numRows rows returned in $elapsed ms"); |
98 | 98 | } else { // graph result |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * @param Vocabulary[]|null $vocabs |
109 | 109 | * @return string |
110 | 110 | */ |
111 | - protected function generateFromClause($vocabs=null) { |
|
111 | + protected function generateFromClause($vocabs = null) { |
|
112 | 112 | $clause = ''; |
113 | 113 | if (!$vocabs) { |
114 | 114 | return $this->graph !== '?graph' && $this->graph !== NULL ? "FROM <$this->graph>" : ''; |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | |
251 | 251 | $quote_string = function($val) { return "'$val'"; }; |
252 | 252 | $quoted_values = array_map($quote_string, $langs); |
253 | - $langFilter = "FILTER(?lang IN (" . implode(',', $quoted_values) . "))"; |
|
253 | + $langFilter = "FILTER(?lang IN (".implode(',', $quoted_values)."))"; |
|
254 | 254 | |
255 | 255 | $values = $this->formatValues('?type', $classes, 'uri'); |
256 | 256 | $valuesProp = $this->formatValues('?prop', $props, null); |
@@ -694,9 +694,9 @@ discard block |
||
694 | 694 | $conceptscheme['title'] = $row->title->getValue(); |
695 | 695 | } |
696 | 696 | // add dct:subject and their labels in the result |
697 | - if(isset($row->domain) && isset($row->domainLabel)){ |
|
698 | - $conceptscheme['subject']['uri']=$row->domain->getURI(); |
|
699 | - $conceptscheme['subject']['prefLabel']=$row->domainLabel->getValue(); |
|
697 | + if (isset($row->domain) && isset($row->domainLabel)) { |
|
698 | + $conceptscheme['subject']['uri'] = $row->domain->getURI(); |
|
699 | + $conceptscheme['subject']['prefLabel'] = $row->domainLabel->getValue(); |
|
700 | 700 | } |
701 | 701 | |
702 | 702 | $ret[$row->cs->getURI()] = $conceptscheme; |
@@ -763,7 +763,7 @@ discard block |
||
763 | 763 | $values[] = "<$graph>"; |
764 | 764 | } |
765 | 765 | if (count($values)) { |
766 | - return "FILTER (?graph IN (" . implode(',', $values) . "))"; |
|
766 | + return "FILTER (?graph IN (".implode(',', $values)."))"; |
|
767 | 767 | } |
768 | 768 | } |
769 | 769 | |
@@ -774,16 +774,16 @@ discard block |
||
774 | 774 | * @return string sparql query clauses |
775 | 775 | */ |
776 | 776 | protected function formatLimitAndOffset($limit, $offset) { |
777 | - $limit = ($limit) ? 'LIMIT ' . $limit : ''; |
|
778 | - $offset = ($offset) ? 'OFFSET ' . $offset : ''; |
|
777 | + $limit = ($limit) ? 'LIMIT '.$limit : ''; |
|
778 | + $offset = ($offset) ? 'OFFSET '.$offset : ''; |
|
779 | 779 | // eliminating whitespace and line changes when the conditions aren't needed. |
780 | 780 | $limitandoffset = ''; |
781 | 781 | if ($limit && $offset) { |
782 | - $limitandoffset = "\n" . $limit . "\n" . $offset; |
|
782 | + $limitandoffset = "\n".$limit."\n".$offset; |
|
783 | 783 | } elseif ($limit) { |
784 | - $limitandoffset = "\n" . $limit; |
|
784 | + $limitandoffset = "\n".$limit; |
|
785 | 785 | } elseif ($offset) { |
786 | - $limitandoffset = "\n" . $offset; |
|
786 | + $limitandoffset = "\n".$offset; |
|
787 | 787 | } |
788 | 788 | |
789 | 789 | return $limitandoffset; |
@@ -922,7 +922,7 @@ discard block |
||
922 | 922 | * @param string|null $distinguisher SPARQL property path from concept to distinguisher object in case of shared prefLabels |
923 | 923 | * @return string sparql query |
924 | 924 | */ |
925 | - protected function generateConceptSearchQueryInner($term, $lang, $searchLang, $props, $unique, $filterGraph, $distinguisher=null) |
|
925 | + protected function generateConceptSearchQueryInner($term, $lang, $searchLang, $props, $unique, $filterGraph, $distinguisher = null) |
|
926 | 926 | { |
927 | 927 | $valuesProp = $this->formatValues('?prop', $props); |
928 | 928 | $textcond = $this->generateConceptSearchQueryCondition($term, $searchLang); |
@@ -936,30 +936,30 @@ discard block |
||
936 | 936 | // if search language and UI/display language differ, must also consider case where there is no prefLabel in |
937 | 937 | // the display language; in that case, should use the label with the same language as the matched label |
938 | 938 | $labelcondFallback = ($searchLang != $lang) ? |
939 | - "OPTIONAL { # in case previous OPTIONAL block gives no labels\n" . |
|
939 | + "OPTIONAL { # in case previous OPTIONAL block gives no labels\n". |
|
940 | 940 | "?s skos:prefLabel ?label . FILTER (LANGMATCHES(LANG(?label), LANG(?match))) }" : ""; |
941 | 941 | |
942 | 942 | // Including the labels if there is no query term given. |
943 | 943 | if ($rawterm === '') { |
944 | 944 | $labelClause = "?s skos:prefLabel ?label ."; |
945 | - $labelClause = ($lang) ? $labelClause . " FILTER (LANGMATCHES(LANG(?label), '$lang'))" : $labelClause . ""; |
|
946 | - return $labelClause . " BIND(?label AS ?match)"; |
|
945 | + $labelClause = ($lang) ? $labelClause." FILTER (LANGMATCHES(LANG(?label), '$lang'))" : $labelClause.""; |
|
946 | + return $labelClause." BIND(?label AS ?match)"; |
|
947 | 947 | } |
948 | 948 | |
949 | 949 | $distinguishercondLabel = "FILTER (LANG(?distLabel) = LANG(?label))"; |
950 | 950 | // Only include distinguisher labels in case of a shared prefLabel |
951 | 951 | $distinguisherClause = $distinguisher ? |
952 | - "OPTIONAL {\n" . |
|
953 | - " ?s skos:prefLabel ?label . ?s2 skos:prefLabel ?label . FILTER(?s2 != ?s)\n" . |
|
954 | - " ?s $distinguisher ?distinguisher.\n" . |
|
955 | - " OPTIONAL {\n" . |
|
956 | - " ?distinguisher skos:prefLabel ?distLabel .\n" . |
|
957 | - " $distinguishercondLabel\n" . |
|
958 | - " }\n" . |
|
959 | - " OPTIONAL {\n" . |
|
960 | - " ?distinguisher rdfs:label ?distLabel .\n" . |
|
961 | - " $distinguishercondLabel\n" . |
|
962 | - " }\n" . |
|
952 | + "OPTIONAL {\n". |
|
953 | + " ?s skos:prefLabel ?label . ?s2 skos:prefLabel ?label . FILTER(?s2 != ?s)\n". |
|
954 | + " ?s $distinguisher ?distinguisher.\n". |
|
955 | + " OPTIONAL {\n". |
|
956 | + " ?distinguisher skos:prefLabel ?distLabel .\n". |
|
957 | + " $distinguishercondLabel\n". |
|
958 | + " }\n". |
|
959 | + " OPTIONAL {\n". |
|
960 | + " ?distinguisher rdfs:label ?distLabel .\n". |
|
961 | + " $distinguishercondLabel\n". |
|
962 | + " }\n". |
|
963 | 963 | "} BIND(COALESCE(?distLabel,STR(?distinguisher)) AS ?distcoal) " : ""; |
964 | 964 | |
965 | 965 | /* |
@@ -1032,20 +1032,20 @@ discard block |
||
1032 | 1032 | $schemecond = ''; |
1033 | 1033 | if (!empty($schemes)) { |
1034 | 1034 | $conditions = array(); |
1035 | - foreach($schemes as $scheme) { |
|
1035 | + foreach ($schemes as $scheme) { |
|
1036 | 1036 | $conditions[] = "{?s skos:inScheme <$scheme>}"; |
1037 | 1037 | } |
1038 | - $schemecond = '{'.implode(" UNION ",$conditions).'}'; |
|
1038 | + $schemecond = '{'.implode(" UNION ", $conditions).'}'; |
|
1039 | 1039 | } |
1040 | - $filterDeprecated=""; |
|
1040 | + $filterDeprecated = ""; |
|
1041 | 1041 | //show or hide deprecated concepts |
1042 | - if(!$showDeprecated){ |
|
1043 | - $filterDeprecated="FILTER NOT EXISTS { ?s owl:deprecated true }"; |
|
1042 | + if (!$showDeprecated) { |
|
1043 | + $filterDeprecated = "FILTER NOT EXISTS { ?s owl:deprecated true }"; |
|
1044 | 1044 | } |
1045 | 1045 | // extra conditions for parent and group, if specified |
1046 | - $parentcond = ($params->getParentLimit()) ? "?s skos:broader+ <" . $params->getParentLimit() . "> ." : ""; |
|
1047 | - $groupcond = ($params->getGroupLimit()) ? "<" . $params->getGroupLimit() . "> skos:member ?s ." : ""; |
|
1048 | - $pgcond = $parentcond . $groupcond; |
|
1046 | + $parentcond = ($params->getParentLimit()) ? "?s skos:broader+ <".$params->getParentLimit()."> ." : ""; |
|
1047 | + $groupcond = ($params->getGroupLimit()) ? "<".$params->getGroupLimit()."> skos:member ?s ." : ""; |
|
1048 | + $pgcond = $parentcond.$groupcond; |
|
1049 | 1049 | |
1050 | 1050 | $orderextra = $this->isDefaultEndpoint() ? $this->graph : ''; |
1051 | 1051 | |
@@ -1134,9 +1134,9 @@ discard block |
||
1134 | 1134 | $hit['type'][] = $this->shortenUri($typeuri); |
1135 | 1135 | } |
1136 | 1136 | |
1137 | - if(!empty($fields)) { |
|
1137 | + if (!empty($fields)) { |
|
1138 | 1138 | foreach ($fields as $prop) { |
1139 | - $propname = $prop . 's'; |
|
1139 | + $propname = $prop.'s'; |
|
1140 | 1140 | if (isset($row->$propname)) { |
1141 | 1141 | foreach (explode("\n", $row->$propname->getValue()) as $line) { |
1142 | 1142 | $rdata = str_getcsv($line, ',', '"', '"'); |
@@ -1151,7 +1151,7 @@ discard block |
||
1151 | 1151 | $propvals = $rdata[2]; |
1152 | 1152 | } |
1153 | 1153 | |
1154 | - $hit['skos:' . $prop][] = $propvals; |
|
1154 | + $hit['skos:'.$prop][] = $propvals; |
|
1155 | 1155 | } |
1156 | 1156 | } |
1157 | 1157 | } |
@@ -1231,7 +1231,7 @@ discard block |
||
1231 | 1231 | * @return array query result object |
1232 | 1232 | */ |
1233 | 1233 | public function queryConcepts($vocabs, $fields, $unique, $params, $showDeprecated = false) { |
1234 | - $query = $this->generateConceptSearchQuery($fields, $unique, $params,$showDeprecated); |
|
1234 | + $query = $this->generateConceptSearchQuery($fields, $unique, $params, $showDeprecated); |
|
1235 | 1235 | $results = $this->query($query); |
1236 | 1236 | return $this->transformConceptSearchResults($results, $vocabs, $fields); |
1237 | 1237 | } |
@@ -1286,10 +1286,10 @@ discard block |
||
1286 | 1286 | $conditions = $this->formatFilterConditions($letter, $lang); |
1287 | 1287 | $filtercondLabel = $conditions['filterpref']; |
1288 | 1288 | $filtercondALabel = $conditions['filteralt']; |
1289 | - $qualifierClause = $qualifier ? "OPTIONAL { ?s <" . $qualifier->getURI() . "> ?qualifier }" : ""; |
|
1290 | - $filterDeprecated=""; |
|
1291 | - if(!$showDeprecated){ |
|
1292 | - $filterDeprecated="FILTER NOT EXISTS { ?s owl:deprecated true }"; |
|
1289 | + $qualifierClause = $qualifier ? "OPTIONAL { ?s <".$qualifier->getURI()."> ?qualifier }" : ""; |
|
1290 | + $filterDeprecated = ""; |
|
1291 | + if (!$showDeprecated) { |
|
1292 | + $filterDeprecated = "FILTER NOT EXISTS { ?s owl:deprecated true }"; |
|
1293 | 1293 | } |
1294 | 1294 | $query = <<<EOQ |
1295 | 1295 | SELECT DISTINCT ?s ?label ?alabel ?qualifier |
@@ -1766,7 +1766,7 @@ discard block |
||
1766 | 1766 | if (!isset($row->label) || $row->label->getLang() === $lang) { |
1767 | 1767 | $ret[$row->object->getUri()] = $val; |
1768 | 1768 | } elseif ($row->label->getLang() === $fallbacklang) { |
1769 | - $val['label'] .= ' (' . $row->label->getLang() . ')'; |
|
1769 | + $val['label'] .= ' ('.$row->label->getLang().')'; |
|
1770 | 1770 | $ret[$row->object->getUri()] = $val; |
1771 | 1771 | } |
1772 | 1772 | } |
@@ -1862,10 +1862,10 @@ discard block |
||
1862 | 1862 | |
1863 | 1863 | $label = null; |
1864 | 1864 | if (isset($row->label)) { |
1865 | - if ($row->label->getLang() == $lang || strpos($row->label->getLang(), $lang . "-") == 0) { |
|
1865 | + if ($row->label->getLang() == $lang || strpos($row->label->getLang(), $lang."-") == 0) { |
|
1866 | 1866 | $label = $row->label->getValue(); |
1867 | 1867 | } else { |
1868 | - $label = $row->label->getValue() . " (" . $row->label->getLang() . ")"; |
|
1868 | + $label = $row->label->getValue()." (".$row->label->getLang().")"; |
|
1869 | 1869 | } |
1870 | 1870 | |
1871 | 1871 | } |
@@ -1941,8 +1941,8 @@ discard block |
||
1941 | 1941 | foreach ($result as $row) { |
1942 | 1942 | if (isset($row->top) && isset($row->label)) { |
1943 | 1943 | $label = $row->label->getValue(); |
1944 | - if ($row->label->getLang() && $row->label->getLang() !== $lang && strpos($row->label->getLang(), $lang . "-") !== 0) { |
|
1945 | - $label .= ' (' . $row->label->getLang() . ')'; |
|
1944 | + if ($row->label->getLang() && $row->label->getLang() !== $lang && strpos($row->label->getLang(), $lang."-") !== 0) { |
|
1945 | + $label .= ' ('.$row->label->getLang().')'; |
|
1946 | 1946 | } |
1947 | 1947 | $top = array('uri' => $row->top->getUri(), 'topConceptOf' => $row->topuri->getUri(), 'label' => $label, 'hasChildren' => filter_var($row->children->getValue(), FILTER_VALIDATE_BOOLEAN)); |
1948 | 1948 | if (isset($row->notation)) { |
@@ -2035,7 +2035,7 @@ discard block |
||
2035 | 2035 | $ret[$uri]['exact'] = $row->exact->getUri(); |
2036 | 2036 | } |
2037 | 2037 | if (isset($row->tops)) { |
2038 | - $topConceptsList=explode(" ", $row->tops->getValue()); |
|
2038 | + $topConceptsList = explode(" ", $row->tops->getValue()); |
|
2039 | 2039 | // sort to guarantee an alphabetical ordering of the URI |
2040 | 2040 | sort($topConceptsList); |
2041 | 2041 | $ret[$uri]['tops'] = $topConceptsList; |
@@ -2048,8 +2048,8 @@ discard block |
||
2048 | 2048 | $label = null; |
2049 | 2049 | if (isset($row->childlabel)) { |
2050 | 2050 | $label = $row->childlabel->getValue(); |
2051 | - if ($row->childlabel->getLang() !== $lang && strpos($row->childlabel->getLang(), $lang . "-") !== 0) { |
|
2052 | - $label .= " (" . $row->childlabel->getLang() . ")"; |
|
2051 | + if ($row->childlabel->getLang() !== $lang && strpos($row->childlabel->getLang(), $lang."-") !== 0) { |
|
2052 | + $label .= " (".$row->childlabel->getLang().")"; |
|
2053 | 2053 | } |
2054 | 2054 | |
2055 | 2055 | } |
@@ -2070,8 +2070,8 @@ discard block |
||
2070 | 2070 | } |
2071 | 2071 | if (isset($row->label)) { |
2072 | 2072 | $preflabel = $row->label->getValue(); |
2073 | - if ($row->label->getLang() && $row->label->getLang() !== $lang && strpos($row->label->getLang(), $lang . "-") !== 0) { |
|
2074 | - $preflabel .= ' (' . $row->label->getLang() . ')'; |
|
2073 | + if ($row->label->getLang() && $row->label->getLang() !== $lang && strpos($row->label->getLang(), $lang."-") !== 0) { |
|
2074 | + $preflabel .= ' ('.$row->label->getLang().')'; |
|
2075 | 2075 | } |
2076 | 2076 | |
2077 | 2077 | $ret[$uri]['prefLabel'] = $preflabel; |
@@ -2192,9 +2192,9 @@ discard block |
||
2192 | 2192 | */ |
2193 | 2193 | private function generateConceptGroupContentsQuery($groupClass, $group, $lang, $showDeprecated = false) { |
2194 | 2194 | $fcl = $this->generateFromClause(); |
2195 | - $filterDeprecated=""; |
|
2196 | - if(!$showDeprecated){ |
|
2197 | - $filterDeprecated=" FILTER NOT EXISTS { ?conc owl:deprecated true }"; |
|
2195 | + $filterDeprecated = ""; |
|
2196 | + if (!$showDeprecated) { |
|
2197 | + $filterDeprecated = " FILTER NOT EXISTS { ?conc owl:deprecated true }"; |
|
2198 | 2198 | } |
2199 | 2199 | $query = <<<EOQ |
2200 | 2200 | SELECT ?conc ?super ?label ?members ?type ?notation $fcl |
@@ -2233,10 +2233,10 @@ discard block |
||
2233 | 2233 | 'type' => array($row->type->shorten()), |
2234 | 2234 | ); |
2235 | 2235 | if (isset($row->label)) { |
2236 | - if ($row->label->getLang() == $lang || strpos($row->label->getLang(), $lang . "-") == 0) { |
|
2236 | + if ($row->label->getLang() == $lang || strpos($row->label->getLang(), $lang."-") == 0) { |
|
2237 | 2237 | $values[$row->conc->getURI()]['prefLabel'] = $row->label->getValue(); |
2238 | 2238 | } else { |
2239 | - $values[$row->conc->getURI()]['prefLabel'] = $row->label->getValue() . " (" . $row->label->getLang() . ")"; |
|
2239 | + $values[$row->conc->getURI()]['prefLabel'] = $row->label->getValue()." (".$row->label->getLang().")"; |
|
2240 | 2240 | } |
2241 | 2241 | |
2242 | 2242 | } |
@@ -2264,8 +2264,8 @@ discard block |
||
2264 | 2264 | * @param boolean $showDeprecated whether to include deprecated concepts in search results |
2265 | 2265 | * @return array Result array with concept URI as key and concept label as value |
2266 | 2266 | */ |
2267 | - public function listConceptGroupContents($groupClass, $group, $lang,$showDeprecated = false) { |
|
2268 | - $query = $this->generateConceptGroupContentsQuery($groupClass, $group, $lang,$showDeprecated); |
|
2267 | + public function listConceptGroupContents($groupClass, $group, $lang, $showDeprecated = false) { |
|
2268 | + $query = $this->generateConceptGroupContentsQuery($groupClass, $group, $lang, $showDeprecated); |
|
2269 | 2269 | $result = $this->query($query); |
2270 | 2270 | return $this->transformConceptGroupContentsResults($result, $lang); |
2271 | 2271 | } |
@@ -2279,9 +2279,9 @@ discard block |
||
2279 | 2279 | * @param boolean $showDeprecated whether to include deprecated concepts in the change list |
2280 | 2280 | * @return string sparql query |
2281 | 2281 | */ |
2282 | - private function generateChangeListQuery($prop, $lang, $offset, $limit=200, $showDeprecated=false) { |
|
2282 | + private function generateChangeListQuery($prop, $lang, $offset, $limit = 200, $showDeprecated = false) { |
|
2283 | 2283 | $fcl = $this->generateFromClause(); |
2284 | - $offset = ($offset) ? 'OFFSET ' . $offset : ''; |
|
2284 | + $offset = ($offset) ? 'OFFSET '.$offset : ''; |
|
2285 | 2285 | |
2286 | 2286 | //Additional clauses when deprecated concepts need to be included in the results |
2287 | 2287 | $deprecatedOptions = ''; |
@@ -2359,7 +2359,7 @@ discard block |
||
2359 | 2359 | * @param boolean $showDeprecated whether to include deprecated concepts in the change list |
2360 | 2360 | * @return array Result array |
2361 | 2361 | */ |
2362 | - public function queryChangeList($prop, $lang, $offset, $limit, $showDeprecated=false) { |
|
2362 | + public function queryChangeList($prop, $lang, $offset, $limit, $showDeprecated = false) { |
|
2363 | 2363 | $query = $this->generateChangeListQuery($prop, $lang, $offset, $limit, $showDeprecated); |
2364 | 2364 | |
2365 | 2365 | $result = $this->query($query); |