Index: trunk/extensions/SemanticMediaWiki/includes/sparql/SMW_SparqlDatabase.php |
— | — | @@ -204,6 +204,21 @@ |
205 | 205 | * @return SMWSparqlResultWrapper |
206 | 206 | */ |
207 | 207 | public function select( $vars, $where, $options = array(), $extraNamespaces = array() ) { |
| 208 | + $sparql = $this->getSparqlForSelect( $vars, $where, $options, $extraNamespaces ); |
| 209 | + return $this->doQuery( $sparql ); |
| 210 | + } |
| 211 | + |
| 212 | + /** |
| 213 | + * Build the SPARQL query that is used by SMWSparqlDatabase::select(). |
| 214 | + * The function declares the standard namespaces wiki, swivt, rdf, owl, |
| 215 | + * rdfs, property, xsd, so these do not have to be included in |
| 216 | + * $extraNamespaces. |
| 217 | + * |
| 218 | + * @param $where string WHERE part of the query, without surrounding { } |
| 219 | + * @param $extraNamespaces array (associative) of namespaceId => namespaceUri |
| 220 | + * @return string SPARQL query |
| 221 | + */ |
| 222 | + public function getSparqlForSelect( $vars, $where, $options = array(), $extraNamespaces = array() ) { |
208 | 223 | $sparql = self::getPrefixString( $extraNamespaces ) . 'SELECT '; |
209 | 224 | if ( array_key_exists( 'DISTINCT', $options ) ) { |
210 | 225 | $sparql .= 'DISTINCT '; |
— | — | @@ -223,8 +238,7 @@ |
224 | 239 | if ( array_key_exists( 'LIMIT', $options ) ) { |
225 | 240 | $sparql .= "\nLIMIT " . $options['LIMIT']; |
226 | 241 | } |
227 | | - |
228 | | - return $this->doQuery( $sparql ); |
| 242 | + return $sparql; |
229 | 243 | } |
230 | 244 | |
231 | 245 | /** |
— | — | @@ -238,11 +252,25 @@ |
239 | 253 | * @return SMWSparqlResultWrapper |
240 | 254 | */ |
241 | 255 | public function ask( $where, $extraNamespaces = array() ) { |
242 | | - $sparql = self::getPrefixString( $extraNamespaces ) . "ASK {\n" . $where . "\n}"; |
| 256 | + $sparql = $this->getSparqlForAsk( $where, $extraNamespaces ); |
243 | 257 | return $this->doQuery( $sparql ); |
244 | 258 | } |
245 | 259 | |
246 | 260 | /** |
| 261 | + * Build the SPARQL query that is used by SMWSparqlDatabase::ask(). |
| 262 | + * The function declares the standard namespaces wiki, swivt, rdf, owl, |
| 263 | + * rdfs, property, xsd, so these do not have to be included in |
| 264 | + * $extraNamespaces. |
| 265 | + * |
| 266 | + * @param $where string WHERE part of the query, without surrounding { } |
| 267 | + * @param $extraNamespaces array (associative) of namespaceId => namespaceUri |
| 268 | + * @return string SPARQL query |
| 269 | + */ |
| 270 | + public function getSparqlForAsk( $where, $extraNamespaces = array() ) { |
| 271 | + return self::getPrefixString( $extraNamespaces ) . "ASK {\n" . $where . "\n}"; |
| 272 | + } |
| 273 | + |
| 274 | + /** |
247 | 275 | * SELECT wrapper for counting results. |
248 | 276 | * The function declares the standard namespaces wiki, swivt, rdf, owl, |
249 | 277 | * rdfs, property, xsd, so these do not have to be included in |