@@ -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,31 +936,31 @@ 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 | - " FILTER (!isLiteral(?distinguisher) || (LANG(?distinguisher) = LANG(?label)))" . |
|
956 | - " OPTIONAL {\n" . |
|
957 | - " ?distinguisher skos:prefLabel ?distLabel .\n" . |
|
958 | - " $distinguishercondLabel\n" . |
|
959 | - " }\n" . |
|
960 | - " OPTIONAL {\n" . |
|
961 | - " ?distinguisher rdfs:label ?distLabel .\n" . |
|
962 | - " $distinguishercondLabel\n" . |
|
963 | - " }\n" . |
|
952 | + "OPTIONAL {\n". |
|
953 | + " ?s skos:prefLabel ?label . ?s2 skos:prefLabel ?label . FILTER(?s2 != ?s)\n". |
|
954 | + " ?s $distinguisher ?distinguisher.\n". |
|
955 | + " FILTER (!isLiteral(?distinguisher) || (LANG(?distinguisher) = LANG(?label)))". |
|
956 | + " OPTIONAL {\n". |
|
957 | + " ?distinguisher skos:prefLabel ?distLabel .\n". |
|
958 | + " $distinguishercondLabel\n". |
|
959 | + " }\n". |
|
960 | + " OPTIONAL {\n". |
|
961 | + " ?distinguisher rdfs:label ?distLabel .\n". |
|
962 | + " $distinguishercondLabel\n". |
|
963 | + " }\n". |
|
964 | 964 | "} BIND(COALESCE(?distLabel,STR(?distinguisher)) AS ?distcoal) " : ""; |
965 | 965 | |
966 | 966 | /* |
@@ -1033,20 +1033,20 @@ discard block |
||
1033 | 1033 | $schemecond = ''; |
1034 | 1034 | if (!empty($schemes)) { |
1035 | 1035 | $conditions = array(); |
1036 | - foreach($schemes as $scheme) { |
|
1036 | + foreach ($schemes as $scheme) { |
|
1037 | 1037 | $conditions[] = "{?s skos:inScheme <$scheme>}"; |
1038 | 1038 | } |
1039 | - $schemecond = '{'.implode(" UNION ",$conditions).'}'; |
|
1039 | + $schemecond = '{'.implode(" UNION ", $conditions).'}'; |
|
1040 | 1040 | } |
1041 | - $filterDeprecated=""; |
|
1041 | + $filterDeprecated = ""; |
|
1042 | 1042 | //show or hide deprecated concepts |
1043 | - if(!$showDeprecated){ |
|
1044 | - $filterDeprecated="FILTER NOT EXISTS { ?s owl:deprecated true }"; |
|
1043 | + if (!$showDeprecated) { |
|
1044 | + $filterDeprecated = "FILTER NOT EXISTS { ?s owl:deprecated true }"; |
|
1045 | 1045 | } |
1046 | 1046 | // extra conditions for parent and group, if specified |
1047 | - $parentcond = ($params->getParentLimit()) ? "?s skos:broader+ <" . $params->getParentLimit() . "> ." : ""; |
|
1048 | - $groupcond = ($params->getGroupLimit()) ? "<" . $params->getGroupLimit() . "> skos:member ?s ." : ""; |
|
1049 | - $pgcond = $parentcond . $groupcond; |
|
1047 | + $parentcond = ($params->getParentLimit()) ? "?s skos:broader+ <".$params->getParentLimit()."> ." : ""; |
|
1048 | + $groupcond = ($params->getGroupLimit()) ? "<".$params->getGroupLimit()."> skos:member ?s ." : ""; |
|
1049 | + $pgcond = $parentcond.$groupcond; |
|
1050 | 1050 | |
1051 | 1051 | $orderextra = $this->isDefaultEndpoint() ? $this->graph : ''; |
1052 | 1052 | |
@@ -1135,9 +1135,9 @@ discard block |
||
1135 | 1135 | $hit['type'][] = $this->shortenUri($typeuri); |
1136 | 1136 | } |
1137 | 1137 | |
1138 | - if(!empty($fields)) { |
|
1138 | + if (!empty($fields)) { |
|
1139 | 1139 | foreach ($fields as $prop) { |
1140 | - $propname = $prop . 's'; |
|
1140 | + $propname = $prop.'s'; |
|
1141 | 1141 | if (isset($row->$propname)) { |
1142 | 1142 | foreach (explode("\n", $row->$propname->getValue()) as $line) { |
1143 | 1143 | $rdata = str_getcsv($line, ',', '"', '"'); |
@@ -1152,7 +1152,7 @@ discard block |
||
1152 | 1152 | $propvals = $rdata[2]; |
1153 | 1153 | } |
1154 | 1154 | |
1155 | - $hit['skos:' . $prop][] = $propvals; |
|
1155 | + $hit['skos:'.$prop][] = $propvals; |
|
1156 | 1156 | } |
1157 | 1157 | } |
1158 | 1158 | } |
@@ -1232,7 +1232,7 @@ discard block |
||
1232 | 1232 | * @return array query result object |
1233 | 1233 | */ |
1234 | 1234 | public function queryConcepts($vocabs, $fields, $unique, $params, $showDeprecated = false) { |
1235 | - $query = $this->generateConceptSearchQuery($fields, $unique, $params,$showDeprecated); |
|
1235 | + $query = $this->generateConceptSearchQuery($fields, $unique, $params, $showDeprecated); |
|
1236 | 1236 | $results = $this->query($query); |
1237 | 1237 | return $this->transformConceptSearchResults($results, $vocabs, $fields); |
1238 | 1238 | } |
@@ -1287,10 +1287,10 @@ discard block |
||
1287 | 1287 | $conditions = $this->formatFilterConditions($letter, $lang); |
1288 | 1288 | $filtercondLabel = $conditions['filterpref']; |
1289 | 1289 | $filtercondALabel = $conditions['filteralt']; |
1290 | - $qualifierClause = $qualifier ? "OPTIONAL { ?s <" . $qualifier->getURI() . "> ?qualifier }" : ""; |
|
1291 | - $filterDeprecated=""; |
|
1292 | - if(!$showDeprecated){ |
|
1293 | - $filterDeprecated="FILTER NOT EXISTS { ?s owl:deprecated true }"; |
|
1290 | + $qualifierClause = $qualifier ? "OPTIONAL { ?s <".$qualifier->getURI()."> ?qualifier }" : ""; |
|
1291 | + $filterDeprecated = ""; |
|
1292 | + if (!$showDeprecated) { |
|
1293 | + $filterDeprecated = "FILTER NOT EXISTS { ?s owl:deprecated true }"; |
|
1294 | 1294 | } |
1295 | 1295 | $query = <<<EOQ |
1296 | 1296 | SELECT DISTINCT ?s ?label ?alabel ?qualifier |
@@ -1767,7 +1767,7 @@ discard block |
||
1767 | 1767 | if (!isset($row->label) || $row->label->getLang() === $lang) { |
1768 | 1768 | $ret[$row->object->getUri()] = $val; |
1769 | 1769 | } elseif ($row->label->getLang() === $fallbacklang) { |
1770 | - $val['label'] .= ' (' . $row->label->getLang() . ')'; |
|
1770 | + $val['label'] .= ' ('.$row->label->getLang().')'; |
|
1771 | 1771 | $ret[$row->object->getUri()] = $val; |
1772 | 1772 | } |
1773 | 1773 | } |
@@ -1863,10 +1863,10 @@ discard block |
||
1863 | 1863 | |
1864 | 1864 | $label = null; |
1865 | 1865 | if (isset($row->label)) { |
1866 | - if ($row->label->getLang() == $lang || strpos($row->label->getLang(), $lang . "-") == 0) { |
|
1866 | + if ($row->label->getLang() == $lang || strpos($row->label->getLang(), $lang."-") == 0) { |
|
1867 | 1867 | $label = $row->label->getValue(); |
1868 | 1868 | } else { |
1869 | - $label = $row->label->getValue() . " (" . $row->label->getLang() . ")"; |
|
1869 | + $label = $row->label->getValue()." (".$row->label->getLang().")"; |
|
1870 | 1870 | } |
1871 | 1871 | |
1872 | 1872 | } |
@@ -1942,8 +1942,8 @@ discard block |
||
1942 | 1942 | foreach ($result as $row) { |
1943 | 1943 | if (isset($row->top) && isset($row->label)) { |
1944 | 1944 | $label = $row->label->getValue(); |
1945 | - if ($row->label->getLang() && $row->label->getLang() !== $lang && strpos($row->label->getLang(), $lang . "-") !== 0) { |
|
1946 | - $label .= ' (' . $row->label->getLang() . ')'; |
|
1945 | + if ($row->label->getLang() && $row->label->getLang() !== $lang && strpos($row->label->getLang(), $lang."-") !== 0) { |
|
1946 | + $label .= ' ('.$row->label->getLang().')'; |
|
1947 | 1947 | } |
1948 | 1948 | $top = array('uri' => $row->top->getUri(), 'topConceptOf' => $row->topuri->getUri(), 'label' => $label, 'hasChildren' => filter_var($row->children->getValue(), FILTER_VALIDATE_BOOLEAN)); |
1949 | 1949 | if (isset($row->notation)) { |
@@ -2036,7 +2036,7 @@ discard block |
||
2036 | 2036 | $ret[$uri]['exact'] = $row->exact->getUri(); |
2037 | 2037 | } |
2038 | 2038 | if (isset($row->tops)) { |
2039 | - $topConceptsList=explode(" ", $row->tops->getValue()); |
|
2039 | + $topConceptsList = explode(" ", $row->tops->getValue()); |
|
2040 | 2040 | // sort to guarantee an alphabetical ordering of the URI |
2041 | 2041 | sort($topConceptsList); |
2042 | 2042 | $ret[$uri]['tops'] = $topConceptsList; |
@@ -2049,8 +2049,8 @@ discard block |
||
2049 | 2049 | $label = null; |
2050 | 2050 | if (isset($row->childlabel)) { |
2051 | 2051 | $label = $row->childlabel->getValue(); |
2052 | - if ($row->childlabel->getLang() !== $lang && strpos($row->childlabel->getLang(), $lang . "-") !== 0) { |
|
2053 | - $label .= " (" . $row->childlabel->getLang() . ")"; |
|
2052 | + if ($row->childlabel->getLang() !== $lang && strpos($row->childlabel->getLang(), $lang."-") !== 0) { |
|
2053 | + $label .= " (".$row->childlabel->getLang().")"; |
|
2054 | 2054 | } |
2055 | 2055 | |
2056 | 2056 | } |
@@ -2071,8 +2071,8 @@ discard block |
||
2071 | 2071 | } |
2072 | 2072 | if (isset($row->label)) { |
2073 | 2073 | $preflabel = $row->label->getValue(); |
2074 | - if ($row->label->getLang() && $row->label->getLang() !== $lang && strpos($row->label->getLang(), $lang . "-") !== 0) { |
|
2075 | - $preflabel .= ' (' . $row->label->getLang() . ')'; |
|
2074 | + if ($row->label->getLang() && $row->label->getLang() !== $lang && strpos($row->label->getLang(), $lang."-") !== 0) { |
|
2075 | + $preflabel .= ' ('.$row->label->getLang().')'; |
|
2076 | 2076 | } |
2077 | 2077 | |
2078 | 2078 | $ret[$uri]['prefLabel'] = $preflabel; |
@@ -2193,9 +2193,9 @@ discard block |
||
2193 | 2193 | */ |
2194 | 2194 | private function generateConceptGroupContentsQuery($groupClass, $group, $lang, $showDeprecated = false) { |
2195 | 2195 | $fcl = $this->generateFromClause(); |
2196 | - $filterDeprecated=""; |
|
2197 | - if(!$showDeprecated){ |
|
2198 | - $filterDeprecated=" FILTER NOT EXISTS { ?conc owl:deprecated true }"; |
|
2196 | + $filterDeprecated = ""; |
|
2197 | + if (!$showDeprecated) { |
|
2198 | + $filterDeprecated = " FILTER NOT EXISTS { ?conc owl:deprecated true }"; |
|
2199 | 2199 | } |
2200 | 2200 | $query = <<<EOQ |
2201 | 2201 | SELECT ?conc ?super ?label ?members ?type ?notation $fcl |
@@ -2234,10 +2234,10 @@ discard block |
||
2234 | 2234 | 'type' => array($row->type->shorten()), |
2235 | 2235 | ); |
2236 | 2236 | if (isset($row->label)) { |
2237 | - if ($row->label->getLang() == $lang || strpos($row->label->getLang(), $lang . "-") == 0) { |
|
2237 | + if ($row->label->getLang() == $lang || strpos($row->label->getLang(), $lang."-") == 0) { |
|
2238 | 2238 | $values[$row->conc->getURI()]['prefLabel'] = $row->label->getValue(); |
2239 | 2239 | } else { |
2240 | - $values[$row->conc->getURI()]['prefLabel'] = $row->label->getValue() . " (" . $row->label->getLang() . ")"; |
|
2240 | + $values[$row->conc->getURI()]['prefLabel'] = $row->label->getValue()." (".$row->label->getLang().")"; |
|
2241 | 2241 | } |
2242 | 2242 | |
2243 | 2243 | } |
@@ -2265,8 +2265,8 @@ discard block |
||
2265 | 2265 | * @param boolean $showDeprecated whether to include deprecated concepts in search results |
2266 | 2266 | * @return array Result array with concept URI as key and concept label as value |
2267 | 2267 | */ |
2268 | - public function listConceptGroupContents($groupClass, $group, $lang,$showDeprecated = false) { |
|
2269 | - $query = $this->generateConceptGroupContentsQuery($groupClass, $group, $lang,$showDeprecated); |
|
2268 | + public function listConceptGroupContents($groupClass, $group, $lang, $showDeprecated = false) { |
|
2269 | + $query = $this->generateConceptGroupContentsQuery($groupClass, $group, $lang, $showDeprecated); |
|
2270 | 2270 | $result = $this->query($query); |
2271 | 2271 | return $this->transformConceptGroupContentsResults($result, $lang); |
2272 | 2272 | } |
@@ -2280,9 +2280,9 @@ discard block |
||
2280 | 2280 | * @param boolean $showDeprecated whether to include deprecated concepts in the change list |
2281 | 2281 | * @return string sparql query |
2282 | 2282 | */ |
2283 | - private function generateChangeListQuery($prop, $lang, $offset, $limit=200, $showDeprecated=false) { |
|
2283 | + private function generateChangeListQuery($prop, $lang, $offset, $limit = 200, $showDeprecated = false) { |
|
2284 | 2284 | $fcl = $this->generateFromClause(); |
2285 | - $offset = ($offset) ? 'OFFSET ' . $offset : ''; |
|
2285 | + $offset = ($offset) ? 'OFFSET '.$offset : ''; |
|
2286 | 2286 | |
2287 | 2287 | // only consider concepts changed within 1 year from today |
2288 | 2288 | $date = new DateTime(); |
@@ -2384,7 +2384,7 @@ discard block |
||
2384 | 2384 | * @param boolean $showDeprecated whether to include deprecated concepts in the change list |
2385 | 2385 | * @return array Result array |
2386 | 2386 | */ |
2387 | - public function queryChangeList($prop, $lang, $offset, $limit, $showDeprecated=false) { |
|
2387 | + public function queryChangeList($prop, $lang, $offset, $limit, $showDeprecated = false) { |
|
2388 | 2388 | $query = $this->generateChangeListQuery($prop, $lang, $offset, $limit, $showDeprecated); |
2389 | 2389 | |
2390 | 2390 | $result = $this->query($query); |