private function mapCategoriesToConditionElements(array $categories, $joinVariable)
 {
     $condition = '';
     $namespaces = array();
     $instExpElement = $this->exporter->getSpecialPropertyResource('_INST');
     foreach ($categories as $category) {
         $categoryExpElement = $this->exporter->getResourceElementForWikiPage($category);
         $categoryName = TurtleSerializer::getTurtleNameForExpElement($categoryExpElement);
         $namespaces[$categoryExpElement->getNamespaceId()] = $categoryExpElement->getNamespace();
         $newcondition = "{ ?{$joinVariable} " . $instExpElement->getQName() . " {$categoryName} . }\n";
         if ($condition === '') {
             $condition = $newcondition;
         } else {
             $condition .= "UNION\n{$newcondition}";
         }
     }
     return array($condition, $namespaces);
 }
 /**
  * @note rdfs:subPropertyOf* where * means a property path of arbitrary length
  * can be found using the "zero or more" will resolve the complete path
  *
  * @see http://www.w3.org/TR/sparql11-query/#propertypath-arbitrary-length
  */
 private function tryToAddPropertyPathForSaturatedHierarchy(&$condition, DIProperty $property, &$propertyName)
 {
     if (!$this->compoundConditionBuilder->canUseQFeature(SMW_SPARQL_QF_SUBP) || !$property->isUserDefined()) {
         return null;
     }
     if ($this->compoundConditionBuilder->getPropertyHierarchyLookup() == null || !$this->compoundConditionBuilder->getPropertyHierarchyLookup()->hasSubpropertyFor($property)) {
         return null;
     }
     $subPropExpElement = $this->exporter->getSpecialPropertyResource('_SUBP', SMW_NS_PROPERTY);
     $propertyByVariable = '?' . $this->compoundConditionBuilder->getNextVariable('sp');
     $condition->weakConditions[$propertyName] = "\n" . "{$propertyByVariable} " . $subPropExpElement->getQName() . "*" . " {$propertyName} .\n" . "";
     $propertyName = $propertyByVariable;
 }
 private function tryToAddClassHierarchyPattern($category, &$categoryExpName)
 {
     if (!$this->compoundConditionBuilder->canUseQFeature(SMW_SPARQL_QF_SUBC)) {
         return '';
     }
     if ($this->compoundConditionBuilder->getPropertyHierarchyLookup() === null || !$this->compoundConditionBuilder->getPropertyHierarchyLookup()->hasSubcategoryFor($category)) {
         return '';
     }
     $subClassExpElement = $this->exporter->getSpecialPropertyResource('_SUBC');
     $classHierarchyByVariable = "?" . $this->compoundConditionBuilder->getNextVariable('sc');
     $condition = "{$classHierarchyByVariable} " . $subClassExpElement->getQName() . "*" . " {$categoryExpName} .\n";
     $categoryExpName = "{$classHierarchyByVariable}";
     return $condition;
 }
 /**
  * Extend the given SPARQL condition by a suitable order by variable,
  * possibly adding conditions if required for the type of data.
  *
  * @param SMWSparqlCondition $sparqlCondition condition to modify
  * @param string $mainVariable the variable that represents the value to be ordered
  * @param integer $diType DataItem type id
  */
 protected function addOrderByData(SMWSparqlCondition &$sparqlCondition, $mainVariable, $diType)
 {
     if ($diType == SMWDataItem::TYPE_WIKIPAGE) {
         $sparqlCondition->orderByVariable = $mainVariable . 'sk';
         $skeyExpElement = SMWExporter::getSpecialPropertyResource('_SKEY');
         $sparqlCondition->weakConditions = array($sparqlCondition->orderByVariable => "?{$mainVariable} " . $skeyExpElement->getQName() . " ?{$sparqlCondition->orderByVariable} .\n");
     } else {
         $sparqlCondition->orderByVariable = $mainVariable;
     }
 }
Exemplo n.º 5
0
 /**
  * Find the redirect target of an SMWExpNsResource.
  * Returns an SMWExpNsResource object the input redirects to,
  * the input itself if there is no redirect (or it cannot be
  * used for making a resource with a prefix).
  *
  * @since 1.6
  * @param $expNsResource string URI to check
  * @param $exists boolean that is set to true if $expNsResource is in the
  * store; always false for blank nodes; always true for subobjects
  * @return SMWExpNsResource
  */
 protected function getSparqlRedirectTarget(SMWExpNsResource $expNsResource, &$exists)
 {
     if ($expNsResource->isBlankNode()) {
         $exists = false;
         return $expNsResource;
     } elseif ($expNsResource->getDataItem() instanceof SMWDIWikiPage && $expNsResource->getDataItem()->getSubobjectName() !== '') {
         $exists = true;
         return $expNsResource;
     }
     $resourceUri = SMWTurtleSerializer::getTurtleNameForExpElement($expNsResource);
     $rediUri = SMWTurtleSerializer::getTurtleNameForExpElement(SMWExporter::getSpecialPropertyResource('_REDI'));
     $skeyUri = SMWTurtleSerializer::getTurtleNameForExpElement(SMWExporter::getSpecialPropertyResource('_SKEY'));
     $sparqlResult = smwfGetSparqlDatabase()->select('*', "{$resourceUri} {$skeyUri} ?s  OPTIONAL { {$resourceUri} {$rediUri} ?r }", array('LIMIT' => 1), array($expNsResource->getNamespaceId() => $expNsResource->getNamespace()));
     $firstRow = $sparqlResult->current();
     if ($firstRow === false) {
         $exists = false;
         return $expNsResource;
     } elseif (count($firstRow) > 1 && !is_null($firstRow[1])) {
         $exists = true;
         $rediTargetElement = $firstRow[1];
         $rediTargetUri = $rediTargetElement->getUri();
         $wikiNamespace = SMWExporter::getNamespaceUri('wiki');
         if (strpos($rediTargetUri, $wikiNamespace) === 0) {
             return new SMWExpNsResource(substr($rediTargetUri, 0, strlen($wikiNamespace)), $wikiNamespace, 'wiki');
         } else {
             return $expNsResource;
         }
     } else {
         $exists = true;
         return $expNsResource;
     }
 }
Exemplo n.º 6
0
 private function lookupResourceUriTargetFromDatabase(ExpNsResource $expNsResource)
 {
     $resourceUri = TurtleSerializer::getTurtleNameForExpElement($expNsResource);
     $rediUri = TurtleSerializer::getTurtleNameForExpElement(Exporter::getSpecialPropertyResource('_REDI'));
     $skeyUri = TurtleSerializer::getTurtleNameForExpElement(Exporter::getSpecialPropertyResource('_SKEY'));
     $federateResultSet = $this->connection->select('*', "{$resourceUri} {$skeyUri} ?s  OPTIONAL { {$resourceUri} {$rediUri} ?r }", array('LIMIT' => 1), array($expNsResource->getNamespaceId() => $expNsResource->getNamespace()));
     return $federateResultSet->current();
 }
Exemplo n.º 7
0
 public function testExportSubSemanticData()
 {
     $semanticData = $this->semanticDataFactory->newEmptySemanticData(__METHOD__);
     $factsheet = $this->fixturesProvider->getFactsheet('berlin');
     $factsheet->setTargetSubject($semanticData->getSubject());
     $demographicsSubobject = $factsheet->getDemographics();
     $semanticData->addPropertyObjectValue($demographicsSubobject->getProperty(), $demographicsSubobject->getContainer());
     $exportData = Exporter::makeExportData($semanticData->findSubSemanticData($demographicsSubobject->getSubobjectId()));
     $this->assertCount(1, $exportData->getValues(Exporter::getSpecialPropertyResource('_SKEY')));
     $this->assertCount(1, $exportData->getValues(Exporter::getSpecialNsResource('swivt', 'wikiNamespace')));
 }
Exemplo n.º 8
0
 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::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;
 }
Exemplo n.º 9
0
 /**
  * Extend the given SPARQL condition by a suitable order by variable,
  * possibly adding conditions if required for the type of data.
  *
  * @param Condition $sparqlCondition condition to modify
  * @param string $mainVariable the variable that represents the value to be ordered
  * @param integer $diType DataItem type id
  */
 public function addOrderByData(Condition &$condition, $mainVariable, $diType)
 {
     if ($diType !== DataItem::TYPE_WIKIPAGE) {
         return $condition->orderByVariable = $mainVariable;
     }
     $condition->orderByVariable = $mainVariable . 'sk';
     $skeyExpElement = Exporter::getSpecialPropertyResource('_SKEY');
     $weakConditions = array($condition->orderByVariable => "?{$mainVariable} " . $skeyExpElement->getQName() . " ?{$condition->orderByVariable} .\n");
     $condition->weakConditions += $weakConditions;
 }