r87919 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87918‎ | r87919 | r87920 >
Date:17:13, 12 May 2011
Author:mkroetzsch
Status:deferred
Tags:
Comment:
support for LIKE comparators in SPARQL store, proper use of helper values in query answering
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SparqlStoreQueryEngine.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SparqlStoreQueryEngine.php
@@ -689,7 +689,13 @@
690690 }
691691
692692 //*** Build the condition ***//
693 - $propertyExpElement = SMWExporter::getResourceElement( $diProperty );
 693+ $typeId = $diProperty->findPropertyTypeID();
 694+ $diType = SMWDataValueFactory::getDataItemId( $typeId );
 695+ if ( SMWExporter::hasHelperExpElement( $diType ) ) {
 696+ $propertyExpElement = SMWExporter::getResourceElementForProperty( $diProperty, true );
 697+ } else {
 698+ $propertyExpElement = SMWExporter::getResourceElementForProperty( $diProperty );
 699+ }
694700 $propertyName = SMWTurtleSerializer::getTurtleNameForExpElement( $propertyExpElement );
695701 if ( $propertyExpElement instanceof SMWExpNsResource ) {
696702 $namespaces[$propertyExpElement->getNamespaceId()] = $propertyExpElement->getNamespace();
@@ -725,7 +731,7 @@
726732 $namespaces = array();
727733 $instExpElement = SMWExporter::getSpecialPropertyResource( '_INST' );
728734 foreach( $description->getCategories() as $diWikiPage ) {
729 - $categoryExpElement = SMWExporter::getResourceElement( $diWikiPage );
 735+ $categoryExpElement = SMWExporter::getResourceElementForWikiPage( $diWikiPage );
730736 $categoryName = SMWTurtleSerializer::getTurtleNameForExpElement( $categoryExpElement );
731737 $namespaces[$categoryExpElement->getNamespaceId()] = $categoryExpElement->getNamespace();
732738 $newcondition = "{ ?$joinVariable " . $instExpElement->getQName() . " $categoryName . }\n";
@@ -787,10 +793,8 @@
788794 case SMW_CMP_LEQ: $comparator = '<='; break;
789795 case SMW_CMP_GEQ: $comparator = '>='; break;
790796 case SMW_CMP_NEQ: $comparator = '!='; break;
791 -// case SMW_CMP_LIKE: case SMW_CMP_NLKE:
792 -// $comparator = ' LIKE ';
793 -// if ( $description->getComparator() == SMW_CMP_NLKE ) $comparator = " NOT{$comparator}";
794 -// $value = str_replace( array( '%', '_', '*', '?' ), array( '\%', '\_', '%', '_' ), $value );
 797+ case SMW_CMP_LIKE: $comparator = 'regex'; break;
 798+ case SMW_CMP_NLKE: $comparator = '!regex'; break;
795799 }
796800
797801 $namespaces = array();
@@ -798,16 +802,27 @@
799803 $expElement = SMWExporter::getDataItemExpElement( $dataItem );
800804 $result = new SMWSparqlSingletonCondition( $expElement );
801805 $this->addOrderByDataForProperty( $result, $joinVariable, $orderByProperty, $dataItem->getDIType() );
802 - } else {
803 - $expElement = SMWExporter::getDataItemExpElement( $dataItem );
 806+ } elseif ( ( $comparator == 'regex' || $comparator == '!regex' ) && ( $dataItem instanceof SMWDIBlob ) ) {
 807+ $pattern = '^' . str_replace( array( '^', '.', '\\', '+', '{', '}', '(', ')', '|', '^', '$', '[', ']', '*', '?' ),
 808+ array( '\^', '\.', '\\\\', '\+', '\{', '\}', '\(', '\)', '\|', '\^', '\$', '\[', '\]', '.*', '.' ),
 809+ $dataItem->getString() ) . '$';
 810+ $result = new SMWSparqlFilterCondition( "$comparator( ?$joinVariable, \"$pattern\", \"s\")", array() );
 811+ $this->addOrderByDataForProperty( $result, $joinVariable, $orderByProperty, $dataItem->getDIType() );
 812+ } elseif ( $comparator != '' ) {
 813+ $expElement = SMWExporter::getDataItemHelperExpElement( $dataItem );
 814+ if ( $expElement === null ) {
 815+ $expElement = SMWExporter::getDataItemExpElement( $dataItem );
 816+ }
804817 $result = new SMWSparqlFilterCondition( '', array() );
805818 $this->addOrderByData( $result, $joinVariable, $dataItem->getDIType() );
806 - $orderVariable = $result->orderByVariable;
 819+ $orderByVariable = $result->orderByVariable;
807820 $valueName = SMWTurtleSerializer::getTurtleNameForExpElement( $expElement );
808821 if ( $expElement instanceof SMWExpNsResource ) {
809822 $result->namespaces[$expElement->getNamespaceId()] = $expElement->getNamespace();
810823 }
811 - $result->filter = "?$orderVariable $comparator $valueName";
 824+ $result->filter = "?$orderByVariable $comparator $valueName";
 825+ } else {
 826+ $result = $this->buildTrueCondition( $joinVariable, $orderByProperty );
812827 }
813828
814829 return $result;

Status & tagging log