Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php |
— | — | @@ -132,15 +132,19 @@ |
133 | 133 | public function prune( &$maxsize, &$maxdepth, &$log ) { |
134 | 134 | if ( ( $maxsize < $this->getSize() ) || ( $maxdepth < $this->getDepth() ) ) { |
135 | 135 | $log[] = $this->getQueryString(); |
| 136 | + |
136 | 137 | $result = new SMWThingDescription(); |
137 | 138 | $result->setPrintRequests( $this->getPrintRequests() ); |
| 139 | + |
138 | 140 | return $result; |
139 | 141 | } else { |
140 | 142 | $maxsize = $maxsize - $this->getSize(); |
141 | 143 | $maxdepth = $maxdepth - $this->getDepth(); |
| 144 | + |
142 | 145 | return $this; |
143 | 146 | } |
144 | 147 | } |
| 148 | + |
145 | 149 | } |
146 | 150 | |
147 | 151 | /** |
— | — | @@ -154,7 +158,7 @@ |
155 | 159 | class SMWThingDescription extends SMWDescription { |
156 | 160 | |
157 | 161 | public function getQueryString( $asvalue = false ) { |
158 | | - return $asvalue?'+':''; |
| 162 | + return $asvalue?'+' : ''; |
159 | 163 | } |
160 | 164 | |
161 | 165 | public function isSingleton() { |
— | — | @@ -188,6 +192,7 @@ |
189 | 193 | * @ingroup SMWQuery |
190 | 194 | */ |
191 | 195 | class SMWClassDescription extends SMWDescription { |
| 196 | + |
192 | 197 | protected $m_titles; |
193 | 198 | |
194 | 199 | public function __construct( $content ) { |
— | — | @@ -208,6 +213,7 @@ |
209 | 214 | |
210 | 215 | public function getQueryString( $asvalue = false ) { |
211 | 216 | $first = true; |
| 217 | + |
212 | 218 | foreach ( $this->m_titles as $cat ) { |
213 | 219 | if ( $first ) { |
214 | 220 | $result = '[[' . $cat->getPrefixedText(); |
— | — | @@ -216,7 +222,9 @@ |
217 | 223 | $result .= '||' . $cat->getText(); |
218 | 224 | } |
219 | 225 | } |
| 226 | + |
220 | 227 | $result .= ']]'; |
| 228 | + |
221 | 229 | if ( $asvalue ) { |
222 | 230 | return ' <q>' . $result . '</q> '; |
223 | 231 | } else { |
— | — | @@ -255,9 +263,11 @@ |
256 | 264 | } else { |
257 | 265 | $result = new SMWClassDescription( array_slice( $this->m_titles, 0, $maxsize ) ); |
258 | 266 | $rest = new SMWClassDescription( array_slice( $this->m_titles, $maxsize ) ); |
| 267 | + |
259 | 268 | $log[] = $rest->getQueryString(); |
260 | 269 | $maxsize = 0; |
261 | 270 | } |
| 271 | + |
262 | 272 | $result->setPrintRequests( $this->getPrintRequests() ); |
263 | 273 | return $result; |
264 | 274 | } |
— | — | @@ -272,6 +282,7 @@ |
273 | 283 | * @ingroup SMWQuery |
274 | 284 | */ |
275 | 285 | class SMWConceptDescription extends SMWDescription { |
| 286 | + |
276 | 287 | protected $m_concept; |
277 | 288 | |
278 | 289 | public function __construct( Title $concept ) { |
— | — | @@ -315,6 +326,7 @@ |
316 | 327 | * @ingroup SMWQuery |
317 | 328 | */ |
318 | 329 | class SMWNamespaceDescription extends SMWDescription { |
| 330 | + |
319 | 331 | protected $m_namespace; |
320 | 332 | |
321 | 333 | public function __construct( $namespace ) { |
— | — | @@ -355,6 +367,7 @@ |
356 | 368 | * @ingroup SMWQuery |
357 | 369 | */ |
358 | 370 | class SMWValueDescription extends SMWDescription { |
| 371 | + |
359 | 372 | protected $m_datavalue; |
360 | 373 | protected $m_comparator; |
361 | 374 | |
— | — | @@ -420,6 +433,7 @@ |
421 | 434 | * @ingroup SMWQuery |
422 | 435 | */ |
423 | 436 | class SMWConjunction extends SMWDescription { |
| 437 | + |
424 | 438 | protected $m_descriptions; |
425 | 439 | |
426 | 440 | public function __construct( $descriptions = array() ) { |
— | — | @@ -439,6 +453,7 @@ |
440 | 454 | } else { |
441 | 455 | $this->m_descriptions[] = $description; |
442 | 456 | } |
| 457 | + |
443 | 458 | // move print descriptions downwards |
444 | 459 | ///TODO: This may not be a good solution, since it does modify $description and since it does not react to future changes |
445 | 460 | $this->m_printreqs = array_merge( $this->m_printreqs, $description->getPrintRequests() ); |
— | — | @@ -448,9 +463,11 @@ |
449 | 464 | |
450 | 465 | public function getQueryString( $asvalue = false ) { |
451 | 466 | $result = ''; |
| 467 | + |
452 | 468 | foreach ( $this->m_descriptions as $desc ) { |
453 | 469 | $result .= ( $result ? ' ':'' ) . $desc->getQueryString( false ); |
454 | 470 | } |
| 471 | + |
455 | 472 | if ( $result == '' ) { |
456 | 473 | return $asvalue ? '+':''; |
457 | 474 | } else { // <q> not needed for stand-alone conjunctions (AND binds stronger than OR) |
— | — | @@ -464,22 +481,27 @@ |
465 | 482 | return true; |
466 | 483 | } |
467 | 484 | } |
| 485 | + |
468 | 486 | return false; |
469 | 487 | } |
470 | 488 | |
471 | 489 | public function getSize() { |
472 | 490 | $size = 0; |
| 491 | + |
473 | 492 | foreach ( $this->m_descriptions as $desc ) { |
474 | 493 | $size += $desc->getSize(); |
475 | 494 | } |
| 495 | + |
476 | 496 | return $size; |
477 | 497 | } |
478 | 498 | |
479 | 499 | public function getDepth() { |
480 | 500 | $depth = 0; |
| 501 | + |
481 | 502 | foreach ( $this->m_descriptions as $desc ) { |
482 | 503 | $depth = max( $depth, $desc->getDepth() ); |
483 | 504 | } |
| 505 | + |
484 | 506 | return $depth; |
485 | 507 | } |
486 | 508 | |
— | — | @@ -493,9 +515,11 @@ |
494 | 516 | |
495 | 517 | public function getQueryFeatures() { |
496 | 518 | $result = SMW_CONJUNCTION_QUERY; |
| 519 | + |
497 | 520 | foreach ( $this->m_descriptions as $desc ) { |
498 | 521 | $result = $result | $desc->getQueryFeatures(); |
499 | 522 | } |
| 523 | + |
500 | 524 | return $result; |
501 | 525 | } |
502 | 526 | |
— | — | @@ -504,30 +528,39 @@ |
505 | 529 | $log[] = $this->getQueryString(); |
506 | 530 | return new SMWThingDescription(); |
507 | 531 | } |
| 532 | + |
508 | 533 | $prunelog = array(); |
509 | 534 | $newdepth = $maxdepth; |
510 | 535 | $result = new SMWConjunction(); |
| 536 | + |
511 | 537 | foreach ( $this->m_descriptions as $desc ) { |
512 | 538 | $restdepth = $maxdepth; |
513 | 539 | $result->addDescription( $desc->prune( $maxsize, $restdepth, $prunelog ) ); |
514 | 540 | $newdepth = min( $newdepth, $restdepth ); |
515 | 541 | } |
| 542 | + |
516 | 543 | if ( count( $result->getDescriptions() ) > 0 ) { |
517 | 544 | $log = array_merge( $log, $prunelog ); |
518 | 545 | $maxdepth = $newdepth; |
| 546 | + |
519 | 547 | if ( count( $result->getDescriptions() ) == 1 ) { // simplify unary conjunctions! |
520 | 548 | $descriptions = $result->getDescriptions(); |
521 | 549 | $result = array_shift( $descriptions ); |
522 | 550 | } |
| 551 | + |
523 | 552 | $result->setPrintRequests( $this->getPrintRequests() ); |
| 553 | + |
524 | 554 | return $result; |
525 | 555 | } else { |
526 | 556 | $log[] = $this->getQueryString(); |
| 557 | + |
527 | 558 | $result = new SMWThingDescription(); |
528 | 559 | $result->setPrintRequests( $this->getPrintRequests() ); |
| 560 | + |
529 | 561 | return $result; |
530 | 562 | } |
531 | 563 | } |
| 564 | + |
532 | 565 | } |
533 | 566 | |
534 | 567 | /** |
— | — | @@ -559,6 +592,7 @@ |
560 | 593 | $this->m_descriptions = array(); // no conditions any more |
561 | 594 | $this->m_classdesc = null; |
562 | 595 | } |
| 596 | + |
563 | 597 | if ( !$this->m_true ) { |
564 | 598 | if ( $description instanceof SMWClassDescription ) { // combine class descriptions |
565 | 599 | if ( $this->m_classdesc === null ) { // first class description |
— | — | @@ -577,6 +611,7 @@ |
578 | 612 | $this->m_descriptions[] = $description; |
579 | 613 | } |
580 | 614 | } |
| 615 | + |
581 | 616 | // move print descriptions downwards |
582 | 617 | ///TODO: This may not be a good solution, since it does modify $description and since it does not react to future cahges |
583 | 618 | $this->m_printreqs = array_merge( $this->m_printreqs, $description->getPrintRequests() ); |
— | — | @@ -587,10 +622,13 @@ |
588 | 623 | if ( $this->m_true ) { |
589 | 624 | return '+'; |
590 | 625 | } |
| 626 | + |
591 | 627 | $result = ''; |
592 | 628 | $sep = $asvalue ? '||':' OR '; |
| 629 | + |
593 | 630 | foreach ( $this->m_descriptions as $desc ) { |
594 | 631 | $subdesc = $desc->getQueryString( $asvalue ); |
| 632 | + |
595 | 633 | if ( $desc instanceof SMWSomeProperty ) { // enclose in <q> for parsing |
596 | 634 | if ( $asvalue ) { |
597 | 635 | $subdesc = ' <q>[[' . $subdesc . ']]</q> '; |
— | — | @@ -598,6 +636,7 @@ |
599 | 637 | $subdesc = ' <q>' . $subdesc . '</q> '; |
600 | 638 | } |
601 | 639 | } |
| 640 | + |
602 | 641 | $result .= ( $result ? $sep:'' ) . $subdesc; |
603 | 642 | } |
604 | 643 | if ( $asvalue ) { |
— | — | @@ -618,17 +657,21 @@ |
619 | 658 | |
620 | 659 | public function getSize() { |
621 | 660 | $size = 0; |
| 661 | + |
622 | 662 | foreach ( $this->m_descriptions as $desc ) { |
623 | 663 | $size += $desc->getSize(); |
624 | 664 | } |
| 665 | + |
625 | 666 | return $size; |
626 | 667 | } |
627 | 668 | |
628 | 669 | public function getDepth() { |
629 | 670 | $depth = 0; |
| 671 | + |
630 | 672 | foreach ( $this->m_descriptions as $desc ) { |
631 | 673 | $depth = max( $depth, $desc->getDepth() ); |
632 | 674 | } |
| 675 | + |
633 | 676 | return $depth; |
634 | 677 | } |
635 | 678 | |
— | — | @@ -642,9 +685,11 @@ |
643 | 686 | |
644 | 687 | public function getQueryFeatures() { |
645 | 688 | $result = SMW_DISJUNCTION_QUERY; |
| 689 | + |
646 | 690 | foreach ( $this->m_descriptions as $desc ) { |
647 | 691 | $result = $result | $desc->getQueryFeatures(); |
648 | 692 | } |
| 693 | + |
649 | 694 | return $result; |
650 | 695 | } |
651 | 696 | |
— | — | @@ -653,27 +698,35 @@ |
654 | 699 | $log[] = $this->getQueryString(); |
655 | 700 | return new SMWThingDescription(); |
656 | 701 | } |
| 702 | + |
657 | 703 | $prunelog = array(); |
658 | 704 | $newdepth = $maxdepth; |
659 | 705 | $result = new SMWDisjunction(); |
| 706 | + |
660 | 707 | foreach ( $this->m_descriptions as $desc ) { |
661 | 708 | $restdepth = $maxdepth; |
662 | 709 | $result->addDescription( $desc->prune( $maxsize, $restdepth, $prunelog ) ); |
663 | 710 | $newdepth = min( $newdepth, $restdepth ); |
664 | 711 | } |
| 712 | + |
665 | 713 | if ( count( $result->getDescriptions() ) > 0 ) { |
666 | 714 | $log = array_merge( $log, $prunelog ); |
667 | 715 | $maxdepth = $newdepth; |
| 716 | + |
668 | 717 | if ( count( $result->getDescriptions() ) == 1 ) { // simplify unary disjunctions! |
669 | 718 | $descriptions = $result->getDescriptions(); |
670 | 719 | $result = array_shift( $descriptions ); |
671 | 720 | } |
| 721 | + |
672 | 722 | $result->setPrintRequests( $this->getPrintRequests() ); |
| 723 | + |
673 | 724 | return $result; |
674 | 725 | } else { |
675 | 726 | $log[] = $this->getQueryString(); |
| 727 | + |
676 | 728 | $result = new SMWThingDescription(); |
677 | 729 | $result->setPrintRequests( $this->getPrintRequests() ); |
| 730 | + |
678 | 731 | return $result; |
679 | 732 | } |
680 | 733 | } |
— | — | @@ -689,6 +742,7 @@ |
690 | 743 | * @ingroup SMWQuery |
691 | 744 | */ |
692 | 745 | class SMWSomeProperty extends SMWDescription { |
| 746 | + |
693 | 747 | protected $m_description; |
694 | 748 | protected $m_property; |
695 | 749 | |
— | — | @@ -709,6 +763,7 @@ |
710 | 764 | $subdesc = $this->m_description; |
711 | 765 | $propertychain = $this->m_property->getWikiValue(); |
712 | 766 | $propertyname = 'loop ...'; |
| 767 | + |
713 | 768 | while ( ( $propertyname != '' ) && ( $subdesc instanceof SMWSomeProperty ) ) { // try to use property chain syntax |
714 | 769 | $propertyname = $subdesc->getProperty()->getWikiValue(); |
715 | 770 | if ( $propertyname != '' ) { |
— | — | @@ -716,6 +771,7 @@ |
717 | 772 | $subdesc = $subdesc->getDescription(); |
718 | 773 | } |
719 | 774 | } |
| 775 | + |
720 | 776 | if ( $asvalue ) { |
721 | 777 | return '<q>[[' . $propertychain . '::' . $subdesc->getQueryString( true ) . ']]</q>'; |
722 | 778 | } else { |
— | — | @@ -744,10 +800,14 @@ |
745 | 801 | $log[] = $this->getQueryString(); |
746 | 802 | return new SMWThingDescription(); |
747 | 803 | } |
| 804 | + |
748 | 805 | $maxsize--; |
749 | 806 | $maxdepth--; |
| 807 | + |
750 | 808 | $result = new SMWSomeProperty( $this->m_property, $this->m_description->prune( $maxsize, $maxdepth, $log ) ); |
751 | 809 | $result->setPrintRequests( $this->getPrintRequests() ); |
| 810 | + |
752 | 811 | return $result; |
753 | 812 | } |
| 813 | + |
754 | 814 | } |
\ No newline at end of file |