Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php |
— | — | @@ -80,8 +80,9 @@ |
81 | 81 | } else { |
82 | 82 | $mainlabel = $qp->getLabel(); |
83 | 83 | } |
84 | | - ///TODO do this only when wanted: |
85 | | - $desc->prependPrintRequest(new SMWPrintRequest(SMW_PRINT_THIS, $mainlabel)); |
| 84 | + if ( !$desc->isSingleton() || (count($desc->getPrintRequests()) == 0) ) { |
| 85 | + $desc->prependPrintRequest(new SMWPrintRequest(SMW_PRINT_THIS, $mainlabel)); |
| 86 | + } |
86 | 87 | |
87 | 88 | $query = new SMWQuery($desc); |
88 | 89 | if ($format == '') { |
— | — | @@ -254,7 +255,7 @@ |
255 | 256 | while ($continue) { |
256 | 257 | switch ($chunk) { |
257 | 258 | case '[[': // start new link block |
258 | | - $ld = $this->getLinkDescription($printrequests); |
| 259 | + $ld = $this->getLinkDescription(); |
259 | 260 | if ($ld === NULL) { |
260 | 261 | return NULL; |
261 | 262 | } elseif ($ld instanceof SMWPrintRequest) { |
— | — | @@ -263,6 +264,10 @@ |
264 | 265 | $result = $this->addDescription($result,$ld); |
265 | 266 | } |
266 | 267 | break; |
| 268 | + case '<q>': // enter new subquery, currently irrelevant but possible |
| 269 | + $this->pushDelimiter('</q>'); |
| 270 | + $result = $this->addDescription($result, $this->getSubqueryDescription()); |
| 271 | + break; |
267 | 272 | case '</q>': // exit current subquery |
268 | 273 | if ($this->popDelimiter('</q>')) { |
269 | 274 | $continue = false; // leave the loop |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php |
— | — | @@ -149,6 +149,13 @@ |
150 | 150 | * Return a string expressing this query. |
151 | 151 | */ |
152 | 152 | abstract public function getQueryString(); |
| 153 | + |
| 154 | + /** |
| 155 | + * Return true if the description is required to encompass at most a single |
| 156 | + * result, independently of the knowledge base. |
| 157 | + */ |
| 158 | + abstract public function isSingleton(); |
| 159 | + |
153 | 160 | } |
154 | 161 | |
155 | 162 | /** |
— | — | @@ -162,6 +169,10 @@ |
163 | 170 | public function getQueryString() { |
164 | 171 | return '+'; |
165 | 172 | } |
| 173 | + |
| 174 | + public function isSingleton() { |
| 175 | + return false; |
| 176 | + } |
166 | 177 | } |
167 | 178 | |
168 | 179 | /** |
— | — | @@ -186,6 +197,10 @@ |
187 | 198 | return ''; |
188 | 199 | } |
189 | 200 | } |
| 201 | + |
| 202 | + public function isSingleton() { |
| 203 | + return false; |
| 204 | + } |
190 | 205 | } |
191 | 206 | |
192 | 207 | /** |
— | — | @@ -214,6 +229,10 @@ |
215 | 230 | return ''; |
216 | 231 | } |
217 | 232 | } |
| 233 | + |
| 234 | + public function isSingleton() { |
| 235 | + return false; |
| 236 | + } |
218 | 237 | } |
219 | 238 | |
220 | 239 | /** |
— | — | @@ -241,7 +260,10 @@ |
242 | 261 | return ''; |
243 | 262 | } |
244 | 263 | } |
245 | | - |
| 264 | + |
| 265 | + public function isSingleton() { |
| 266 | + return true; |
| 267 | + } |
246 | 268 | } |
247 | 269 | |
248 | 270 | /** |
— | — | @@ -295,6 +317,10 @@ |
296 | 318 | return '+'; |
297 | 319 | } |
298 | 320 | } |
| 321 | + |
| 322 | + public function isSingleton() { |
| 323 | + return false; |
| 324 | + } |
299 | 325 | } |
300 | 326 | |
301 | 327 | /** |
— | — | @@ -325,6 +351,15 @@ |
326 | 352 | } |
327 | 353 | return $result . '</q>'; |
328 | 354 | } |
| 355 | + |
| 356 | + public function isSingleton() { |
| 357 | + foreach ($this->m_descriptions as $d) { |
| 358 | + if ($d->isSingleton()) { |
| 359 | + return true; |
| 360 | + } |
| 361 | + } |
| 362 | + return false; |
| 363 | + } |
329 | 364 | } |
330 | 365 | |
331 | 366 | /** |
— | — | @@ -362,6 +397,16 @@ |
363 | 398 | } |
364 | 399 | return '<q>' . $result . '</q>'; |
365 | 400 | } |
| 401 | + |
| 402 | + public function isSingleton() { |
| 403 | + // NOTE: this neglects the case where several disjuncts describe the same object. |
| 404 | + // I think I cannot really make myself care about this issue ... -- mak |
| 405 | + if (count($this->m_descriptions) != 1) { |
| 406 | + return false; |
| 407 | + } else { |
| 408 | + return $this->m_descriptions[0]->isSingleton(); |
| 409 | + } |
| 410 | + } |
366 | 411 | } |
367 | 412 | |
368 | 413 | /** |
— | — | @@ -392,6 +437,10 @@ |
393 | 438 | public function getQueryString() { |
394 | 439 | return '[[' . $this->m_relation->getText() . '::<q>' . $this->m_description->getQueryString() . '</q>]]'; |
395 | 440 | } |
| 441 | + |
| 442 | + public function isSingleton() { |
| 443 | + return false; |
| 444 | + } |
396 | 445 | } |
397 | 446 | |
398 | 447 | /** |
— | — | @@ -422,6 +471,10 @@ |
423 | 472 | public function getQueryString() { |
424 | 473 | return '[[' . $this->m_attribute->getText() . ':=' . $this->m_description->getQueryString() . ']]'; |
425 | 474 | } |
| 475 | + |
| 476 | + public function isSingleton() { |
| 477 | + return false; |
| 478 | + } |
426 | 479 | } |
427 | 480 | |
428 | 481 | |