r23296 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23295‎ | r23296 | r23297 >
Date:15:56, 23 June 2007
Author:mkroetzsch
Status:old
Tags:
Comment:
Support for auto-hiding subject in singleton queries.
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
@@ -80,8 +80,9 @@
8181 } else {
8282 $mainlabel = $qp->getLabel();
8383 }
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+ }
8687
8788 $query = new SMWQuery($desc);
8889 if ($format == '') {
@@ -254,7 +255,7 @@
255256 while ($continue) {
256257 switch ($chunk) {
257258 case '[[': // start new link block
258 - $ld = $this->getLinkDescription($printrequests);
 259+ $ld = $this->getLinkDescription();
259260 if ($ld === NULL) {
260261 return NULL;
261262 } elseif ($ld instanceof SMWPrintRequest) {
@@ -263,6 +264,10 @@
264265 $result = $this->addDescription($result,$ld);
265266 }
266267 break;
 268+ case '<q>': // enter new subquery, currently irrelevant but possible
 269+ $this->pushDelimiter('</q>');
 270+ $result = $this->addDescription($result, $this->getSubqueryDescription());
 271+ break;
267272 case '</q>': // exit current subquery
268273 if ($this->popDelimiter('</q>')) {
269274 $continue = false; // leave the loop
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php
@@ -149,6 +149,13 @@
150150 * Return a string expressing this query.
151151 */
152152 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+
153160 }
154161
155162 /**
@@ -162,6 +169,10 @@
163170 public function getQueryString() {
164171 return '+';
165172 }
 173+
 174+ public function isSingleton() {
 175+ return false;
 176+ }
166177 }
167178
168179 /**
@@ -186,6 +197,10 @@
187198 return '';
188199 }
189200 }
 201+
 202+ public function isSingleton() {
 203+ return false;
 204+ }
190205 }
191206
192207 /**
@@ -214,6 +229,10 @@
215230 return '';
216231 }
217232 }
 233+
 234+ public function isSingleton() {
 235+ return false;
 236+ }
218237 }
219238
220239 /**
@@ -241,7 +260,10 @@
242261 return '';
243262 }
244263 }
245 -
 264+
 265+ public function isSingleton() {
 266+ return true;
 267+ }
246268 }
247269
248270 /**
@@ -295,6 +317,10 @@
296318 return '+';
297319 }
298320 }
 321+
 322+ public function isSingleton() {
 323+ return false;
 324+ }
299325 }
300326
301327 /**
@@ -325,6 +351,15 @@
326352 }
327353 return $result . '</q>';
328354 }
 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+ }
329364 }
330365
331366 /**
@@ -362,6 +397,16 @@
363398 }
364399 return '<q>' . $result . '</q>';
365400 }
 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+ }
366411 }
367412
368413 /**
@@ -392,6 +437,10 @@
393438 public function getQueryString() {
394439 return '[[' . $this->m_relation->getText() . '::<q>' . $this->m_description->getQueryString() . '</q>]]';
395440 }
 441+
 442+ public function isSingleton() {
 443+ return false;
 444+ }
396445 }
397446
398447 /**
@@ -422,6 +471,10 @@
423472 public function getQueryString() {
424473 return '[[' . $this->m_attribute->getText() . ':=' . $this->m_description->getQueryString() . ']]';
425474 }
 475+
 476+ public function isSingleton() {
 477+ return false;
 478+ }
426479 }
427480
428481

Status & tagging log