@@ -69,8 +69,9 @@ |
||
69 | 69 | { |
70 | 70 | $term = $this->request->getQueryParamRaw('q') ? $this->request->getQueryParamRaw('q') : $this->request->getQueryParamRaw('query'); |
71 | 71 | $term = ($term == 0) ? '0' : $term; |
72 | - if (!$term && $this->rest) |
|
73 | - $term = $this->request->getQueryParamRaw('label'); |
|
72 | + if (!$term && $this->rest) { |
|
73 | + $term = $this->request->getQueryParamRaw('label'); |
|
74 | + } |
|
74 | 75 | $term = trim($term); // surrounding whitespace is not considered significant |
75 | 76 | $term = Normalizer::normalize( $term, Normalizer::FORM_C ); //Normalize decomposed unicode characters #1184 |
76 | 77 | if ($this->rest) { |
@@ -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>" : ''; |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | |
250 | 250 | $quote_string = function($val) { return "'$val'"; }; |
251 | 251 | $quoted_values = array_map($quote_string, $langs); |
252 | - $langFilter = "FILTER(?lang IN (" . implode(',', $quoted_values) . "))"; |
|
252 | + $langFilter = "FILTER(?lang IN (".implode(',', $quoted_values)."))"; |
|
253 | 253 | |
254 | 254 | $values = $this->formatValues('?type', $classes, 'uri'); |
255 | 255 | $valuesProp = $this->formatValues('?prop', $props, null); |
@@ -693,9 +693,9 @@ discard block |
||
693 | 693 | $conceptscheme['title'] = $row->title->getValue(); |
694 | 694 | } |
695 | 695 | // add dct:subject and their labels in the result |
696 | - if(isset($row->domain) && isset($row->domainLabel)){ |
|
697 | - $conceptscheme['subject']['uri']=$row->domain->getURI(); |
|
698 | - $conceptscheme['subject']['prefLabel']=$row->domainLabel->getValue(); |
|
696 | + if (isset($row->domain) && isset($row->domainLabel)) { |
|
697 | + $conceptscheme['subject']['uri'] = $row->domain->getURI(); |
|
698 | + $conceptscheme['subject']['prefLabel'] = $row->domainLabel->getValue(); |
|
699 | 699 | } |
700 | 700 | |
701 | 701 | $ret[$row->cs->getURI()] = $conceptscheme; |
@@ -762,7 +762,7 @@ discard block |
||
762 | 762 | $values[] = "<$graph>"; |
763 | 763 | } |
764 | 764 | if (count($values)) { |
765 | - return "FILTER (?graph IN (" . implode(',', $values) . "))"; |
|
765 | + return "FILTER (?graph IN (".implode(',', $values)."))"; |
|
766 | 766 | } |
767 | 767 | } |
768 | 768 | |
@@ -773,16 +773,16 @@ discard block |
||
773 | 773 | * @return string sparql query clauses |
774 | 774 | */ |
775 | 775 | protected function formatLimitAndOffset($limit, $offset) { |
776 | - $limit = ($limit) ? 'LIMIT ' . $limit : ''; |
|
777 | - $offset = ($offset) ? 'OFFSET ' . $offset : ''; |
|
776 | + $limit = ($limit) ? 'LIMIT '.$limit : ''; |
|
777 | + $offset = ($offset) ? 'OFFSET '.$offset : ''; |
|
778 | 778 | // eliminating whitespace and line changes when the conditions aren't needed. |
779 | 779 | $limitandoffset = ''; |
780 | 780 | if ($limit && $offset) { |
781 | - $limitandoffset = "\n" . $limit . "\n" . $offset; |
|
781 | + $limitandoffset = "\n".$limit."\n".$offset; |
|
782 | 782 | } elseif ($limit) { |
783 | - $limitandoffset = "\n" . $limit; |
|
783 | + $limitandoffset = "\n".$limit; |
|
784 | 784 | } elseif ($offset) { |
785 | - $limitandoffset = "\n" . $offset; |
|
785 | + $limitandoffset = "\n".$offset; |
|
786 | 786 | } |
787 | 787 | |
788 | 788 | return $limitandoffset; |
@@ -922,7 +922,7 @@ discard block |
||
922 | 922 | */ |
923 | 923 | protected function generateConceptSearchQueryInner($term, $lang, $searchLang, $props, $unique, $filterGraph) |
924 | 924 | { |
925 | - error_log('term >>> ' . $term . '<<<<'); |
|
925 | + error_log('term >>> '.$term.'<<<<'); |
|
926 | 926 | $valuesProp = $this->formatValues('?prop', $props); |
927 | 927 | $textcond = $this->generateConceptSearchQueryCondition($term, $searchLang); |
928 | 928 | |
@@ -935,14 +935,14 @@ discard block |
||
935 | 935 | // if search language and UI/display language differ, must also consider case where there is no prefLabel in |
936 | 936 | // the display language; in that case, should use the label with the same language as the matched label |
937 | 937 | $labelcondFallback = ($searchLang != $lang) ? |
938 | - "OPTIONAL { # in case previous OPTIONAL block gives no labels\n" . |
|
938 | + "OPTIONAL { # in case previous OPTIONAL block gives no labels\n". |
|
939 | 939 | "?s skos:prefLabel ?label . FILTER (LANGMATCHES(LANG(?label), LANG(?match))) }" : ""; |
940 | 940 | |
941 | 941 | // Including the labels if there is no query term given. |
942 | 942 | if ($rawterm === '') { |
943 | 943 | $labelClause = "?s skos:prefLabel ?label ."; |
944 | - $labelClause = ($lang) ? $labelClause . " FILTER (LANGMATCHES(LANG(?label), '$lang'))" : $labelClause . ""; |
|
945 | - return $labelClause . " BIND(?label AS ?match)"; |
|
944 | + $labelClause = ($lang) ? $labelClause." FILTER (LANGMATCHES(LANG(?label), '$lang'))" : $labelClause.""; |
|
945 | + return $labelClause." BIND(?label AS ?match)"; |
|
946 | 946 | } |
947 | 947 | |
948 | 948 | /* |
@@ -980,8 +980,8 @@ discard block |
||
980 | 980 | } |
981 | 981 | $hitgroup |
982 | 982 | EOQ; |
983 | - error_log('>>>>>' . $textcond . '<<<<<'); |
|
984 | - error_log('>>>>>' . $query . '<<<<<'); |
|
983 | + error_log('>>>>>'.$textcond.'<<<<<'); |
|
984 | + error_log('>>>>>'.$query.'<<<<<'); |
|
985 | 985 | return $query; |
986 | 986 | } |
987 | 987 | /** |
@@ -1015,20 +1015,20 @@ discard block |
||
1015 | 1015 | $schemecond = ''; |
1016 | 1016 | if (!empty($schemes)) { |
1017 | 1017 | $conditions = array(); |
1018 | - foreach($schemes as $scheme) { |
|
1018 | + foreach ($schemes as $scheme) { |
|
1019 | 1019 | $conditions[] = "{?s skos:inScheme <$scheme>}"; |
1020 | 1020 | } |
1021 | - $schemecond = '{'.implode(" UNION ",$conditions).'}'; |
|
1021 | + $schemecond = '{'.implode(" UNION ", $conditions).'}'; |
|
1022 | 1022 | } |
1023 | - $filterDeprecated=""; |
|
1023 | + $filterDeprecated = ""; |
|
1024 | 1024 | //show or hide deprecated concepts |
1025 | - if(!$showDeprecated){ |
|
1026 | - $filterDeprecated="FILTER NOT EXISTS { ?s owl:deprecated true }"; |
|
1025 | + if (!$showDeprecated) { |
|
1026 | + $filterDeprecated = "FILTER NOT EXISTS { ?s owl:deprecated true }"; |
|
1027 | 1027 | } |
1028 | 1028 | // extra conditions for parent and group, if specified |
1029 | - $parentcond = ($params->getParentLimit()) ? "?s skos:broader+ <" . $params->getParentLimit() . "> ." : ""; |
|
1030 | - $groupcond = ($params->getGroupLimit()) ? "<" . $params->getGroupLimit() . "> skos:member ?s ." : ""; |
|
1031 | - $pgcond = $parentcond . $groupcond; |
|
1029 | + $parentcond = ($params->getParentLimit()) ? "?s skos:broader+ <".$params->getParentLimit()."> ." : ""; |
|
1030 | + $groupcond = ($params->getGroupLimit()) ? "<".$params->getGroupLimit()."> skos:member ?s ." : ""; |
|
1031 | + $pgcond = $parentcond.$groupcond; |
|
1032 | 1032 | |
1033 | 1033 | $orderextra = $this->isDefaultEndpoint() ? $this->graph : ''; |
1034 | 1034 | |
@@ -1114,9 +1114,9 @@ discard block |
||
1114 | 1114 | $hit['type'][] = $this->shortenUri($typeuri); |
1115 | 1115 | } |
1116 | 1116 | |
1117 | - if(!empty($fields)) { |
|
1117 | + if (!empty($fields)) { |
|
1118 | 1118 | foreach ($fields as $prop) { |
1119 | - $propname = $prop . 's'; |
|
1119 | + $propname = $prop.'s'; |
|
1120 | 1120 | if (isset($row->$propname)) { |
1121 | 1121 | foreach (explode("\n", $row->$propname->getValue()) as $line) { |
1122 | 1122 | $rdata = str_getcsv($line, ',', '"', '"'); |
@@ -1131,7 +1131,7 @@ discard block |
||
1131 | 1131 | $propvals = $rdata[2]; |
1132 | 1132 | } |
1133 | 1133 | |
1134 | - $hit['skos:' . $prop][] = $propvals; |
|
1134 | + $hit['skos:'.$prop][] = $propvals; |
|
1135 | 1135 | } |
1136 | 1136 | } |
1137 | 1137 | } |
@@ -1207,7 +1207,7 @@ discard block |
||
1207 | 1207 | * @return array query result object |
1208 | 1208 | */ |
1209 | 1209 | public function queryConcepts($vocabs, $fields = null, $unique = false, $params, $showDeprecated = false) { |
1210 | - $query = $this->generateConceptSearchQuery($fields, $unique, $params,$showDeprecated); |
|
1210 | + $query = $this->generateConceptSearchQuery($fields, $unique, $params, $showDeprecated); |
|
1211 | 1211 | $results = $this->query($query); |
1212 | 1212 | return $this->transformConceptSearchResults($results, $vocabs, $fields); |
1213 | 1213 | } |
@@ -1262,10 +1262,10 @@ discard block |
||
1262 | 1262 | $conditions = $this->formatFilterConditions($letter, $lang); |
1263 | 1263 | $filtercondLabel = $conditions['filterpref']; |
1264 | 1264 | $filtercondALabel = $conditions['filteralt']; |
1265 | - $qualifierClause = $qualifier ? "OPTIONAL { ?s <" . $qualifier->getURI() . "> ?qualifier }" : ""; |
|
1266 | - $filterDeprecated=""; |
|
1267 | - if(!$showDeprecated){ |
|
1268 | - $filterDeprecated="FILTER NOT EXISTS { ?s owl:deprecated true }"; |
|
1265 | + $qualifierClause = $qualifier ? "OPTIONAL { ?s <".$qualifier->getURI()."> ?qualifier }" : ""; |
|
1266 | + $filterDeprecated = ""; |
|
1267 | + if (!$showDeprecated) { |
|
1268 | + $filterDeprecated = "FILTER NOT EXISTS { ?s owl:deprecated true }"; |
|
1269 | 1269 | } |
1270 | 1270 | $query = <<<EOQ |
1271 | 1271 | SELECT DISTINCT ?s ?label ?alabel ?qualifier |
@@ -1742,7 +1742,7 @@ discard block |
||
1742 | 1742 | if (!isset($row->label) || $row->label->getLang() === $lang) { |
1743 | 1743 | $ret[$row->object->getUri()] = $val; |
1744 | 1744 | } elseif ($row->label->getLang() === $fallbacklang) { |
1745 | - $val['label'] .= ' (' . $row->label->getLang() . ')'; |
|
1745 | + $val['label'] .= ' ('.$row->label->getLang().')'; |
|
1746 | 1746 | $ret[$row->object->getUri()] = $val; |
1747 | 1747 | } |
1748 | 1748 | } |
@@ -1838,10 +1838,10 @@ discard block |
||
1838 | 1838 | |
1839 | 1839 | $label = null; |
1840 | 1840 | if (isset($row->label)) { |
1841 | - if ($row->label->getLang() == $lang || strpos($row->label->getLang(), $lang . "-") == 0) { |
|
1841 | + if ($row->label->getLang() == $lang || strpos($row->label->getLang(), $lang."-") == 0) { |
|
1842 | 1842 | $label = $row->label->getValue(); |
1843 | 1843 | } else { |
1844 | - $label = $row->label->getValue() . " (" . $row->label->getLang() . ")"; |
|
1844 | + $label = $row->label->getValue()." (".$row->label->getLang().")"; |
|
1845 | 1845 | } |
1846 | 1846 | |
1847 | 1847 | } |
@@ -1917,8 +1917,8 @@ discard block |
||
1917 | 1917 | foreach ($result as $row) { |
1918 | 1918 | if (isset($row->top) && isset($row->label)) { |
1919 | 1919 | $label = $row->label->getValue(); |
1920 | - if ($row->label->getLang() && $row->label->getLang() !== $lang && strpos($row->label->getLang(), $lang . "-") !== 0) { |
|
1921 | - $label .= ' (' . $row->label->getLang() . ')'; |
|
1920 | + if ($row->label->getLang() && $row->label->getLang() !== $lang && strpos($row->label->getLang(), $lang."-") !== 0) { |
|
1921 | + $label .= ' ('.$row->label->getLang().')'; |
|
1922 | 1922 | } |
1923 | 1923 | $top = array('uri' => $row->top->getUri(), 'topConceptOf' => $row->topuri->getUri(), 'label' => $label, 'hasChildren' => filter_var($row->children->getValue(), FILTER_VALIDATE_BOOLEAN)); |
1924 | 1924 | if (isset($row->notation)) { |
@@ -2011,7 +2011,7 @@ discard block |
||
2011 | 2011 | $ret[$uri]['exact'] = $row->exact->getUri(); |
2012 | 2012 | } |
2013 | 2013 | if (isset($row->tops)) { |
2014 | - $topConceptsList=explode(" ", $row->tops->getValue()); |
|
2014 | + $topConceptsList = explode(" ", $row->tops->getValue()); |
|
2015 | 2015 | // sort to guarantee an alphabetical ordering of the URI |
2016 | 2016 | sort($topConceptsList); |
2017 | 2017 | $ret[$uri]['tops'] = $topConceptsList; |
@@ -2024,8 +2024,8 @@ discard block |
||
2024 | 2024 | $label = null; |
2025 | 2025 | if (isset($row->childlabel)) { |
2026 | 2026 | $label = $row->childlabel->getValue(); |
2027 | - if ($row->childlabel->getLang() !== $lang && strpos($row->childlabel->getLang(), $lang . "-") !== 0) { |
|
2028 | - $label .= " (" . $row->childlabel->getLang() . ")"; |
|
2027 | + if ($row->childlabel->getLang() !== $lang && strpos($row->childlabel->getLang(), $lang."-") !== 0) { |
|
2028 | + $label .= " (".$row->childlabel->getLang().")"; |
|
2029 | 2029 | } |
2030 | 2030 | |
2031 | 2031 | } |
@@ -2046,8 +2046,8 @@ discard block |
||
2046 | 2046 | } |
2047 | 2047 | if (isset($row->label)) { |
2048 | 2048 | $preflabel = $row->label->getValue(); |
2049 | - if ($row->label->getLang() && $row->label->getLang() !== $lang && strpos($row->label->getLang(), $lang . "-") !== 0) { |
|
2050 | - $preflabel .= ' (' . $row->label->getLang() . ')'; |
|
2049 | + if ($row->label->getLang() && $row->label->getLang() !== $lang && strpos($row->label->getLang(), $lang."-") !== 0) { |
|
2050 | + $preflabel .= ' ('.$row->label->getLang().')'; |
|
2051 | 2051 | } |
2052 | 2052 | |
2053 | 2053 | $ret[$uri]['prefLabel'] = $preflabel; |
@@ -2168,9 +2168,9 @@ discard block |
||
2168 | 2168 | */ |
2169 | 2169 | private function generateConceptGroupContentsQuery($groupClass, $group, $lang, $showDeprecated = false) { |
2170 | 2170 | $fcl = $this->generateFromClause(); |
2171 | - $filterDeprecated=""; |
|
2172 | - if(!$showDeprecated){ |
|
2173 | - $filterDeprecated=" FILTER NOT EXISTS { ?conc owl:deprecated true }"; |
|
2171 | + $filterDeprecated = ""; |
|
2172 | + if (!$showDeprecated) { |
|
2173 | + $filterDeprecated = " FILTER NOT EXISTS { ?conc owl:deprecated true }"; |
|
2174 | 2174 | } |
2175 | 2175 | $query = <<<EOQ |
2176 | 2176 | SELECT ?conc ?super ?label ?members ?type ?notation $fcl |
@@ -2209,10 +2209,10 @@ discard block |
||
2209 | 2209 | 'type' => array($row->type->shorten()), |
2210 | 2210 | ); |
2211 | 2211 | if (isset($row->label)) { |
2212 | - if ($row->label->getLang() == $lang || strpos($row->label->getLang(), $lang . "-") == 0) { |
|
2212 | + if ($row->label->getLang() == $lang || strpos($row->label->getLang(), $lang."-") == 0) { |
|
2213 | 2213 | $values[$row->conc->getURI()]['prefLabel'] = $row->label->getValue(); |
2214 | 2214 | } else { |
2215 | - $values[$row->conc->getURI()]['prefLabel'] = $row->label->getValue() . " (" . $row->label->getLang() . ")"; |
|
2215 | + $values[$row->conc->getURI()]['prefLabel'] = $row->label->getValue()." (".$row->label->getLang().")"; |
|
2216 | 2216 | } |
2217 | 2217 | |
2218 | 2218 | } |
@@ -2240,8 +2240,8 @@ discard block |
||
2240 | 2240 | * @param boolean $showDeprecated whether to include deprecated concepts in search results |
2241 | 2241 | * @return array Result array with concept URI as key and concept label as value |
2242 | 2242 | */ |
2243 | - public function listConceptGroupContents($groupClass, $group, $lang,$showDeprecated = false) { |
|
2244 | - $query = $this->generateConceptGroupContentsQuery($groupClass, $group, $lang,$showDeprecated); |
|
2243 | + public function listConceptGroupContents($groupClass, $group, $lang, $showDeprecated = false) { |
|
2244 | + $query = $this->generateConceptGroupContentsQuery($groupClass, $group, $lang, $showDeprecated); |
|
2245 | 2245 | $result = $this->query($query); |
2246 | 2246 | return $this->transformConceptGroupContentsResults($result, $lang); |
2247 | 2247 | } |
@@ -2255,9 +2255,9 @@ discard block |
||
2255 | 2255 | * @param boolean $showDeprecated whether to include deprecated concepts in the change list |
2256 | 2256 | * @return string sparql query |
2257 | 2257 | */ |
2258 | - private function generateChangeListQuery($prop, $lang, $offset, $limit=200, $showDeprecated=false) { |
|
2258 | + private function generateChangeListQuery($prop, $lang, $offset, $limit = 200, $showDeprecated = false) { |
|
2259 | 2259 | $fcl = $this->generateFromClause(); |
2260 | - $offset = ($offset) ? 'OFFSET ' . $offset : ''; |
|
2260 | + $offset = ($offset) ? 'OFFSET '.$offset : ''; |
|
2261 | 2261 | |
2262 | 2262 | //Additional clauses when deprecated concepts need to be included in the results |
2263 | 2263 | $deprecatedOptions = ''; |
@@ -2335,7 +2335,7 @@ discard block |
||
2335 | 2335 | * @param boolean $showDeprecated whether to include deprecated concepts in the change list |
2336 | 2336 | * @return array Result array |
2337 | 2337 | */ |
2338 | - public function queryChangeList($prop, $lang, $offset, $limit, $showDeprecated=false) { |
|
2338 | + public function queryChangeList($prop, $lang, $offset, $limit, $showDeprecated = false) { |
|
2339 | 2339 | $query = $this->generateChangeListQuery($prop, $lang, $offset, $limit, $showDeprecated); |
2340 | 2340 | |
2341 | 2341 | $result = $this->query($query); |