Completed
Pull Request — master (#930)
by Dan Michael O.
01:51
created
model/sparql/GenericSparql.php 3 patches
Doc Comments   +9 added lines, -5 removed lines patch added patch discarded remove patch
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 
153 153
     /**
154 154
      * Returns the graph instance
155
-     * @return object EasyRDF graph instance.
155
+     * @return string|null EasyRDF graph instance.
156 156
      */
157 157
     public function getGraph() {
158 158
         return $this->graph;
@@ -287,6 +287,7 @@  discard block
 block discarded – undo
287 287
     /**
288 288
      * Counts the number of concepts in a easyRDF graph with a specific language.
289 289
      * @param array $langs Languages to query for
290
+     * @param string[] $classes
290 291
      * @return Array containing count of concepts for each language and property.
291 292
      */
292 293
     public function countLangConcepts($langs, $classes = null) {
@@ -471,7 +472,7 @@  discard block
 block discarded – undo
471 472
      * Returns information (as a graph) for one or more concept URIs
472 473
      * @param mixed $uris concept URI (string) or array of URIs
473 474
      * @param string|null $arrayClass the URI for thesaurus array class, or null if not used
474
-     * @param \Vocabulary[]|null $vocabs vocabularies to target
475
+     * @param Vocabulary[] $vocabs vocabularies to target
475 476
      * @return \EasyRdf\Graph
476 477
      */
477 478
     public function queryConceptInfoGraph($uris, $arrayClass = null, $vocabs = array()) {
@@ -487,7 +488,7 @@  discard block
 block discarded – undo
487 488
 
488 489
     /**
489 490
      * Returns information (as an array of Concept objects) for one or more concept URIs
490
-     * @param mixed $uris concept URI (string) or array of URIs
491
+     * @param string $uris concept URI (string) or array of URIs
491 492
      * @param string|null $arrayClass the URI for thesaurus array class, or null if not used
492 493
      * @param \Vocabulary[] $vocabs vocabularies to target
493 494
      * @param string|null $clang content language
@@ -705,7 +706,7 @@  discard block
 block discarded – undo
705 706
 
706 707
     /**
707 708
      * Generate a VALUES clause for limiting the targeted graphs.
708
-     * @param Vocabulary[]|null $vocabs array of Vocabulary objects to target
709
+     * @param Vocabulary[] $vocabs array of Vocabulary objects to target
709 710
      * @return string VALUES clause, or "" if not necessary to limit
710 711
      */
711 712
     protected function formatValuesGraph($vocabs) {
@@ -887,6 +888,7 @@  discard block
 block discarded – undo
887 888
      * @param string $searchLang language code used for matching labels (null means any language)
888 889
      * @param string[] $props properties to target e.g. array('skos:prefLabel','skos:altLabel')
889 890
      * @param boolean $unique restrict results to unique concepts (default: false)
891
+     * @param string $filterGraph
890 892
      * @return string sparql query
891 893
      */
892 894
     protected function generateConceptSearchQueryInner($term, $lang, $searchLang, $props, $unique, $filterGraph)
@@ -1161,6 +1163,7 @@  discard block
 block discarded – undo
1161 1163
     /**
1162 1164
      * Generates sparql query clauses used for creating the alphabetical index.
1163 1165
      * @param string $letter the letter (or special class) to search for
1166
+     * @param string $lang
1164 1167
      * @return array of sparql query clause strings
1165 1168
      */
1166 1169
     private function formatFilterConditions($letter, $lang) {
@@ -1328,6 +1331,7 @@  discard block
 block discarded – undo
1328 1331
     /**
1329 1332
      * Query for the first characters (letter or otherwise) of the labels in the particular language.
1330 1333
      * @param string $lang language
1334
+     * @param string[] $classes
1331 1335
      * @return array array of characters
1332 1336
      */
1333 1337
     public function queryFirstCharacters($lang, $classes = null) {
@@ -1650,7 +1654,7 @@  discard block
 block discarded – undo
1650 1654
     /**
1651 1655
      * Query a single transitive property of a concept.
1652 1656
      * @param string $uri
1653
-     * @param array $props the property/properties.
1657
+     * @param string[] $props the property/properties.
1654 1658
      * @param string $lang
1655 1659
      * @param string $fallbacklang language to use if label is not available in the preferred language
1656 1660
      * @param integer $limit
Please login to merge, or discard this patch.
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -88,11 +88,11 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
         $graphs = array();
113 113
         $clause = '';
114 114
         if (!$vocabs) {
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
 
237 237
 	$quote_string = function($val) { return "'$val'"; };
238 238
 	$quoted_values = array_map($quote_string, $langs);
239
-	$langFilter = "FILTER(?lang IN (" . implode(',', $quoted_values) . "))";
239
+	$langFilter = "FILTER(?lang IN (".implode(',', $quoted_values)."))";
240 240
 
241 241
         $values = $this->formatValues('?type', $classes, 'uri');
242 242
         $valuesProp = $this->formatValues('?prop', $props, null);
@@ -662,9 +662,9 @@  discard block
 block discarded – undo
662 662
                 $conceptscheme['title'] = $row->title->getValue();
663 663
             }
664 664
             // add dct:subject and their labels in the result
665
-            if(isset($row->domain) && isset($row->domainLabel)){
666
-                $conceptscheme['subject']['uri']=$row->domain->getURI();
667
-                $conceptscheme['subject']['prefLabel']=$row->domainLabel->getValue();
665
+            if (isset($row->domain) && isset($row->domainLabel)) {
666
+                $conceptscheme['subject']['uri'] = $row->domain->getURI();
667
+                $conceptscheme['subject']['prefLabel'] = $row->domainLabel->getValue();
668 668
             }
669 669
 
670 670
             $ret[$row->cs->getURI()] = $conceptscheme;
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
           $values[] = "<$graph>";
732 732
         }
733 733
         if (count($values)) {
734
-          return "FILTER (?graph IN (" . implode(',', $values) . "))";
734
+          return "FILTER (?graph IN (".implode(',', $values)."))";
735 735
         }
736 736
     }
737 737
 
@@ -742,16 +742,16 @@  discard block
 block discarded – undo
742 742
      * @return string sparql query clauses
743 743
      */
744 744
     protected function formatLimitAndOffset($limit, $offset) {
745
-        $limit = ($limit) ? 'LIMIT ' . $limit : '';
746
-        $offset = ($offset) ? 'OFFSET ' . $offset : '';
745
+        $limit = ($limit) ? 'LIMIT '.$limit : '';
746
+        $offset = ($offset) ? 'OFFSET '.$offset : '';
747 747
         // eliminating whitespace and line changes when the conditions aren't needed.
748 748
         $limitandoffset = '';
749 749
         if ($limit && $offset) {
750
-            $limitandoffset = "\n" . $limit . "\n" . $offset;
750
+            $limitandoffset = "\n".$limit."\n".$offset;
751 751
         } elseif ($limit) {
752
-            $limitandoffset = "\n" . $limit;
752
+            $limitandoffset = "\n".$limit;
753 753
         } elseif ($offset) {
754
-            $limitandoffset = "\n" . $offset;
754
+            $limitandoffset = "\n".$offset;
755 755
         }
756 756
 
757 757
         return $limitandoffset;
@@ -903,14 +903,14 @@  discard block
 block discarded – undo
903 903
         // if search language and UI/display language differ, must also consider case where there is no prefLabel in
904 904
         // the display language; in that case, should use the label with the same language as the matched label
905 905
         $labelcondFallback = ($searchLang != $lang) ?
906
-          "OPTIONAL { # in case previous OPTIONAL block gives no labels\n" .
906
+          "OPTIONAL { # in case previous OPTIONAL block gives no labels\n".
907 907
           "?s skos:prefLabel ?label . FILTER (LANGMATCHES(LANG(?label), LANG(?match))) }" : "";
908 908
           
909 909
         //  Including the labels if there is no query term given.
910 910
         if ($rawterm === '') {
911 911
           $labelClause = "?s skos:prefLabel ?label .";
912
-          $labelClause = ($lang) ? $labelClause . " FILTER (LANGMATCHES(LANG(?label), '$lang'))" : $labelClause . "";
913
-          return $labelClause . " BIND(?label AS ?match)";
912
+          $labelClause = ($lang) ? $labelClause." FILTER (LANGMATCHES(LANG(?label), '$lang'))" : $labelClause."";
913
+          return $labelClause." BIND(?label AS ?match)";
914 914
         }
915 915
 
916 916
         /*
@@ -974,20 +974,20 @@  discard block
 block discarded – undo
974 974
         $schemecond = '';
975 975
         if (!empty($schemes)) {
976 976
             $conditions = array();
977
-            foreach($schemes as $scheme) {
977
+            foreach ($schemes as $scheme) {
978 978
                 $conditions[] = "{?s skos:inScheme <$scheme>}";
979 979
             }
980
-            $schemecond = '{'.implode(" UNION ",$conditions).'}';
980
+            $schemecond = '{'.implode(" UNION ", $conditions).'}';
981 981
         }
982
-        $filterDeprecated="";
982
+        $filterDeprecated = "";
983 983
         //show or hide deprecated concepts
984
-        if(!$showDeprecated){
985
-            $filterDeprecated="FILTER NOT EXISTS { ?s owl:deprecated true }";
984
+        if (!$showDeprecated) {
985
+            $filterDeprecated = "FILTER NOT EXISTS { ?s owl:deprecated true }";
986 986
         }
987 987
         // extra conditions for parent and group, if specified
988
-        $parentcond = ($params->getParentLimit()) ? "?s skos:broader+ <" . $params->getParentLimit() . "> ." : "";
989
-        $groupcond = ($params->getGroupLimit()) ? "<" . $params->getGroupLimit() . "> skos:member ?s ." : "";
990
-        $pgcond = $parentcond . $groupcond;
988
+        $parentcond = ($params->getParentLimit()) ? "?s skos:broader+ <".$params->getParentLimit()."> ." : "";
989
+        $groupcond = ($params->getGroupLimit()) ? "<".$params->getGroupLimit()."> skos:member ?s ." : "";
990
+        $pgcond = $parentcond.$groupcond;
991 991
 
992 992
         $orderextra = $this->isDefaultEndpoint() ? $this->graph : '';
993 993
 
@@ -1060,9 +1060,9 @@  discard block
 block discarded – undo
1060 1060
             $hit['type'][] = $this->shortenUri($typeuri);
1061 1061
         }
1062 1062
 
1063
-        if(!empty($fields)) {
1063
+        if (!empty($fields)) {
1064 1064
             foreach ($fields as $prop) {
1065
-                $propname = $prop . 's';
1065
+                $propname = $prop.'s';
1066 1066
                 if (isset($row->$propname)) {
1067 1067
                     foreach (explode("\n", $row->$propname->getValue()) as $line) {
1068 1068
                         $rdata = str_getcsv($line, ',', '"', '"');
@@ -1077,7 +1077,7 @@  discard block
 block discarded – undo
1077 1077
                             $propvals = $rdata[2];
1078 1078
                         }
1079 1079
 
1080
-                        $hit['skos:' . $prop][] = $propvals;
1080
+                        $hit['skos:'.$prop][] = $propvals;
1081 1081
                     }
1082 1082
                 }
1083 1083
             }
@@ -1153,7 +1153,7 @@  discard block
 block discarded – undo
1153 1153
      * @return array query result object
1154 1154
      */
1155 1155
     public function queryConcepts($vocabs, $fields = null, $unique = false, $params, $showDeprecated = false) {
1156
-        $query = $this->generateConceptSearchQuery($fields, $unique, $params,$showDeprecated);
1156
+        $query = $this->generateConceptSearchQuery($fields, $unique, $params, $showDeprecated);
1157 1157
         $results = $this->query($query);
1158 1158
         return $this->transformConceptSearchResults($results, $vocabs, $fields);
1159 1159
     }
@@ -1207,9 +1207,9 @@  discard block
 block discarded – undo
1207 1207
         $conditions = $this->formatFilterConditions($letter, $lang);
1208 1208
         $filtercondLabel = $conditions['filterpref'];
1209 1209
         $filtercondALabel = $conditions['filteralt'];
1210
-        $filterDeprecated="";
1211
-        if(!$showDeprecated){
1212
-            $filterDeprecated="FILTER NOT EXISTS { ?s owl:deprecated true }";
1210
+        $filterDeprecated = "";
1211
+        if (!$showDeprecated) {
1212
+            $filterDeprecated = "FILTER NOT EXISTS { ?s owl:deprecated true }";
1213 1213
         }
1214 1214
         $query = <<<EOQ
1215 1215
 SELECT DISTINCT ?s ?label ?alabel $fcl
@@ -1285,8 +1285,8 @@  discard block
 block discarded – undo
1285 1285
      * @param array $classes
1286 1286
      * @param boolean $showDeprecated whether to include deprecated concepts in the result (default: false)
1287 1287
      */
1288
-    public function queryConceptsAlphabetical($letter, $lang, $limit = null, $offset = null, $classes = null,$showDeprecated = false) {
1289
-        $query = $this->generateAlphabeticalListQuery($letter, $lang, $limit, $offset, $classes,$showDeprecated);
1288
+    public function queryConceptsAlphabetical($letter, $lang, $limit = null, $offset = null, $classes = null, $showDeprecated = false) {
1289
+        $query = $this->generateAlphabeticalListQuery($letter, $lang, $limit, $offset, $classes, $showDeprecated);
1290 1290
         $results = $this->query($query);
1291 1291
         return $this->transformAlphabeticalListResults($results);
1292 1292
     }
@@ -1620,7 +1620,7 @@  discard block
 block discarded – undo
1620 1620
                 if (!isset($row->label) || $row->label->getLang() === $lang) {
1621 1621
                     $ret[$row->object->getUri()] = $val;
1622 1622
                 } elseif ($row->label->getLang() === $fallbacklang) {
1623
-                    $val['label'] .= ' (' . $row->label->getLang() . ')';
1623
+                    $val['label'] .= ' ('.$row->label->getLang().')';
1624 1624
                     $ret[$row->object->getUri()] = $val;
1625 1625
                 }
1626 1626
             }
@@ -1716,10 +1716,10 @@  discard block
 block discarded – undo
1716 1716
 
1717 1717
             $label = null;
1718 1718
             if (isset($row->label)) {
1719
-                if ($row->label->getLang() == $lang || strpos($row->label->getLang(), $lang . "-") == 0) {
1719
+                if ($row->label->getLang() == $lang || strpos($row->label->getLang(), $lang."-") == 0) {
1720 1720
                     $label = $row->label->getValue();
1721 1721
                 } else {
1722
-                    $label = $row->label->getValue() . " (" . $row->label->getLang() . ")";
1722
+                    $label = $row->label->getValue()." (".$row->label->getLang().")";
1723 1723
                 }
1724 1724
 
1725 1725
             }
@@ -1795,8 +1795,8 @@  discard block
 block discarded – undo
1795 1795
         foreach ($result as $row) {
1796 1796
             if (isset($row->top) && isset($row->label)) {
1797 1797
                 $label = $row->label->getValue();
1798
-                if ($row->label->getLang() && $row->label->getLang() !== $lang && strpos($row->label->getLang(), $lang . "-") !== 0) {
1799
-                    $label .= ' (' . $row->label->getLang() . ')';
1798
+                if ($row->label->getLang() && $row->label->getLang() !== $lang && strpos($row->label->getLang(), $lang."-") !== 0) {
1799
+                    $label .= ' ('.$row->label->getLang().')';
1800 1800
                 }
1801 1801
                 $top = array('uri' => $row->top->getUri(), 'topConceptOf' => $row->topuri->getUri(), 'label' => $label, 'hasChildren' => filter_var($row->children->getValue(), FILTER_VALIDATE_BOOLEAN));
1802 1802
                 if (isset($row->notation)) {
@@ -1889,7 +1889,7 @@  discard block
 block discarded – undo
1889 1889
                 $ret[$uri]['exact'] = $row->exact->getUri();
1890 1890
             }
1891 1891
             if (isset($row->tops)) {
1892
-               $topConceptsList=explode(" ", $row->tops->getValue());
1892
+               $topConceptsList = explode(" ", $row->tops->getValue());
1893 1893
                // sort to garantee an alphabetical ordering of the URI
1894 1894
                sort($topConceptsList);
1895 1895
                $ret[$uri]['tops'] = $topConceptsList;
@@ -1902,8 +1902,8 @@  discard block
 block discarded – undo
1902 1902
                 $label = null;
1903 1903
                 if (isset($row->childlabel)) {
1904 1904
                     $label = $row->childlabel->getValue();
1905
-                    if ($row->childlabel->getLang() !== $lang && strpos($row->childlabel->getLang(), $lang . "-") !== 0) {
1906
-                        $label .= " (" . $row->childlabel->getLang() . ")";
1905
+                    if ($row->childlabel->getLang() !== $lang && strpos($row->childlabel->getLang(), $lang."-") !== 0) {
1906
+                        $label .= " (".$row->childlabel->getLang().")";
1907 1907
                     }
1908 1908
 
1909 1909
                 }
@@ -1924,8 +1924,8 @@  discard block
 block discarded – undo
1924 1924
             }
1925 1925
             if (isset($row->label)) {
1926 1926
                 $preflabel = $row->label->getValue();
1927
-                if ($row->label->getLang() && $row->label->getLang() !== $lang && strpos($row->label->getLang(), $lang . "-") !== 0) {
1928
-                    $preflabel .= ' (' . $row->label->getLang() . ')';
1927
+                if ($row->label->getLang() && $row->label->getLang() !== $lang && strpos($row->label->getLang(), $lang."-") !== 0) {
1928
+                    $preflabel .= ' ('.$row->label->getLang().')';
1929 1929
                 }
1930 1930
 
1931 1931
                 $ret[$uri]['prefLabel'] = $preflabel;
@@ -2046,9 +2046,9 @@  discard block
 block discarded – undo
2046 2046
      */
2047 2047
     private function generateConceptGroupContentsQuery($groupClass, $group, $lang, $showDeprecated = false) {
2048 2048
         $fcl = $this->generateFromClause();
2049
-        $filterDeprecated="";
2050
-        if(!$showDeprecated){
2051
-            $filterDeprecated="  FILTER NOT EXISTS { ?conc owl:deprecated true }";
2049
+        $filterDeprecated = "";
2050
+        if (!$showDeprecated) {
2051
+            $filterDeprecated = "  FILTER NOT EXISTS { ?conc owl:deprecated true }";
2052 2052
         }
2053 2053
         $query = <<<EOQ
2054 2054
 SELECT ?conc ?super ?label ?members ?type ?notation $fcl
@@ -2087,10 +2087,10 @@  discard block
 block discarded – undo
2087 2087
                     'type' => array($row->type->shorten()),
2088 2088
                 );
2089 2089
                 if (isset($row->label)) {
2090
-                    if ($row->label->getLang() == $lang || strpos($row->label->getLang(), $lang . "-") == 0) {
2090
+                    if ($row->label->getLang() == $lang || strpos($row->label->getLang(), $lang."-") == 0) {
2091 2091
                         $values[$row->conc->getURI()]['prefLabel'] = $row->label->getValue();
2092 2092
                     } else {
2093
-                        $values[$row->conc->getURI()]['prefLabel'] = $row->label->getValue() . " (" . $row->label->getLang() . ")";
2093
+                        $values[$row->conc->getURI()]['prefLabel'] = $row->label->getValue()." (".$row->label->getLang().")";
2094 2094
                     }
2095 2095
 
2096 2096
                 }
@@ -2118,8 +2118,8 @@  discard block
 block discarded – undo
2118 2118
      * @param boolean $showDeprecated whether to include deprecated concepts in search results
2119 2119
      * @return array Result array with concept URI as key and concept label as value
2120 2120
      */
2121
-    public function listConceptGroupContents($groupClass, $group, $lang,$showDeprecated = false) {
2122
-        $query = $this->generateConceptGroupContentsQuery($groupClass, $group, $lang,$showDeprecated);
2121
+    public function listConceptGroupContents($groupClass, $group, $lang, $showDeprecated = false) {
2122
+        $query = $this->generateConceptGroupContentsQuery($groupClass, $group, $lang, $showDeprecated);
2123 2123
         $result = $this->query($query);
2124 2124
         return $this->transformConceptGroupContentsResults($result, $lang);
2125 2125
     }
@@ -2132,7 +2132,7 @@  discard block
 block discarded – undo
2132 2132
      */
2133 2133
     private function generateChangeListQuery($lang, $offset, $prop) {
2134 2134
         $fcl = $this->generateFromClause();
2135
-        $offset = ($offset) ? 'OFFSET ' . $offset : '';
2135
+        $offset = ($offset) ? 'OFFSET '.$offset : '';
2136 2136
 
2137 2137
         $query = <<<EOQ
2138 2138
 SELECT DISTINCT ?concept ?date ?label $fcl
Please login to merge, or discard this patch.
Braces   +7 added lines, -4 removed lines patch added patch discarded remove patch
@@ -47,12 +47,16 @@  discard block
 block discarded – undo
47 47
         $this->client = new EasyRdf\Sparql\Client($endpoint);
48 48
 
49 49
         // set graphClause so that it can be used by all queries
50
-        if ($this->isDefaultEndpoint()) // default endpoint; query any graph (and catch it in a variable)
50
+        if ($this->isDefaultEndpoint()) {
51
+          // default endpoint; query any graph (and catch it in a variable)
51 52
         {
52 53
             $this->graphClause = "GRAPH $graph";
53
-        } elseif ($graph) // query a specific graph
54
+        }
55
+        } elseif ($graph) {
56
+          // query a specific graph
54 57
         {
55 58
             $this->graphClause = "GRAPH <$graph>";
59
+        }
56 60
         } else // query the default graph
57 61
         {
58 62
             $this->graphClause = "";
@@ -1943,8 +1947,7 @@  discard block
 block discarded – undo
1943 1947
         if (sizeof($ret) > 0) {
1944 1948
             // existing concept, with children
1945 1949
             return $ret;
1946
-        }
1947
-        else {
1950
+        } else {
1948 1951
             // nonexistent concept
1949 1952
             return null;
1950 1953
         }
Please login to merge, or discard this patch.