/**
  * #576
  */
 public function testSortableDateQuery()
 {
     $this->getStore()->updateData($this->fixturesProvider->getFactsheet('Berlin')->asEntity());
     // #576 introduced resource caching, therefore make sure that the
     // instance is cleared after data have been created before further
     // tests are carried out
     Exporter::getInstance()->clear();
     /**
      * @query {{#ask: [[Founded::SomeDistinctValue]] }}
      */
     $foundedValue = $this->fixturesProvider->getFactsheet('Berlin')->getFoundedValue();
     $description = new SomeProperty($foundedValue->getProperty(), new ValueDescription($foundedValue->getDataItem(), null, SMW_CMP_EQ));
     $propertyValue = new PropertyValue('__pro');
     $propertyValue->setDataItem($foundedValue->getProperty());
     $query = new Query($description, false, false);
     $query->querymode = Query::MODE_INSTANCES;
     $query->sortkeys = array($foundedValue->getProperty()->getLabel() => 'ASC');
     // Be aware of
     // Virtuoso 22023 Error SR353: Sorted TOP clause specifies more then
     // 10001 rows to sort. Only 10000 are allowed. Either decrease the
     // offset and/or row count or use a scrollable cursor
     $query->setLimit(100);
     $query->setExtraPrintouts(array(new PrintRequest(PrintRequest::PRINT_THIS, ''), new PrintRequest(PrintRequest::PRINT_PROP, null, $propertyValue)));
     $queryResult = $this->getStore()->getQueryResult($query);
     $this->queryResultValidator->assertThatQueryResultHasSubjects($this->fixturesProvider->getFactsheet('Berlin')->asSubject(), $queryResult);
 }
 private function makeQueryResultForInstance(RepositoryResult $repositoryResult, Query $query)
 {
     $resultDataItems = array();
     foreach ($repositoryResult as $resultRow) {
         if (count($resultRow) > 0 && $resultRow[0] instanceof ExpElement) {
             $dataItem = Exporter::getInstance()->findDataItemForExpElement($resultRow[0]);
             if (!is_null($dataItem)) {
                 $resultDataItems[] = $dataItem;
             }
         }
     }
     if ($repositoryResult->numRows() > $query->getLimit()) {
         if (count($resultDataItems) > 1) {
             array_pop($resultDataItems);
         }
         $hasFurtherResults = true;
     } else {
         $hasFurtherResults = false;
     }
     $result = new QueryResult($query->getDescription()->getPrintrequests(), $query, $resultDataItems, $this->store, $hasFurtherResults);
     switch ($repositoryResult->getErrorCode()) {
         case RepositoryResult::ERROR_NOERROR:
             break;
         case RepositoryResult::ERROR_INCOMPLETE:
             $result->addErrors(array(wfMessage('smw_db_sparqlqueryincomplete')->inContentLanguage()->text()));
             break;
         default:
             $result->addErrors(array(wfMessage('smw_db_sparqlqueryproblem')->inContentLanguage()->text()));
             break;
     }
     return $result;
 }
 public function categoryProvider()
 {
     $stringBuilder = UtilityFactory::getInstance()->newStringBuilder();
     # 0
     $conditionType = '\\SMW\\SPARQLStore\\QueryEngine\\Condition\\FalseCondition';
     $description = new ClassDescription(array());
     $orderByProperty = null;
     $expected = $stringBuilder->addString('<http://www.example.org> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#nothing> .')->addNewLine()->getString();
     $provider[] = array($description, $orderByProperty, $conditionType, $expected);
     # 1
     $conditionType = '\\SMW\\SPARQLStore\\QueryEngine\\Condition\\WhereCondition';
     $category = new DIWikiPage('Foo', NS_CATEGORY);
     $categoryName = \SMWTurtleSerializer::getTurtleNameForExpElement(\SMWExporter::getInstance()->getResourceElementForWikiPage($category));
     $description = new ClassDescription($category);
     $orderByProperty = null;
     $expected = $stringBuilder->addString("{ ?result rdf:type {$categoryName} . }")->addNewLine()->getString();
     $provider[] = array($description, $orderByProperty, $conditionType, $expected);
     # 2
     $conditionType = '\\SMW\\SPARQLStore\\QueryEngine\\Condition\\WhereCondition';
     $categoryFoo = new DIWikiPage('Foo', NS_CATEGORY);
     $categoryFooName = \SMWTurtleSerializer::getTurtleNameForExpElement(\SMWExporter::getInstance()->getResourceElementForWikiPage($categoryFoo));
     $categoryBar = new DIWikiPage('Bar', NS_CATEGORY);
     $categoryBarName = \SMWTurtleSerializer::getTurtleNameForExpElement(\SMWExporter::getInstance()->getResourceElementForWikiPage($categoryBar));
     $description = new ClassDescription(array($categoryFoo, $categoryBar));
     $orderByProperty = null;
     $expected = $stringBuilder->addString("{ ?result rdf:type {$categoryFooName} . }")->addNewLine()->addString('UNION')->addNewLine()->addString("{ ?result rdf:type {$categoryBarName} . }")->addNewLine()->getString();
     $provider[] = array($description, $orderByProperty, $conditionType, $expected);
     # 3
     $conditionType = '\\SMW\\SPARQLStore\\QueryEngine\\Condition\\WhereCondition';
     $description = new ClassDescription(array($categoryFoo, $categoryBar));
     $orderByProperty = new DIProperty('Foo');
     $expected = $stringBuilder->addString('?result swivt:wikiPageSortKey ?resultsk .')->addNewLine()->addString("{ ?result rdf:type {$categoryFooName} . }")->addNewLine()->addString('UNION')->addNewLine()->addString("{ ?result rdf:type {$categoryBarName} . }")->addNewLine()->getString();
     $provider[] = array($description, $orderByProperty, $conditionType, $expected);
     return $provider;
 }
 /**
  * @since 2.4
  *
  * @param Exporter|null $exporter
  */
 public function __construct(Exporter $exporter = null)
 {
     $this->exporter = $exporter;
     if ($this->exporter === null) {
         $this->exporter = Exporter::getInstance();
     }
 }
 protected function serializeHeader()
 {
     $this->namespaces_are_global = true;
     $this->namespace_block_started = true;
     $this->pre_ns_buffer = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . "<!DOCTYPE rdf:RDF[\n" . "\t<!ENTITY rdf " . $this->makeValueEntityString(SMWExporter::getInstance()->expandURI('&rdf;')) . ">\n" . "\t<!ENTITY rdfs " . $this->makeValueEntityString(SMWExporter::getInstance()->expandURI('&rdfs;')) . ">\n" . "\t<!ENTITY owl " . $this->makeValueEntityString(SMWExporter::getInstance()->expandURI('&owl;')) . ">\n" . "\t<!ENTITY swivt " . $this->makeValueEntityString(SMWExporter::getInstance()->expandURI('&swivt;')) . ">\n" . "\t<!ENTITY wiki " . $this->makeValueEntityString(SMWExporter::getInstance()->expandURI('&wiki;')) . ">\n" . "\t<!ENTITY property " . $this->makeValueEntityString(SMWExporter::getInstance()->expandURI('&property;')) . ">\n" . "\t<!ENTITY wikiurl " . $this->makeValueEntityString(SMWExporter::getInstance()->expandURI('&wikiurl;')) . ">\n" . "]>\n\n" . "<rdf:RDF\n" . "\txmlns:rdf=\"&rdf;\"\n" . "\txmlns:rdfs=\"&rdfs;\"\n" . "\txmlns:owl =\"&owl;\"\n" . "\txmlns:swivt=\"&swivt;\"\n" . "\txmlns:wiki=\"&wiki;\"\n" . "\txmlns:property=\"&property;\"";
     $this->global_namespaces = array('rdf' => true, 'rdfs' => true, 'owl' => true, 'swivt' => true, 'wiki' => true, 'property' => true);
     $this->post_ns_buffer .= ">\n\n";
 }
 /**
  * @since 2.5
  *
  * @param Exporter|null $exporter
  */
 public function __construct(Exporter $exporter = null)
 {
     $this->exporter = $exporter;
     if ($this->exporter === null) {
         $this->exporter = Exporter::getInstance();
     }
     $this->inMemoryPoolCache = ApplicationFactory::getInstance()->getInMemoryPoolCache()->getPoolCacheFor(Exporter::POOLCACHE_ID);
 }
 protected function tearDown()
 {
     ApplicationFactory::clear();
     NamespaceExaminer::clear();
     PropertyRegistry::clear();
     Settings::clear();
     Exporter::getInstance()->clear();
     parent::tearDown();
 }
 public function testChunkedTriples()
 {
     $expNsResource = new ExpNsResource('Redirect', Exporter::getInstance()->getNamespaceUri('wiki'), 'Redirect');
     $semanticData = new SemanticData(new DIWikiPage('Foo', NS_MAIN));
     $redirectLookup = $this->getMockBuilder('\\SMW\\SPARQLStore\\RedirectLookup')->disableOriginalConstructor()->getMock();
     $redirectLookup->expects($this->atLeastOnce())->method('findRedirectTargetResource')->will($this->returnValue($expNsResource));
     $instance = new TurtleTriplesBuilder($semanticData, $redirectLookup);
     $instance->setTriplesChunkSize(1);
     $this->assertInternalType('array', $instance->getChunkedTriples());
 }
Esempio n. 9
0
 public function testExportPageWithNumericProperty()
 {
     $semanticData = $this->semanticDataFactory->newEmptySemanticData(__METHOD__);
     $property = new DIProperty('123');
     $semanticData->addPropertyObjectValue($property, new DIWikiPage('345', NS_MAIN));
     $exportData = Exporter::makeExportData($semanticData);
     $expectedProperty = new ExpNsResource(Exporter::getInstance()->getEncodedPropertyNamespace() . '123', Exporter::getNamespaceUri('wiki'), 'wiki', new DIWikiPage('123', SMW_NS_PROPERTY));
     $this->assertCount(1, $exportData->getValues($expectedProperty));
     $this->exportDataValidator->assertThatExportDataContainsProperty($expectedProperty, $exportData);
     $expectedResourceElement = new ExpNsResource('345', Exporter::getNamespaceUri('wiki'), 'wiki', new DIWikiPage('345', NS_MAIN));
     $this->exportDataValidator->assertThatExportDataContainsResource($expectedResourceElement, $expectedProperty, $exportData);
 }
 protected function tearDown()
 {
     // If setUp is skipped early this might not be initialized
     if ($this->testEnvironment !== null) {
         $this->testEnvironment->tearDown();
     }
     ApplicationFactory::clear();
     NamespaceExaminer::clear();
     PropertyRegistry::clear();
     Settings::clear();
     Exporter::getInstance()->clear();
     parent::tearDown();
 }
 private function addListenersToCollection()
 {
     $this->eventListenerCollection->registerCallback('exporter.reset', function () {
         Exporter::getInstance()->clear();
     });
     $this->eventListenerCollection->registerCallback('property.spec.change', function ($dispatchContext) {
         $subject = $dispatchContext->get('subject');
         $updateDispatcherJob = ApplicationFactory::getInstance()->newJobFactory()->newUpdateDispatcherJob($subject->getTitle());
         $updateDispatcherJob->run();
         Exporter::getInstance()->resetCacheFor($subject);
         $dispatchContext->set('propagationstop', true);
     });
     return $this->eventListenerCollection;
 }
 public function testDeleteSubjectOnMockBaseStore()
 {
     $title = Title::newFromText('DeleteSubjectOnMockBaseStore');
     $expResource = Exporter::getInstance()->getDataItemExpElement(DIWikiPage::newFromTitle($title));
     $resourceUri = TurtleSerializer::getTurtleNameForExpElement($expResource);
     $extraNamespaces = array($expResource->getNamespaceId() => $expResource->getNamespace());
     $baseStore = $this->getMockBuilder('\\SMWStore')->disableOriginalConstructor()->getMockForAbstractClass();
     $baseStore->expects($this->once())->method('deleteSubject')->with($this->equalTo($title))->will($this->returnValue(true));
     $sparqlDatabase = $this->getMockBuilder('\\SMWSparqlDatabase')->disableOriginalConstructor()->getMock();
     $sparqlDatabase->expects($this->once())->method('deleteContentByValue')->will($this->returnValue(true));
     $sparqlDatabase->expects($this->once())->method('delete')->with($this->equalTo("{$resourceUri} ?p ?o"), $this->equalTo("{$resourceUri} ?p ?o"), $this->equalTo($extraNamespaces))->will($this->returnValue(true));
     $connectionManager = $this->getMockBuilder('\\SMW\\ConnectionManager')->disableOriginalConstructor()->getMock();
     $connectionManager->expects($this->any())->method('getConnection')->will($this->returnValue($sparqlDatabase));
     $instance = new SPARQLStore($baseStore);
     $instance->setConnectionManager($connectionManager);
     $instance->deleteSubject($title);
 }
 private function registerStateChangeEvents()
 {
     /**
      * Emitted during PropertySpecificationChangeNotifier::notifyDispatcher
      */
     $this->eventListenerCollection->registerCallback('property.specification.change', function ($dispatchContext) {
         $applicationFactory = ApplicationFactory::getInstance();
         $subject = $dispatchContext->get('subject');
         $updateDispatcherJob = $applicationFactory->newJobFactory()->newUpdateDispatcherJob($subject->getTitle());
         $updateDispatcherJob->run();
         Exporter::getInstance()->resetCacheBy($subject);
         $applicationFactory->getPropertySpecificationLookup()->resetCacheBy($subject);
         $dispatchContext->set('propagationstop', true);
     });
     /**
      * Emitted during Store::updateData
      */
     $this->eventListenerCollection->registerCallback('on.before.semanticdata.update.complete', function ($dispatchContext) {
         $subject = $dispatchContext->get('subject');
         $hash = $subject->getHash();
         $applicationFactory = ApplicationFactory::getInstance();
         $poolCache = $applicationFactory->getInMemoryPoolCache()->getPoolCacheFor('store.redirectTarget.lookup');
         $poolCache->delete($hash);
         $dispatchContext->set('propagationstop', true);
     });
     /**
      * Emitted during Store::updateData
      */
     $this->eventListenerCollection->registerCallback('on.after.semanticdata.update.complete', function ($dispatchContext) {
         $applicationFactory = ApplicationFactory::getInstance();
         $subject = $dispatchContext->get('subject');
         $pageUpdater = $applicationFactory->newMwCollaboratorFactory()->newPageUpdater();
         if ($GLOBALS['smwgAutoRefreshSubject'] && $pageUpdater->canUpdate()) {
             $pageUpdater->addPage($subject->getTitle());
             $deferredCallableUpdate = $applicationFactory->newDeferredCallableUpdate(function () use($pageUpdater) {
                 $pageUpdater->doPurgeParserCache();
                 $pageUpdater->doPurgeHtmlCache();
             });
             $deferredCallableUpdate->setOrigin('Event on.after.semanticdata.update.complete doPurgeParserCache for ' . $subject->getHash());
             $deferredCallableUpdate->pushToUpdateQueue();
         }
         $dispatchContext->set('propagationstop', true);
     });
 }
 private function addListenersToCollection()
 {
     $this->eventListenerCollection->registerCallback('factbox.cache.delete', function ($dispatchContext) {
         $title = $dispatchContext->get('title');
         $cache = ApplicationFactory::getInstance()->getCache();
         $cache->delete(ApplicationFactory::getInstance()->newCacheFactory()->getFactboxCacheKey($title->getArticleID()));
     });
     $this->eventListenerCollection->registerCallback('exporter.reset', function () {
         Exporter::getInstance()->clear();
     });
     $this->eventListenerCollection->registerCallback('query.comparator.reset', function () {
         QueryComparator::getInstance()->clear();
     });
     $this->eventListenerCollection->registerCallback('property.spec.change', function ($dispatchContext) {
         $subject = $dispatchContext->get('subject');
         $updateDispatcherJob = ApplicationFactory::getInstance()->newJobFactory()->newUpdateDispatcherJob($subject->getTitle());
         $updateDispatcherJob->run();
         Exporter::getInstance()->resetCacheFor($subject);
         $dispatchContext->set('propagationstop', true);
     });
     return $this->eventListenerCollection;
 }
 public function diWikiPageProvider()
 {
     // Constant
     $wiki = \SMWExporter::getInstance()->getNamespaceUri('wiki');
     $property = \SMWExporter::getInstance()->getNamespaceUri('property');
     #0
     $provider[] = array(new DIWikiPage('Foo', NS_MAIN, '', ''), '', array('type' => Element::TYPE_NSRESOURCE, 'uri' => "Foo|{$wiki}|wiki", 'dataitem' => array('type' => 9, 'item' => 'Foo#0#')));
     #1
     $provider[] = array(new DIWikiPage('Foo', NS_MAIN, 'bar', ''), '', array('type' => Element::TYPE_NSRESOURCE, 'uri' => "bar-3AFoo|{$wiki}|wiki", 'dataitem' => array('type' => 9, 'item' => 'Foo#0#bar')));
     #2
     $provider[] = array(new DIWikiPage('Foo', NS_MAIN, 'bar', '1234'), '', array('type' => Element::TYPE_NSRESOURCE, 'uri' => "bar-3AFoo-231234|{$wiki}|wiki", 'dataitem' => array('type' => 9, 'item' => 'Foo#0#bar#1234')));
     #3 Extra modififer doesn't not alter the object when a subobject is used
     $provider[] = array(new DIWikiPage('Foo', NS_MAIN, 'bar', '1234'), 'abc', array('type' => Element::TYPE_NSRESOURCE, 'uri' => "bar-3AFoo-231234|{$wiki}|wiki", 'dataitem' => array('type' => 9, 'item' => 'Foo#0#bar#1234')));
     #4
     $provider[] = array(new DIWikiPage('Foo', SMW_NS_PROPERTY, '', ''), '', array('type' => Element::TYPE_NSRESOURCE, 'uri' => "Foo|{$property}|property", 'dataitem' => array('type' => 9, 'item' => 'Foo#102#')));
     #5
     $provider[] = array(new DIWikiPage('Foo', SMW_NS_PROPERTY, '', ''), true, array('type' => Element::TYPE_NSRESOURCE, 'uri' => "Foo-23aux|{$property}|property", 'dataitem' => array('type' => 9, 'item' => 'Foo#102#')));
     #6
     $name = Escaper::encodePage(new DIWikiPage('-Foo', SMW_NS_PROPERTY, '', ''));
     $provider[] = array(new DIWikiPage('-Foo', SMW_NS_PROPERTY, '', ''), true, array('type' => Element::TYPE_NSRESOURCE, 'uri' => "{$name}-23aux|{$wiki}|wiki", 'dataitem' => array('type' => 9, 'item' => '-Foo#102#')));
     return $provider;
 }
 /**
  * @since 2.1
  *
  * @param CompoundConditionBuilder|null $compoundConditionBuilder
  */
 public function __construct(CompoundConditionBuilder $compoundConditionBuilder = null)
 {
     $this->compoundConditionBuilder = $compoundConditionBuilder;
     $this->exporter = Exporter::getInstance();
 }
 /**
  * Create the standard PREFIX declarations for SPARQL or Turtle,
  * possibly with additional namespaces involved.
  *
  * @param $extraNamespaces array (associative) of namespaceId => namespaceUri
  * @param $forSparql boolean true to use SPARQL prefix syntax, false to use Turtle prefix syntax
  *
  * @return string
  */
 public static function getPrefixString($extraNamespaces = array(), $forSparql = true)
 {
     $prefixString = '';
     $prefixIntro = $forSparql ? 'PREFIX ' : '@prefix ';
     $prefixOutro = $forSparql ? "\n" : " .\n";
     foreach (array('wiki', 'rdf', 'rdfs', 'owl', 'swivt', 'property', 'xsd') as $shortname) {
         $prefixString .= "{$prefixIntro}{$shortname}: <" . Exporter::getInstance()->getNamespaceUri($shortname) . ">{$prefixOutro}";
         unset($extraNamespaces[$shortname]);
         // avoid double declaration
     }
     foreach ($extraNamespaces as $shortname => $uri) {
         $prefixString .= "{$prefixIntro}{$shortname}: <{$uri}>{$prefixOutro}";
     }
     return $prefixString;
 }
 /**
  * '[[Born in::<q>[[Category:City]] [[Located in::Outback]]</q>]]'
  */
 public function testNestedPropertyConjunction()
 {
     $property = DIProperty::newFromUserLabel('Born in');
     $property->setPropertyTypeId('_wpg');
     $category = new DIWikiPage('City', NS_CATEGORY);
     $categoryName = \SMWTurtleSerializer::getTurtleNameForExpElement(\SMWExporter::getInstance()->getResourceElementForWikiPage($category));
     $conjunction = new Conjunction(array(new ClassDescription($category), new SomeProperty(DIProperty::newFromUserLabel('Located in'), new ValueDescription(new DIWikiPage('Outback', NS_MAIN), DIProperty::newFromUserLabel('Located in')))));
     $description = new SomeProperty($property, $conjunction);
     $instance = new CompoundConditionBuilder();
     $condition = $instance->buildCondition($description);
     $this->assertInstanceOf('\\SMW\\SPARQLStore\\QueryEngine\\Condition\\WhereCondition', $condition);
     $expectedConditionString = $this->stringBuilder->addString('?result property:Born_in ?v1 .')->addNewLine()->addString('{ ')->addString("{ ?v1 rdf:type {$categoryName} . }")->addNewLine()->addString('?v1 property:Located_in wiki:Outback .')->addNewLine()->addString('}')->addNewLine()->getString();
     $this->assertEquals($expectedConditionString, $instance->convertConditionToString($condition));
 }
 public function descriptionProvider()
 {
     $stringBuilder = UtilityFactory::getInstance()->newStringBuilder();
     # 0
     $conditionType = '\\SMW\\SPARQLStore\\QueryEngine\\Condition\\TrueCondition';
     $description = new Conjunction();
     $orderByProperty = null;
     $sortkeys = array();
     $expected = $stringBuilder->addString('?result swivt:page ?url .')->addNewLine()->getString();
     $provider[] = array($description, $orderByProperty, $sortkeys, $conditionType, $expected);
     # 1
     $conditionType = '\\SMW\\SPARQLStore\\QueryEngine\\Condition\\FalseCondition';
     $description = new Conjunction(array(new ValueDescription(new DIWikiPage('Bar', NS_MAIN))));
     $description = new Conjunction(array(new ValueDescription(new DIWikiPage('Foo', NS_MAIN)), $description));
     $orderByProperty = null;
     $sortkeys = array();
     $expected = $stringBuilder->addString('<http://www.example.org> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#nothing> .')->addNewLine()->getString();
     $provider[] = array($description, $orderByProperty, $sortkeys, $conditionType, $expected);
     # 2
     $conditionType = '\\SMW\\SPARQLStore\\QueryEngine\\Condition\\TrueCondition';
     $description = new Conjunction(array(new ThingDescription()));
     $orderByProperty = null;
     $sortkeys = array();
     $expected = $stringBuilder->addString('?result swivt:page ?url .')->addNewLine()->getString();
     $provider[] = array($description, $orderByProperty, $sortkeys, $conditionType, $expected);
     # 3
     $conditionType = '\\SMW\\SPARQLStore\\QueryEngine\\Condition\\WhereCondition';
     $description = new SomeProperty(new DIProperty('Foo'), new ThingDescription());
     $description = new Conjunction(array($description, new NamespaceDescription(NS_HELP)));
     $orderByProperty = null;
     $sortkeys = array();
     $expected = $stringBuilder->addString('?result property:Foo ?v1 .')->addNewLine()->addString('{ ?result swivt:wikiNamespace "12"^^xsd:integer . }')->addNewLine()->getString();
     $provider[] = array($description, $orderByProperty, $sortkeys, $conditionType, $expected);
     # 4
     $conditionType = '\\SMW\\SPARQLStore\\QueryEngine\\Condition\\SingletonCondition';
     $description = new Conjunction(array(new NamespaceDescription(NS_MAIN), new ValueDescription(new DIWikiPage('SomePageValue', NS_MAIN))));
     $orderByProperty = null;
     $sortkeys = array();
     $expected = $stringBuilder->addString('{ wiki:SomePageValue swivt:wikiNamespace "0"^^xsd:integer . }')->addNewLine()->getString();
     $provider[] = array($description, $orderByProperty, $sortkeys, $conditionType, $expected);
     # 5
     $conditionType = '\\SMW\\SPARQLStore\\QueryEngine\\Condition\\WhereCondition';
     $description = new ValueDescription(new DIBlob('SomePropertyBlobValue'), new DIProperty('Foo'), SMW_CMP_LESS);
     $description = new SomeProperty(new DIProperty('Foo'), $description);
     $description = new Conjunction(array($description, new ValueDescription(new DIBlob('SomeOtherPropertyBlobValue'), null, SMW_CMP_LESS), new ValueDescription(new DIBlob('YetAnotherPropertyBlobValue'), null, SMW_CMP_GRTR), new NamespaceDescription(NS_MAIN)));
     $orderByProperty = null;
     $sortkeys = array();
     $expected = $stringBuilder->addString('?result property:Foo ?v1 .')->addNewLine()->addString('FILTER( ?v1 < "SomePropertyBlobValue" )')->addNewLine()->addString('{ ?result swivt:wikiNamespace "0"^^xsd:integer . }')->addNewLine()->addString('FILTER( ?result < "SomeOtherPropertyBlobValue" && ?result > "YetAnotherPropertyBlobValue" )')->getString();
     $provider[] = array($description, $orderByProperty, $sortkeys, $conditionType, $expected);
     # 6
     $conditionType = '\\SMW\\SPARQLStore\\QueryEngine\\Condition\\SingletonCondition';
     $description = new ValueDescription(new DIBlob('SomePropertyBlobValue'), new DIProperty('Foo'), SMW_CMP_LESS);
     $description = new SomeProperty(new DIProperty('Foo'), $description);
     $description = new Conjunction(array($description, new ValueDescription(new DIBlob('SomeOtherPropertyBlobValue'), null, SMW_CMP_LIKE), new ValueDescription(new DIWikiPage('SomePropertyPageValue', NS_MAIN)), new NamespaceDescription(NS_MAIN)));
     $orderByProperty = null;
     $sortkeys = array();
     $expected = $stringBuilder->addString('wiki:SomePropertyPageValue property:Foo ?v1 .')->addNewLine()->addString('FILTER( ?v1 < "SomePropertyBlobValue" )')->addNewLine()->addString('{ wiki:SomePropertyPageValue swivt:wikiNamespace "0"^^xsd:integer . }')->addNewLine()->addString('FILTER( regex( ?result, "^SomeOtherPropertyBlobValue$", "s") )')->getString();
     $provider[] = array($description, $orderByProperty, $sortkeys, $conditionType, $expected);
     # 7
     $conditionType = '\\SMW\\SPARQLStore\\QueryEngine\\Condition\\FilterCondition';
     $description = new Conjunction(array(new ValueDescription(new DIBlob('SomeOtherPropertyBlobValue'), null, SMW_CMP_LIKE), new ValueDescription(new DIBlob('YetAnotherPropertyBlobValue'), new DIProperty('Foo'), SMW_CMP_NLKE), new ThingDescription()));
     $orderByProperty = null;
     $sortkeys = array();
     $expected = $stringBuilder->addString('?result swivt:page ?url .')->addNewLine()->addString('FILTER( regex( ?result, "^SomeOtherPropertyBlobValue$", "s") && ')->addString('!regex( ?result, "^YetAnotherPropertyBlobValue$", "s") )')->addNewLine()->getString();
     $provider[] = array($description, $orderByProperty, $sortkeys, $conditionType, $expected);
     # 8
     $conditionType = '\\SMW\\SPARQLStore\\QueryEngine\\Condition\\WhereCondition';
     $propertyValue = new DIWikiPage('SomePropertyPageValue', NS_HELP);
     $propertyValueName = \SMWTurtleSerializer::getTurtleNameForExpElement(\SMWExporter::getInstance()->getResourceElementForWikiPage($propertyValue));
     $description = new SomeProperty(new DIProperty('Foo'), new ValueDescription($propertyValue));
     $category = new DIWikiPage('Bar', NS_CATEGORY);
     $categoryName = \SMWTurtleSerializer::getTurtleNameForExpElement(\SMWExporter::getInstance()->getResourceElementForWikiPage($category));
     $description = new Conjunction(array($description, new ClassDescription($category)));
     $orderByProperty = new DIProperty('Foo');
     $sortkeys = array('Foo' => 'ASC');
     $expected = $stringBuilder->addString('?result swivt:wikiPageSortKey ?resultsk .')->addNewLine()->addString("?result property:Foo {$propertyValueName} .")->addNewLine()->addString('{ ?v1 swivt:wikiPageSortKey ?v1sk .')->addNewLine()->addString('}')->addNewLine()->addString("{ ?result rdf:type {$categoryName} . }")->addNewLine()->getString();
     $provider[] = array($description, $orderByProperty, $sortkeys, $conditionType, $expected);
     return $provider;
 }
 /**
  * @see http://www.w3.org/TR/sparql11-query/#propertypaths
  *
  * Query of:
  *
  * SELECT DISTINCT ?result WHERE {
  *	?result swivt:wikiPageSortKey ?resultsk .
  *	{
  *		?result property:FOO ?v1 .
  *		FILTER( ?v1sk >= "=BAR" )
  *		?v1 swivt:wikiPageSortKey ?v1sk .
  *	} UNION {
  *		?result property:FOO ?v2 .
  *	}
  * }
  *
  * results in:
  *
  * SELECT DISTINCT ?result WHERE {
  *	?result swivt:wikiPageSortKey ?resultsk .
  *	?r2 ^swivt:redirectsTo property:FOO .
  *	{
  *		?result ?r2 ?v1 .
  *		FILTER( ?v1sk >= "=BAR" )
  *		?v1 swivt:wikiPageSortKey ?v1sk .
  *	} UNION {
  *		?result ?r2 ?v3 .
  *	}
  * }
  */
 private function addRedirectTriplePatternToFinalCondition(Condition &$condition)
 {
     if ($this->redirectByVariableReplacementMap === array()) {
         return;
     }
     $weakConditions = array();
     $namespaces = array();
     $rediExpElement = Exporter::getInstance()->getSpecialPropertyResource('_REDI');
     $namespaces[$rediExpElement->getNamespaceId()] = $rediExpElement->getNamespace();
     foreach ($this->redirectByVariableReplacementMap as $valueName => $content) {
         list($redirectByVariable, $ns) = $content;
         $weakConditions[] = "{$redirectByVariable} " . "^" . $rediExpElement->getQName() . " {$valueName} .\n";
         $namespaces = array_merge($namespaces, $ns);
     }
     $condition->namespaces = array_merge($condition->namespaces, $namespaces);
     $condition->weakConditions += $weakConditions;
 }
 public function descriptionProvider()
 {
     $stringBuilder = UtilityFactory::getInstance()->newStringBuilder();
     # 0
     $conditionType = '\\SMW\\SPARQLStore\\QueryEngine\\Condition\\FalseCondition';
     $description = new SomeProperty(new DIProperty('Foo'), new Disjunction());
     $orderByProperty = null;
     $sortkeys = array();
     $expected = $stringBuilder->addString('<http://www.example.org> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#nothing> .')->addNewLine()->getString();
     $provider[] = array($description, $orderByProperty, $sortkeys, $conditionType, $expected);
     # 1
     $conditionType = '\\SMW\\SPARQLStore\\QueryEngine\\Condition\\WhereCondition';
     $description = new SomeProperty(new DIProperty('Foo'), new ThingDescription());
     $orderByProperty = null;
     $sortkeys = array();
     $expected = $stringBuilder->addString('?result property:Foo ?v1 .')->addNewLine()->getString();
     $provider[] = array($description, $orderByProperty, $sortkeys, $conditionType, $expected);
     # 2 Inverse
     $conditionType = '\\SMW\\SPARQLStore\\QueryEngine\\Condition\\WhereCondition';
     $description = new SomeProperty(new DIProperty('Foo', true), new ThingDescription());
     $orderByProperty = null;
     $sortkeys = array();
     $expected = $stringBuilder->addString('?v1 property:Foo ?result .')->addNewLine()->getString();
     $provider[] = array($description, $orderByProperty, $sortkeys, $conditionType, $expected);
     # 3
     $conditionType = '\\SMW\\SPARQLStore\\QueryEngine\\Condition\\WhereCondition';
     $description = new SomeProperty(new DIProperty('Foo'), new ThingDescription());
     $orderByProperty = new DIProperty('Foo');
     $sortkeys = array();
     $expected = $stringBuilder->addString('?result swivt:wikiPageSortKey ?resultsk .')->addNewLine()->addString('?result property:Foo ?v1 .')->addNewLine()->getString();
     $provider[] = array($description, $orderByProperty, $sortkeys, $conditionType, $expected);
     # 4
     $conditionType = '\\SMW\\SPARQLStore\\QueryEngine\\Condition\\WhereCondition';
     $property = new DIProperty('Foo');
     $property->setPropertyTypeId('_txt');
     $description = new SomeProperty($property, new ValueDescription(new DIBlob('SomePropertyBlobValue')));
     $orderByProperty = null;
     $sortkeys = array();
     $expected = $stringBuilder->addString('?result property:Foo "SomePropertyBlobValue" .')->addNewLine()->getString();
     $provider[] = array($description, $orderByProperty, $sortkeys, $conditionType, $expected);
     # 5
     $conditionType = '\\SMW\\SPARQLStore\\QueryEngine\\Condition\\WhereCondition';
     $property = new DIProperty('Foo');
     $property->setPropertyTypeId('_txt');
     $description = new SomeProperty($property, new ValueDescription(new DIBlob('SomePropertyBlobValue')));
     $orderByProperty = $property;
     $sortkeys = array();
     $expected = $stringBuilder->addString('?result swivt:wikiPageSortKey ?resultsk .')->addNewLine()->addString('?result property:Foo "SomePropertyBlobValue" .')->addNewLine()->getString();
     $provider[] = array($description, $orderByProperty, $sortkeys, $conditionType, $expected);
     # 6
     $conditionType = '\\SMW\\SPARQLStore\\QueryEngine\\Condition\\WhereCondition';
     $property = new DIProperty('Foo');
     $property->setPropertyTypeId('_wpg');
     $propertyValue = new DIWikiPage('SomePropertyPageValue', NS_HELP);
     $propertyValueName = \SMWTurtleSerializer::getTurtleNameForExpElement(\SMWExporter::getInstance()->getResourceElementForWikiPage($propertyValue));
     $description = new SomeProperty($property, new ValueDescription($propertyValue));
     $orderByProperty = $property;
     $sortkeys = array();
     $expected = $stringBuilder->addString('?result swivt:wikiPageSortKey ?resultsk .')->addNewLine()->addString("?result property:Foo {$propertyValueName} .")->addNewLine()->getString();
     $provider[] = array($description, $orderByProperty, $sortkeys, $conditionType, $expected);
     # 7
     $conditionType = '\\SMW\\SPARQLStore\\QueryEngine\\Condition\\WhereCondition';
     $property = new DIProperty('Foo');
     $property->setPropertyTypeId('_wpg');
     $description = new SomeProperty($property, new ValueDescription(new DIWikiPage('SomePropertyPageValue', NS_HELP), $property, SMW_CMP_LEQ));
     $orderByProperty = new DIProperty('SomePropertyPageValue');
     $sortkeys = array();
     $expected = $stringBuilder->addString('?result swivt:wikiPageSortKey ?resultsk .')->addNewLine()->addString('?result property:Foo ?v1 .')->addNewLine()->addString('FILTER( ?v1sk <= "SomePropertyPageValue" )')->addNewLine()->addString('?v1 swivt:wikiPageSortKey ?v1sk .')->addNewLine()->getString();
     $provider[] = array($description, $orderByProperty, $sortkeys, $conditionType, $expected);
     # 8
     $conditionType = '\\SMW\\SPARQLStore\\QueryEngine\\Condition\\WhereCondition';
     $property = new DIProperty('Foo');
     $property->setPropertyTypeId('_wpg');
     $description = new SomeProperty($property, new ValueDescription(new DIWikiPage('SomePropertyPageValue', NS_HELP), $property, SMW_CMP_LEQ));
     $description = new SomeProperty(new DIProperty('Bar'), $description);
     $orderByProperty = new DIProperty('Bar');
     $sortkeys = array('Foo' => 'ASC');
     $expected = $stringBuilder->addString('?result swivt:wikiPageSortKey ?resultsk .')->addNewLine()->addString('?result property:Bar ?v1 .')->addNewLine()->addString('{ ?v1 property:Foo ?v2 .')->addNewLine()->addString('FILTER( ?v2sk <= "SomePropertyPageValue" )')->addNewLine()->addString('?v2 swivt:wikiPageSortKey ?v2sk .')->addNewLine()->addString('}')->addNewLine()->getString();
     $provider[] = array($description, $orderByProperty, $sortkeys, $conditionType, $expected);
     # 9 Inverse -> ?v1 property:Foo ?v2 vs. ?v2 property:Foo ?v1
     $conditionType = '\\SMW\\SPARQLStore\\QueryEngine\\Condition\\WhereCondition';
     $property = new DIProperty('Foo', true);
     $property->setPropertyTypeId('_wpg');
     $description = new SomeProperty($property, new ValueDescription(new DIWikiPage('SomePropertyPageValue', NS_HELP), $property, SMW_CMP_LEQ));
     $description = new SomeProperty(new DIProperty('Bar'), $description);
     $expected = $stringBuilder->addString('?result swivt:wikiPageSortKey ?resultsk .')->addNewLine()->addString('?result property:Bar ?v1 .')->addNewLine()->addString('{ ?v2 property:Foo ?v1 .')->addNewLine()->addString('FILTER( ?v2sk <= "SomePropertyPageValue" )')->addNewLine()->addString('?v2 swivt:wikiPageSortKey ?v2sk .')->addNewLine()->addString('}')->addNewLine()->getString();
     $provider[] = array($description, $orderByProperty, $sortkeys, $conditionType, $expected);
     # 10
     $conditionType = '\\SMW\\SPARQLStore\\QueryEngine\\Condition\\WhereCondition';
     $property = new DIProperty('_MDAT');
     $description = new SomeProperty($property, new ThingDescription());
     $sortkeys = array('_MDAT' => 'ASC');
     $propertyLabel = str_replace(' ', '_', $property->getLabel());
     $expected = $stringBuilder->addString('?result swivt:wikiPageSortKey ?resultsk .')->addNewLine()->addString("?result property:{$propertyLabel}-23aux ?v1 .")->addNewLine()->getString();
     $provider[] = array($description, $orderByProperty, $sortkeys, $conditionType, $expected);
     # 11, issue 556
     $conditionType = '\\SMW\\SPARQLStore\\QueryEngine\\Condition\\WhereCondition';
     $property = new DIProperty('Foo');
     $property->setPropertyTypeId('_txt');
     $description = new SomeProperty($property, new Disjunction(array(new ValueDescription(new DIBlob('Bar')), new ValueDescription(new DIBlob('Baz')))));
     $expected = $stringBuilder->addString('?result swivt:wikiPageSortKey ?resultsk .')->addNewLine()->addString('?result property:Foo ?v1 .')->addNewLine()->addString('FILTER( ?v1 = "Bar" || ?v1 = "Baz" )')->addNewLine()->getString();
     $provider[] = array($description, $orderByProperty, $sortkeys, $conditionType, $expected);
     # 12 use the rdf/owl equivalent for a predefined property
     $conditionType = '\\SMW\\SPARQLStore\\QueryEngine\\Condition\\WhereCondition';
     $property = new DIProperty('_SUBC');
     $description = new SomeProperty($property, new ValueDescription(new DIBlob('Bar')));
     $expected = $stringBuilder->addString('?result swivt:wikiPageSortKey ?resultsk .')->addNewLine()->addString('?result rdfs:subClassOf "Bar" .')->addNewLine()->getString();
     $provider[] = array($description, $orderByProperty, $sortkeys, $conditionType, $expected);
     # 13
     $conditionType = '\\SMW\\SPARQLStore\\QueryEngine\\Condition\\WhereCondition';
     $property = new DIProperty('_SUBP');
     $description = new SomeProperty($property, new ValueDescription(new DIWikiPage('Bar', SMW_NS_PROPERTY)));
     $expected = $stringBuilder->addString('?result swivt:wikiPageSortKey ?resultsk .')->addNewLine()->addString('?result rdfs:subPropertyOf property:Bar .')->addNewLine()->getString();
     $provider[] = array($description, $orderByProperty, $sortkeys, $conditionType, $expected);
     # 14 aux-property
     $conditionType = '\\SMW\\SPARQLStore\\QueryEngine\\Condition\\WhereCondition';
     $property = new DIProperty('_MDAT');
     $description = new SomeProperty($property, new ValueDescription(new DITime(1, 1970, 01, 01, 1, 1)));
     $expected = $stringBuilder->addString('?result swivt:wikiPageSortKey ?resultsk .')->addNewLine()->addString('?result property:Modification_date-23aux "2440587.5423611"^^xsd:double .')->addNewLine()->getString();
     $provider[] = array($description, $orderByProperty, $sortkeys, $conditionType, $expected);
     return $provider;
 }
 private function defineElementsForDiWikiPage(DIWikiPage $diWikiPage, $modifier)
 {
     $localName = '';
     if ($diWikiPage->getNamespace() === SMW_NS_PROPERTY) {
         $namespace = Exporter::getInstance()->getNamespaceUri('property');
         $namespaceId = 'property';
         $localName = Escaper::encodeUri(rawurlencode($diWikiPage->getDBkey()));
     }
     if ($localName === '' || in_array($localName[0], array('-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'))) {
         $namespace = Exporter::getInstance()->getNamespaceUri('wiki');
         $namespaceId = 'wiki';
         $localName = Escaper::encodePage($diWikiPage);
     }
     // "-23$modifier" where "-23" is the URI encoding of "#" (a symbol not
     // occuring in MW titles).
     if ($modifier !== '') {
         $localName .= '-23' . Escaper::encodeUri(rawurlencode($modifier));
     }
     return array($localName, $namespace, $namespaceId);
 }
 private function getResourceForTargetElement(ExpNsResource $expNsResource, $rediTargetElement)
 {
     if (!$rediTargetElement instanceof ExpResource) {
         throw new RuntimeException('Expected a ExpResource instance');
     }
     $rediTargetUri = $rediTargetElement->getUri();
     $wikiNamespace = Exporter::getInstance()->getNamespaceUri('wiki');
     if (strpos($rediTargetUri, $wikiNamespace) === 0) {
         return new ExpNsResource(substr($rediTargetUri, strlen($wikiNamespace)), $wikiNamespace, 'wiki');
     }
     return $expNsResource;
 }
Esempio n. 24
0
 /**
  * Delete a dataitem from the Sparql back-end together with all data that is
  * associated resources
  *
  * @since 2.0
  *
  * @param DataItem $dataItem
  *
  * @return boolean
  */
 public function doSparqlDataDelete(DataItem $dataItem)
 {
     $extraNamespaces = array();
     $expResource = Exporter::getInstance()->getDataItemExpElement($dataItem);
     $resourceUri = TurtleSerializer::getTurtleNameForExpElement($expResource);
     if ($expResource instanceof ExpNsResource) {
         $extraNamespaces = array($expResource->getNamespaceId() => $expResource->getNamespace());
     }
     $masterPageProperty = Exporter::getInstance()->getSpecialNsResource('swivt', 'masterPage');
     $masterPagePropertyUri = TurtleSerializer::getTurtleNameForExpElement($masterPageProperty);
     $success = $this->getConnection()->deleteContentByValue($masterPagePropertyUri, $resourceUri, $extraNamespaces);
     if ($success) {
         return $this->getConnection()->delete("{$resourceUri} ?p ?o", "{$resourceUri} ?p ?o", $extraNamespaces);
     }
     return false;
 }
 /**
  * Get the Turtle serialization string for the given SMWExpElement. The
  * method just computes a name, and does not serialize triples, so the
  * parameter must be an SMWExpResource or SMWExpLiteral, no SMWExpData.
  *
  * @param $expElement SMWExpElement being SMWExpLiteral or SMWExpResource
  * @return string
  */
 public static function getTurtleNameForExpElement(SMWExpElement $expElement)
 {
     if ($expElement instanceof SMWExpResource) {
         if ($expElement->isBlankNode()) {
             return '[]';
         } elseif ($expElement instanceof SMWExpNsResource && $expElement->hasAllowedLocalName()) {
             return $expElement->getQName();
         } else {
             return '<' . str_replace('>', '\\>', SMWExporter::getInstance()->expandURI($expElement->getUri())) . '>';
         }
     } elseif ($expElement instanceof SMWExpLiteral) {
         $dataType = $expElement->getDatatype();
         $lexicalForm = self::getCorrectLexicalForm($expElement);
         if ($dataType !== '' && $dataType != 'http://www.w3.org/2001/XMLSchema#string') {
             $count = 0;
             $newdt = str_replace('http://www.w3.org/2001/XMLSchema#', 'xsd:', $dataType, $count);
             return $count == 1 ? "{$lexicalForm}^^{$newdt}" : "{$lexicalForm}^^<{$dataType}>";
         } else {
             return $lexicalForm;
         }
     } else {
         throw new InvalidArgumentException('The method can only serialize atomic elements of type SMWExpResource or SMWExpLiteral.');
     }
 }
 public function descriptionToExpData($desc, &$exact)
 {
     if ($desc instanceof SMWConjunction || $desc instanceof SMWDisjunction) {
         $result = new SMWExpData(new SMWExpResource(''));
         $result->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('rdf', 'type'), new SMWExpData(SMWExporter::getInstance()->getSpecialNsResource('owl', 'Class')));
         $elements = array();
         foreach ($desc->getDescriptions() as $subdesc) {
             $element = $this->descriptionToExpData($subdesc, $exact);
             if ($element === false) {
                 $element = new SMWExpData(SMWExporter::getInstance()->getSpecialNsResource('owl', 'Thing'));
             }
             $elements[] = $element;
         }
         $prop = $desc instanceof SMWConjunction ? 'intersectionOf' : 'unionOf';
         $result->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('owl', $prop), SMWExpData::makeCollection($elements));
     } elseif ($desc instanceof SMWClassDescription) {
         if (count($desc->getCategories()) == 1) {
             // single category
             $result = new SMWExpData(SMWExporter::getInstance()->getResourceElement(end($desc->getCategories())));
         } else {
             // disjunction of categories
             $result = new SMWExpData(new SMWExpResource(''));
             $elements = array();
             foreach ($desc->getCategories() as $cat) {
                 $elements[] = new SMWExpData(SMWExporter::getInstance()->getResourceElement($cat));
             }
             $result->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('owl', 'unionOf'), SMWExpData::makeCollection($elements));
         }
         $result->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('rdf', 'type'), new SMWExpData(SMWExporter::getInstance()->getSpecialNsResource('owl', 'Class')));
     } elseif ($desc instanceof SMWConceptDescription) {
         $result = new SMWExpData(SMWExporter::getInstance()->getResourceElement($desc->getConcept()));
     } elseif ($desc instanceof SMWSomeProperty) {
         $result = new SMWExpData(new SMWExpResource(''));
         $result->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('rdf', 'type'), new SMWExpData(SMWExporter::getInstance()->getSpecialNsResource('owl', 'Restriction')));
         $result->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('owl', 'onProperty'), new SMWExpData(SMWExporter::getInstance()->getResourceElement($desc->getProperty())));
         $subdata = $this->descriptionToExpData($desc->getDescription(), $exact);
         if ($desc->getDescription() instanceof SMWValueDescription && $desc->getDescription()->getComparator() == SMW_CMP_EQ) {
             $result->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('owl', 'hasValue'), $subdata);
         } else {
             if ($subdata === false) {
                 $owltype = SMWExporter::getInstance()->getOWLPropertyType($desc->getProperty()->getPropertyTypeID());
                 if ($owltype == 'ObjectProperty') {
                     $subdata = new SMWExpData(SMWExporter::getInstance()->getSpecialNsResource('owl', 'Thing'));
                 } elseif ($owltype == 'DatatypeProperty') {
                     $subdata = new SMWExpData(SMWExporter::getInstance()->getSpecialNsResource('rdfs', 'Literal'));
                 } else {
                     // no restrictions at all with annotation properties ...
                     return new SMWExpData(SMWExporter::getInstance()->getSpecialNsResource('owl', 'Thing'));
                 }
             }
             $result->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('owl', 'someValuesFrom'), $subdata);
         }
     } elseif ($desc instanceof SMWValueDescription) {
         if ($desc->getComparator() == SMW_CMP_EQ) {
             $result = SMWExporter::getInstance()->getDataItemExpElement($desc->getDataItem());
         } else {
             // alas, OWL cannot represent <= and >= ...
             $exact = false;
             $result = false;
         }
     } elseif ($desc instanceof SMWThingDescription) {
         $result = false;
     } else {
         $result = false;
         $exact = false;
     }
     return $result;
 }
 /**
  * Return a fully qualified URL that points to the link target (whether internal or not).
  * This function might be used when the URL is needed outside normal links, e.g. in the HTML
  * header or in some metadata file. For making normal links, getText() should be used.
  *
  * @return string
  */
 public function getURL()
 {
     if ($this->mInternal) {
         $title = Title::newFromText($this->mTarget);
         if (!is_null($title)) {
             return $title->getFullURL(self::encodeParameters($this->mParams, false));
         } else {
             return '';
             // the title was bad, normally this would indicate a software bug
         }
     } else {
         if (count($this->mParams) > 0) {
             if (strpos(SMWExporter::getInstance()->expandURI('&wikiurl;'), '?') === false) {
                 $target = $this->mTarget . '?' . self::encodeParameters($this->mParams, false);
             } else {
                 $target = $this->mTarget . '&' . self::encodeParameters($this->mParams, false);
             }
         } else {
             $target = $this->mTarget;
         }
         return $target;
     }
 }
 /**
  * Check if this element encodes an RDF list, and if yes return an
  * array of SMWExpElements corresponding to the collection elements in
  * the specified order. Otherwise return false.
  * The method only returns lists that can be encoded using
  * parseType="Collection" in RDF/XML, i.e. only lists of non-literal
  * resources.
  *
  * @return mixed array of SMWExpElement (but not SMWExpLiteral) or false
  */
 public function getCollection()
 {
     $rdftypeUri = SMWExporter::getInstance()->getSpecialNsResource('rdf', 'type')->getUri();
     $rdffirstUri = SMWExporter::getInstance()->getSpecialNsResource('rdf', 'first')->getUri();
     $rdfrestUri = SMWExporter::getInstance()->getSpecialNsResource('rdf', 'rest')->getUri();
     $rdfnilUri = SMWExporter::getInstance()->getSpecialNsResource('rdf', 'nil')->getUri();
     // first check if we are basically an RDF List:
     if ($this->m_subject->isBlankNode() && count($this->m_children) == 3 && array_key_exists($rdftypeUri, $this->m_children) && count($this->m_children[$rdftypeUri]) == 1 && array_key_exists($rdffirstUri, $this->m_children) && count($this->m_children[$rdffirstUri]) == 1 && !end($this->m_children[$rdffirstUri]) instanceof SMWExpLiteral && array_key_exists($rdfrestUri, $this->m_children) && count($this->m_children[$rdfrestUri]) == 1) {
         $typedata = end($this->m_children[$rdftypeUri]);
         $rdflistUri = SMWExporter::getInstance()->getSpecialNsResource('rdf', 'List')->getUri();
         if ($typedata->getSubject()->getUri() == $rdflistUri) {
             $first = end($this->m_children[$rdffirstUri]);
             $rest = end($this->m_children[$rdfrestUri]);
             if ($rest instanceof SMWExpData) {
                 $restlist = $rest->getCollection();
                 if ($restlist === false) {
                     return false;
                 } else {
                     array_unshift($restlist, $first);
                     return $restlist;
                 }
             } elseif ($rest instanceof SMWExpResource && $rest->getUri() == $rdfnilUri) {
                 return array($first);
             } else {
                 return false;
             }
         } else {
             return false;
         }
     } elseif (count($this->m_children) == 0 && $this->m_subject->getUri() == $rdfnilUri) {
         return array();
     } else {
         return false;
     }
 }
 /**
  * Print basic information about this site.
  */
 public function printWikiInfo()
 {
     global $wgSitename, $wgLanguageCode;
     $this->prepareSerialization();
     $this->delay_flush = 35;
     // don't do intermediate flushes with default parameters
     // assemble export data:
     $expData = new SMWExpData(new SMWExpResource('&wiki;#wiki'));
     $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('rdf', 'type'), new SMWExpData(SMWExporter::getInstance()->getSpecialNsResource('swivt', 'Wikisite')));
     // basic wiki information
     $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('rdfs', 'label'), new SMWExpLiteral($wgSitename));
     $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('swivt', 'siteName'), new SMWExpLiteral($wgSitename, 'http://www.w3.org/2001/XMLSchema#string'));
     $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('swivt', 'pagePrefix'), new SMWExpLiteral(SMWExporter::getInstance()->expandURI('&wikiurl;'), 'http://www.w3.org/2001/XMLSchema#string'));
     $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('swivt', 'smwVersion'), new SMWExpLiteral(SMW_VERSION, 'http://www.w3.org/2001/XMLSchema#string'));
     $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('swivt', 'langCode'), new SMWExpLiteral($wgLanguageCode, 'http://www.w3.org/2001/XMLSchema#string'));
     $mainpage = Title::newMainPage();
     if (!is_null($mainpage)) {
         $ed = new SMWExpData(new SMWExpResource($mainpage->getFullURL()));
         $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('swivt', 'mainPage'), $ed);
     }
     // statistical information
     $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('swivt', 'pageCount'), new SMWExpLiteral(SiteStats::pages(), 'http://www.w3.org/2001/XMLSchema#int'));
     $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('swivt', 'contentPageCount'), new SMWExpLiteral(SiteStats::articles(), 'http://www.w3.org/2001/XMLSchema#int'));
     $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('swivt', 'mediaCount'), new SMWExpLiteral(SiteStats::images(), 'http://www.w3.org/2001/XMLSchema#int'));
     $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('swivt', 'editCount'), new SMWExpLiteral(SiteStats::edits(), 'http://www.w3.org/2001/XMLSchema#int'));
     // SiteStats::views was deprecated in MediaWiki 1.25
     // "Stop calling this function, it will be removed some time in the future"
     //$expData->addPropertyObjectValue(
     //	SMWExporter::getInstance()->getSpecialNsResource( 'swivt', 'viewCount' ),
     //	new SMWExpLiteral( SiteStats::views(), 'http://www.w3.org/2001/XMLSchema#int' )
     //);
     $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('swivt', 'userCount'), new SMWExpLiteral(SiteStats::users(), 'http://www.w3.org/2001/XMLSchema#int'));
     $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('swivt', 'adminCount'), new SMWExpLiteral(SiteStats::numberingroup('sysop'), 'http://www.w3.org/2001/XMLSchema#int'));
     $this->serializer->startSerialization();
     $this->serializer->serializeExpData(SMWExporter::getInstance()->getOntologyExpData(''));
     $this->serializer->serializeExpData($expData);
     // link to list of existing pages:
     if (strpos(SMWExporter::getInstance()->expandURI('&wikiurl;'), '?') === false) {
         // check whether we have title as a first parameter or in URL
         $nexturl = SMWExporter::getInstance()->expandURI('&export;?offset=0');
     } else {
         $nexturl = SMWExporter::getInstance()->expandURI('&export;&amp;offset=0');
     }
     $expData = new SMWExpData(new SMWExpResource($nexturl));
     $ed = new SMWExpData(SMWExporter::getInstance()->getSpecialNsResource('owl', 'Thing'));
     $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('rdf', 'type'), $ed);
     $ed = new SMWExpData(new SMWExpResource($nexturl));
     $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('rdfs', 'isDefinedBy'), $ed);
     $this->serializer->serializeExpData($expData);
     $this->serializer->finishSerialization();
     $this->flush(true);
 }
 private function createFilterConditionToMatchRegexPattern($dataItem, &$joinVariable, $comparator, $pattern)
 {
     if ($dataItem instanceof DIBlob) {
         return new FilterCondition("{$comparator}( ?{$joinVariable}, \"{$pattern}\", \"s\")", array());
     }
     if ($dataItem instanceof DIUri) {
         return new FilterCondition("{$comparator}( str( ?{$joinVariable} ), \"{$pattern}\", \"i\")", array());
     }
     // Pattern search for a wikipage object can only be done on the sortkey
     // literal and not on it's resource
     $skeyExpElement = Exporter::getInstance()->getSpecialPropertyResource('_SKEY');
     $expElement = $this->exporter->getDataItemExpElement($dataItem->getSortKeyDataItem());
     $condition = new SingletonCondition($expElement);
     $filterVariable = $this->compoundConditionBuilder->getNextVariable();
     $condition->condition = "?{$joinVariable} " . $skeyExpElement->getQName() . " ?{$filterVariable} .\n";
     $condition->matchElement = "?{$joinVariable}";
     $filterCondition = new FilterCondition("{$comparator}( ?{$filterVariable}, \"{$pattern}\", \"s\")", array());
     $condition->weakConditions = array($filterVariable => $filterCondition->getCondition());
     return $condition;
 }