@@ -104,11 +104,11 @@ discard block |
||
104 | 104 | { |
105 | 105 | $queryId = sprintf("%05d", rand(0, 99999)); |
106 | 106 | $logger = $this->model->getLogger(); |
107 | - $logger->info("[qid $queryId] SPARQL query:\n" . $this->generateQueryPrefixes($query) . "\n$query\n"); |
|
107 | + $logger->info("[qid $queryId] SPARQL query:\n".$this->generateQueryPrefixes($query)."\n$query\n"); |
|
108 | 108 | $starttime = microtime(true); |
109 | 109 | $result = $this->client->query($query); |
110 | 110 | $elapsed = intval(round((microtime(true) - $starttime) * 1000)); |
111 | - if(method_exists($result, 'numRows')) { |
|
111 | + if (method_exists($result, 'numRows')) { |
|
112 | 112 | $numRows = $result->numRows(); |
113 | 113 | $logger->info("[qid $queryId] result: $numRows rows returned in $elapsed ms"); |
114 | 114 | } else { // graph result |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | */ |
127 | 127 | protected function query($query) |
128 | 128 | { |
129 | - $key = $this->endpoint . " " . $query; |
|
129 | + $key = $this->endpoint." ".$query; |
|
130 | 130 | if (!array_key_exists($key, self::$querycache)) { |
131 | 131 | self::$querycache[$key] = $this->doQuery($query); |
132 | 132 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | * @param Vocabulary[]|null $vocabs |
140 | 140 | * @return string |
141 | 141 | */ |
142 | - protected function generateFromClause($vocabs=null) { |
|
142 | + protected function generateFromClause($vocabs = null) { |
|
143 | 143 | $clause = ''; |
144 | 144 | if (!$vocabs) { |
145 | 145 | return $this->graph !== '?graph' && $this->graph !== NULL ? "FROM <$this->graph>" : ''; |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | |
282 | 282 | $quote_string = function($val) { return "'$val'"; }; |
283 | 283 | $quoted_values = array_map($quote_string, $langs); |
284 | - $langFilter = "FILTER(?lang IN (" . implode(',', $quoted_values) . "))"; |
|
284 | + $langFilter = "FILTER(?lang IN (".implode(',', $quoted_values)."))"; |
|
285 | 285 | |
286 | 286 | $values = $this->formatValues('?type', $classes, 'uri'); |
287 | 287 | $valuesProp = $this->formatValues('?prop', $props, null); |
@@ -725,9 +725,9 @@ discard block |
||
725 | 725 | $conceptscheme['title'] = $row->title->getValue(); |
726 | 726 | } |
727 | 727 | // add dct:subject and their labels in the result |
728 | - if(isset($row->domain) && isset($row->domainLabel)){ |
|
729 | - $conceptscheme['subject']['uri']=$row->domain->getURI(); |
|
730 | - $conceptscheme['subject']['prefLabel']=$row->domainLabel->getValue(); |
|
728 | + if (isset($row->domain) && isset($row->domainLabel)) { |
|
729 | + $conceptscheme['subject']['uri'] = $row->domain->getURI(); |
|
730 | + $conceptscheme['subject']['prefLabel'] = $row->domainLabel->getValue(); |
|
731 | 731 | } |
732 | 732 | |
733 | 733 | $ret[$row->cs->getURI()] = $conceptscheme; |
@@ -794,7 +794,7 @@ discard block |
||
794 | 794 | $values[] = "<$graph>"; |
795 | 795 | } |
796 | 796 | if (count($values)) { |
797 | - return "FILTER (?graph IN (" . implode(',', $values) . "))"; |
|
797 | + return "FILTER (?graph IN (".implode(',', $values)."))"; |
|
798 | 798 | } |
799 | 799 | } |
800 | 800 | |
@@ -805,16 +805,16 @@ discard block |
||
805 | 805 | * @return string sparql query clauses |
806 | 806 | */ |
807 | 807 | protected function formatLimitAndOffset($limit, $offset) { |
808 | - $limit = ($limit) ? 'LIMIT ' . $limit : ''; |
|
809 | - $offset = ($offset) ? 'OFFSET ' . $offset : ''; |
|
808 | + $limit = ($limit) ? 'LIMIT '.$limit : ''; |
|
809 | + $offset = ($offset) ? 'OFFSET '.$offset : ''; |
|
810 | 810 | // eliminating whitespace and line changes when the conditions aren't needed. |
811 | 811 | $limitandoffset = ''; |
812 | 812 | if ($limit && $offset) { |
813 | - $limitandoffset = "\n" . $limit . "\n" . $offset; |
|
813 | + $limitandoffset = "\n".$limit."\n".$offset; |
|
814 | 814 | } elseif ($limit) { |
815 | - $limitandoffset = "\n" . $limit; |
|
815 | + $limitandoffset = "\n".$limit; |
|
816 | 816 | } elseif ($offset) { |
817 | - $limitandoffset = "\n" . $offset; |
|
817 | + $limitandoffset = "\n".$offset; |
|
818 | 818 | } |
819 | 819 | |
820 | 820 | return $limitandoffset; |
@@ -953,7 +953,7 @@ discard block |
||
953 | 953 | * @param string|null $distinguisher SPARQL property path from concept to distinguisher object in case of shared prefLabels |
954 | 954 | * @return string sparql query |
955 | 955 | */ |
956 | - protected function generateConceptSearchQueryInner($term, $lang, $searchLang, $props, $unique, $filterGraph, $distinguisher=null) |
|
956 | + protected function generateConceptSearchQueryInner($term, $lang, $searchLang, $props, $unique, $filterGraph, $distinguisher = null) |
|
957 | 957 | { |
958 | 958 | $valuesProp = $this->formatValues('?prop', $props); |
959 | 959 | $textcond = $this->generateConceptSearchQueryCondition($term, $searchLang); |
@@ -967,31 +967,31 @@ discard block |
||
967 | 967 | // if search language and UI/display language differ, must also consider case where there is no prefLabel in |
968 | 968 | // the display language; in that case, should use the label with the same language as the matched label |
969 | 969 | $labelcondFallback = ($searchLang != $lang) ? |
970 | - "OPTIONAL { # in case previous OPTIONAL block gives no labels\n" . |
|
970 | + "OPTIONAL { # in case previous OPTIONAL block gives no labels\n". |
|
971 | 971 | "?s skos:prefLabel ?label . FILTER (LANGMATCHES(LANG(?label), LANG(?match))) }" : ""; |
972 | 972 | |
973 | 973 | // Including the labels if there is no query term given. |
974 | 974 | if ($rawterm === '') { |
975 | 975 | $labelClause = "?s skos:prefLabel ?label ."; |
976 | - $labelClause = ($lang) ? $labelClause . " FILTER (LANGMATCHES(LANG(?label), '$lang'))" : $labelClause . ""; |
|
977 | - return $labelClause . " BIND(?label AS ?match)"; |
|
976 | + $labelClause = ($lang) ? $labelClause." FILTER (LANGMATCHES(LANG(?label), '$lang'))" : $labelClause.""; |
|
977 | + return $labelClause." BIND(?label AS ?match)"; |
|
978 | 978 | } |
979 | 979 | |
980 | 980 | $distinguishercondLabel = "FILTER (LANG(?distLabel) = LANG(?label))"; |
981 | 981 | // Only include distinguisher labels in case of a shared prefLabel |
982 | 982 | $distinguisherClause = $distinguisher ? |
983 | - "OPTIONAL {\n" . |
|
984 | - " ?s skos:prefLabel ?label . ?s2 skos:prefLabel ?label . FILTER(?s2 != ?s)\n" . |
|
985 | - " ?s $distinguisher ?distinguisher.\n" . |
|
986 | - " FILTER (!isLiteral(?distinguisher) || (LANG(?distinguisher) = LANG(?label)))" . |
|
987 | - " OPTIONAL {\n" . |
|
988 | - " ?distinguisher skos:prefLabel ?distLabel .\n" . |
|
989 | - " $distinguishercondLabel\n" . |
|
990 | - " }\n" . |
|
991 | - " OPTIONAL {\n" . |
|
992 | - " ?distinguisher rdfs:label ?distLabel .\n" . |
|
993 | - " $distinguishercondLabel\n" . |
|
994 | - " }\n" . |
|
983 | + "OPTIONAL {\n". |
|
984 | + " ?s skos:prefLabel ?label . ?s2 skos:prefLabel ?label . FILTER(?s2 != ?s)\n". |
|
985 | + " ?s $distinguisher ?distinguisher.\n". |
|
986 | + " FILTER (!isLiteral(?distinguisher) || (LANG(?distinguisher) = LANG(?label)))". |
|
987 | + " OPTIONAL {\n". |
|
988 | + " ?distinguisher skos:prefLabel ?distLabel .\n". |
|
989 | + " $distinguishercondLabel\n". |
|
990 | + " }\n". |
|
991 | + " OPTIONAL {\n". |
|
992 | + " ?distinguisher rdfs:label ?distLabel .\n". |
|
993 | + " $distinguishercondLabel\n". |
|
994 | + " }\n". |
|
995 | 995 | "} BIND(COALESCE(?distLabel,STR(?distinguisher)) AS ?distcoal) " : ""; |
996 | 996 | |
997 | 997 | /* |
@@ -1064,20 +1064,20 @@ discard block |
||
1064 | 1064 | $schemecond = ''; |
1065 | 1065 | if (!empty($schemes)) { |
1066 | 1066 | $conditions = array(); |
1067 | - foreach($schemes as $scheme) { |
|
1067 | + foreach ($schemes as $scheme) { |
|
1068 | 1068 | $conditions[] = "{?s skos:inScheme <$scheme>}"; |
1069 | 1069 | } |
1070 | - $schemecond = '{'.implode(" UNION ",$conditions).'}'; |
|
1070 | + $schemecond = '{'.implode(" UNION ", $conditions).'}'; |
|
1071 | 1071 | } |
1072 | - $filterDeprecated=""; |
|
1072 | + $filterDeprecated = ""; |
|
1073 | 1073 | //show or hide deprecated concepts |
1074 | - if(!$showDeprecated){ |
|
1075 | - $filterDeprecated="FILTER NOT EXISTS { ?s owl:deprecated true }"; |
|
1074 | + if (!$showDeprecated) { |
|
1075 | + $filterDeprecated = "FILTER NOT EXISTS { ?s owl:deprecated true }"; |
|
1076 | 1076 | } |
1077 | 1077 | // extra conditions for parent and group, if specified |
1078 | - $parentcond = ($params->getParentLimit()) ? "?s skos:broader+ <" . $params->getParentLimit() . "> ." : ""; |
|
1079 | - $groupcond = ($params->getGroupLimit()) ? "<" . $params->getGroupLimit() . "> skos:member ?s ." : ""; |
|
1080 | - $pgcond = $parentcond . $groupcond; |
|
1078 | + $parentcond = ($params->getParentLimit()) ? "?s skos:broader+ <".$params->getParentLimit()."> ." : ""; |
|
1079 | + $groupcond = ($params->getGroupLimit()) ? "<".$params->getGroupLimit()."> skos:member ?s ." : ""; |
|
1080 | + $pgcond = $parentcond.$groupcond; |
|
1081 | 1081 | |
1082 | 1082 | $orderextra = $this->isDefaultEndpoint() ? $this->graph : ''; |
1083 | 1083 | |
@@ -1166,9 +1166,9 @@ discard block |
||
1166 | 1166 | $hit['type'][] = $this->shortenUri($typeuri); |
1167 | 1167 | } |
1168 | 1168 | |
1169 | - if(!empty($fields)) { |
|
1169 | + if (!empty($fields)) { |
|
1170 | 1170 | foreach ($fields as $prop) { |
1171 | - $propname = $prop . 's'; |
|
1171 | + $propname = $prop.'s'; |
|
1172 | 1172 | if (isset($row->$propname)) { |
1173 | 1173 | foreach (explode("\n", $row->$propname->getValue()) as $line) { |
1174 | 1174 | $rdata = str_getcsv($line, ',', '"', '"'); |
@@ -1183,7 +1183,7 @@ discard block |
||
1183 | 1183 | $propvals = $rdata[2]; |
1184 | 1184 | } |
1185 | 1185 | |
1186 | - $hit['skos:' . $prop][] = $propvals; |
|
1186 | + $hit['skos:'.$prop][] = $propvals; |
|
1187 | 1187 | } |
1188 | 1188 | } |
1189 | 1189 | } |
@@ -1263,7 +1263,7 @@ discard block |
||
1263 | 1263 | * @return array query result object |
1264 | 1264 | */ |
1265 | 1265 | public function queryConcepts($vocabs, $fields, $unique, $params, $showDeprecated = false) { |
1266 | - $query = $this->generateConceptSearchQuery($fields, $unique, $params,$showDeprecated); |
|
1266 | + $query = $this->generateConceptSearchQuery($fields, $unique, $params, $showDeprecated); |
|
1267 | 1267 | $results = $this->query($query); |
1268 | 1268 | return $this->transformConceptSearchResults($results, $vocabs, $fields); |
1269 | 1269 | } |
@@ -1318,10 +1318,10 @@ discard block |
||
1318 | 1318 | $conditions = $this->formatFilterConditions($letter, $lang); |
1319 | 1319 | $filtercondLabel = $conditions['filterpref']; |
1320 | 1320 | $filtercondALabel = $conditions['filteralt']; |
1321 | - $qualifierClause = $qualifier ? "OPTIONAL { ?s <" . $qualifier->getURI() . "> ?qualifier }" : ""; |
|
1322 | - $filterDeprecated=""; |
|
1323 | - if(!$showDeprecated){ |
|
1324 | - $filterDeprecated="FILTER NOT EXISTS { ?s owl:deprecated true }"; |
|
1321 | + $qualifierClause = $qualifier ? "OPTIONAL { ?s <".$qualifier->getURI()."> ?qualifier }" : ""; |
|
1322 | + $filterDeprecated = ""; |
|
1323 | + if (!$showDeprecated) { |
|
1324 | + $filterDeprecated = "FILTER NOT EXISTS { ?s owl:deprecated true }"; |
|
1325 | 1325 | } |
1326 | 1326 | $query = <<<EOQ |
1327 | 1327 | SELECT DISTINCT ?s ?label ?alabel ?qualifier |
@@ -1798,7 +1798,7 @@ discard block |
||
1798 | 1798 | if (!isset($row->label) || $row->label->getLang() === $lang) { |
1799 | 1799 | $ret[$row->object->getUri()] = $val; |
1800 | 1800 | } elseif ($row->label->getLang() === $fallbacklang) { |
1801 | - $val['label'] .= ' (' . $row->label->getLang() . ')'; |
|
1801 | + $val['label'] .= ' ('.$row->label->getLang().')'; |
|
1802 | 1802 | $ret[$row->object->getUri()] = $val; |
1803 | 1803 | } |
1804 | 1804 | } |
@@ -1894,10 +1894,10 @@ discard block |
||
1894 | 1894 | |
1895 | 1895 | $label = null; |
1896 | 1896 | if (isset($row->label)) { |
1897 | - if ($row->label->getLang() == $lang || strpos($row->label->getLang(), $lang . "-") == 0) { |
|
1897 | + if ($row->label->getLang() == $lang || strpos($row->label->getLang(), $lang."-") == 0) { |
|
1898 | 1898 | $label = $row->label->getValue(); |
1899 | 1899 | } else { |
1900 | - $label = $row->label->getValue() . " (" . $row->label->getLang() . ")"; |
|
1900 | + $label = $row->label->getValue()." (".$row->label->getLang().")"; |
|
1901 | 1901 | } |
1902 | 1902 | |
1903 | 1903 | } |
@@ -1973,8 +1973,8 @@ discard block |
||
1973 | 1973 | foreach ($result as $row) { |
1974 | 1974 | if (isset($row->top) && isset($row->label)) { |
1975 | 1975 | $label = $row->label->getValue(); |
1976 | - if ($row->label->getLang() && $row->label->getLang() !== $lang && strpos($row->label->getLang(), $lang . "-") !== 0) { |
|
1977 | - $label .= ' (' . $row->label->getLang() . ')'; |
|
1976 | + if ($row->label->getLang() && $row->label->getLang() !== $lang && strpos($row->label->getLang(), $lang."-") !== 0) { |
|
1977 | + $label .= ' ('.$row->label->getLang().')'; |
|
1978 | 1978 | } |
1979 | 1979 | $top = array('uri' => $row->top->getUri(), 'topConceptOf' => $row->topuri->getUri(), 'label' => $label, 'hasChildren' => filter_var($row->children->getValue(), FILTER_VALIDATE_BOOLEAN)); |
1980 | 1980 | if (isset($row->notation)) { |
@@ -2067,7 +2067,7 @@ discard block |
||
2067 | 2067 | $ret[$uri]['exact'] = $row->exact->getUri(); |
2068 | 2068 | } |
2069 | 2069 | if (isset($row->tops)) { |
2070 | - $topConceptsList=explode(" ", $row->tops->getValue()); |
|
2070 | + $topConceptsList = explode(" ", $row->tops->getValue()); |
|
2071 | 2071 | // sort to guarantee an alphabetical ordering of the URI |
2072 | 2072 | sort($topConceptsList); |
2073 | 2073 | $ret[$uri]['tops'] = $topConceptsList; |
@@ -2080,8 +2080,8 @@ discard block |
||
2080 | 2080 | $label = null; |
2081 | 2081 | if (isset($row->childlabel)) { |
2082 | 2082 | $label = $row->childlabel->getValue(); |
2083 | - if ($row->childlabel->getLang() !== $lang && strpos($row->childlabel->getLang(), $lang . "-") !== 0) { |
|
2084 | - $label .= " (" . $row->childlabel->getLang() . ")"; |
|
2083 | + if ($row->childlabel->getLang() !== $lang && strpos($row->childlabel->getLang(), $lang."-") !== 0) { |
|
2084 | + $label .= " (".$row->childlabel->getLang().")"; |
|
2085 | 2085 | } |
2086 | 2086 | |
2087 | 2087 | } |
@@ -2102,8 +2102,8 @@ discard block |
||
2102 | 2102 | } |
2103 | 2103 | if (isset($row->label)) { |
2104 | 2104 | $preflabel = $row->label->getValue(); |
2105 | - if ($row->label->getLang() && $row->label->getLang() !== $lang && strpos($row->label->getLang(), $lang . "-") !== 0) { |
|
2106 | - $preflabel .= ' (' . $row->label->getLang() . ')'; |
|
2105 | + if ($row->label->getLang() && $row->label->getLang() !== $lang && strpos($row->label->getLang(), $lang."-") !== 0) { |
|
2106 | + $preflabel .= ' ('.$row->label->getLang().')'; |
|
2107 | 2107 | } |
2108 | 2108 | |
2109 | 2109 | $ret[$uri]['prefLabel'] = $preflabel; |
@@ -2224,9 +2224,9 @@ discard block |
||
2224 | 2224 | */ |
2225 | 2225 | private function generateConceptGroupContentsQuery($groupClass, $group, $lang, $showDeprecated = false) { |
2226 | 2226 | $fcl = $this->generateFromClause(); |
2227 | - $filterDeprecated=""; |
|
2228 | - if(!$showDeprecated){ |
|
2229 | - $filterDeprecated=" FILTER NOT EXISTS { ?conc owl:deprecated true }"; |
|
2227 | + $filterDeprecated = ""; |
|
2228 | + if (!$showDeprecated) { |
|
2229 | + $filterDeprecated = " FILTER NOT EXISTS { ?conc owl:deprecated true }"; |
|
2230 | 2230 | } |
2231 | 2231 | $query = <<<EOQ |
2232 | 2232 | SELECT ?conc ?super ?label ?members ?type ?notation $fcl |
@@ -2265,10 +2265,10 @@ discard block |
||
2265 | 2265 | 'type' => array($row->type->shorten()), |
2266 | 2266 | ); |
2267 | 2267 | if (isset($row->label)) { |
2268 | - if ($row->label->getLang() == $lang || strpos($row->label->getLang(), $lang . "-") == 0) { |
|
2268 | + if ($row->label->getLang() == $lang || strpos($row->label->getLang(), $lang."-") == 0) { |
|
2269 | 2269 | $values[$row->conc->getURI()]['prefLabel'] = $row->label->getValue(); |
2270 | 2270 | } else { |
2271 | - $values[$row->conc->getURI()]['prefLabel'] = $row->label->getValue() . " (" . $row->label->getLang() . ")"; |
|
2271 | + $values[$row->conc->getURI()]['prefLabel'] = $row->label->getValue()." (".$row->label->getLang().")"; |
|
2272 | 2272 | } |
2273 | 2273 | |
2274 | 2274 | } |
@@ -2296,8 +2296,8 @@ discard block |
||
2296 | 2296 | * @param boolean $showDeprecated whether to include deprecated concepts in search results |
2297 | 2297 | * @return array Result array with concept URI as key and concept label as value |
2298 | 2298 | */ |
2299 | - public function listConceptGroupContents($groupClass, $group, $lang,$showDeprecated = false) { |
|
2300 | - $query = $this->generateConceptGroupContentsQuery($groupClass, $group, $lang,$showDeprecated); |
|
2299 | + public function listConceptGroupContents($groupClass, $group, $lang, $showDeprecated = false) { |
|
2300 | + $query = $this->generateConceptGroupContentsQuery($groupClass, $group, $lang, $showDeprecated); |
|
2301 | 2301 | $result = $this->query($query); |
2302 | 2302 | return $this->transformConceptGroupContentsResults($result, $lang); |
2303 | 2303 | } |
@@ -2311,9 +2311,9 @@ discard block |
||
2311 | 2311 | * @param boolean $showDeprecated whether to include deprecated concepts in the change list |
2312 | 2312 | * @return string sparql query |
2313 | 2313 | */ |
2314 | - private function generateChangeListQuery($prop, $lang, $offset, $limit=200, $showDeprecated=false) { |
|
2314 | + private function generateChangeListQuery($prop, $lang, $offset, $limit = 200, $showDeprecated = false) { |
|
2315 | 2315 | $fcl = $this->generateFromClause(); |
2316 | - $offset = ($offset) ? 'OFFSET ' . $offset : ''; |
|
2316 | + $offset = ($offset) ? 'OFFSET '.$offset : ''; |
|
2317 | 2317 | |
2318 | 2318 | //Additional clauses when deprecated concepts need to be included in the results |
2319 | 2319 | $deprecatedOptions = ''; |
@@ -2403,7 +2403,7 @@ discard block |
||
2403 | 2403 | * @param boolean $showDeprecated whether to include deprecated concepts in the change list |
2404 | 2404 | * @return array Result array |
2405 | 2405 | */ |
2406 | - public function queryChangeList($prop, $lang, $offset, $limit, $showDeprecated=false) { |
|
2406 | + public function queryChangeList($prop, $lang, $offset, $limit, $showDeprecated = false) { |
|
2407 | 2407 | $query = $this->generateChangeListQuery($prop, $lang, $offset, $limit, $showDeprecated); |
2408 | 2408 | |
2409 | 2409 | $result = $this->query($query); |