private function getPropertyNameByUsingTurtleSerializer(DIProperty $property, DIProperty $nonInverseProperty, &$namespaces)
 {
     // Use helper properties in encoding values, refer to this helper property:
     if ($this->exporter->hasHelperExpElement($property)) {
         $propertyExpElement = $this->exporter->getResourceElementForProperty($nonInverseProperty, true);
     } else {
         $propertyExpElement = $this->exporter->getResourceElementForProperty($nonInverseProperty);
     }
     if ($propertyExpElement instanceof ExpNsResource) {
         $namespaces[$propertyExpElement->getNamespaceId()] = $propertyExpElement->getNamespace();
     }
     return TurtleSerializer::getTurtleNameForExpElement($propertyExpElement);
 }
 private function findMostSuitablePropertyRepresentation(DIProperty $property, DIProperty $nonInverseProperty, &$namespaces)
 {
     $redirectByVariable = $this->compoundConditionBuilder->tryToFindRedirectVariableForDataItem($nonInverseProperty->getDiWikiPage());
     // If the property is represented by a redirect then use the variable instead
     if ($redirectByVariable !== null) {
         return $redirectByVariable;
     }
     // Use helper properties in encoding values, refer to this helper property:
     if ($this->exporter->hasHelperExpElement($property)) {
         $propertyExpElement = $this->exporter->getResourceElementForProperty($nonInverseProperty, true);
     } elseif (!$property->isUserDefined()) {
         $propertyExpElement = $this->exporter->getSpecialPropertyResource($nonInverseProperty->getKey(), SMW_NS_PROPERTY);
     } else {
         $propertyExpElement = $this->exporter->getResourceElementForProperty($nonInverseProperty);
     }
     if ($propertyExpElement instanceof ExpNsResource) {
         $namespaces[$propertyExpElement->getNamespaceId()] = $propertyExpElement->getNamespace();
     }
     return TurtleSerializer::getTurtleNameForExpElement($propertyExpElement);
 }
 /**
  * Recursively create an SMWSparqlCondition from an SMWSomeProperty.
  *
  * @param $description SMWSomeProperty
  * @param $joinVariable string name, see buildSparqlCondition()
  * @param $orderByProperty mixed SMWDIProperty or null, see buildSparqlCondition()
  * @return SMWSparqlCondition
  */
 protected function buildPropertyCondition(SMWSomeProperty $description, $joinVariable, $orderByProperty)
 {
     $diProperty = $description->getProperty();
     //*** Find out if we should order by the values of this property ***//
     if (array_key_exists($diProperty->getKey(), $this->m_sortkeys)) {
         $innerOrderByProperty = $diProperty;
     } else {
         $innerOrderByProperty = null;
     }
     //*** Prepare inner condition ***//
     $innerJoinVariable = $this->getNextVariable();
     $innerCondition = $this->buildSparqlCondition($description->getDescription(), $innerJoinVariable, $innerOrderByProperty);
     $namespaces = $innerCondition->namespaces;
     if ($innerCondition instanceof SMWSparqlFalseCondition) {
         return new SMWSparqlFalseCondition();
     } elseif ($innerCondition instanceof SMWSparqlSingletonCondition) {
         $matchElement = $innerCondition->matchElement;
         $objectName = SMWTurtleSerializer::getTurtleNameForExpElement($matchElement);
         if ($matchElement instanceof SMWExpNsResource) {
             $namespaces[$matchElement->getNamespaceId()] = $matchElement->getNamespace();
         }
     } else {
         $objectName = '?' . $innerJoinVariable;
     }
     //*** Exchange arguments when property is inverse ***//
     if ($diProperty->isInverse()) {
         // don't check if this really makes sense
         $subjectName = $objectName;
         $objectName = '?' . $joinVariable;
         $diNonInverseProperty = new SMWDIProperty($diProperty->getKey(), false);
     } else {
         $subjectName = '?' . $joinVariable;
         $diNonInverseProperty = $diProperty;
     }
     //*** Build the condition ***//
     $typeId = $diProperty->findPropertyTypeID();
     $diType = SMWDataValueFactory::getDataItemId($typeId);
     // for types that use helper properties in encoding values, refer to this helper property:
     if (SMWExporter::hasHelperExpElement($diType)) {
         $propertyExpElement = SMWExporter::getResourceElementForProperty($diNonInverseProperty, true);
     } else {
         $propertyExpElement = SMWExporter::getResourceElementForProperty($diNonInverseProperty);
     }
     $propertyName = SMWTurtleSerializer::getTurtleNameForExpElement($propertyExpElement);
     if ($propertyExpElement instanceof SMWExpNsResource) {
         $namespaces[$propertyExpElement->getNamespaceId()] = $propertyExpElement->getNamespace();
     }
     $condition = "{$subjectName} {$propertyName} {$objectName} .\n";
     $innerConditionString = $innerCondition->getCondition() . $innerCondition->getWeakConditionString();
     if ($innerConditionString !== '') {
         if ($innerCondition instanceof SMWSparqlFilterCondition) {
             $condition .= $innerConditionString;
         } else {
             $condition .= "{ {$innerConditionString}}\n";
         }
     }
     $result = new SMWSparqlWhereCondition($condition, true, $namespaces);
     //*** Record inner ordering variable if found ***//
     $result->orderVariables = $innerCondition->orderVariables;
     if (!is_null($innerOrderByProperty) && $innerCondition->orderByVariable !== '') {
         $result->orderVariables[$diProperty->getKey()] = $innerCondition->orderByVariable;
     }
     $this->addOrderByDataForProperty($result, $joinVariable, $orderByProperty, SMWDataItem::TYPE_WIKIPAGE);
     return $result;
 }
Ejemplo n.º 4
0
 public function testExportSubobject()
 {
     $semanticData = $this->semanticDataFactory->newEmptySemanticData(__METHOD__);
     $subobject = new Subobject($semanticData->getSubject()->getTitle());
     $subobject->setEmptyContainerForId('Foo');
     $semanticData->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer());
     $exportData = Exporter::makeExportData($semanticData);
     $expectedProperty = new ExpNsResource($this->transformPropertyLabelToAuxiliary($subobject->getProperty()), Exporter::getNamespaceUri('property'), 'property', new DIWikiPage('Has_subobject', SMW_NS_PROPERTY));
     $this->assertTrue(Exporter::hasHelperExpElement($subobject->getProperty()));
     $this->assertCount(1, $exportData->getValues($expectedProperty));
     $this->exportDataValidator->assertThatExportDataContainsProperty($expectedProperty, $exportData);
     $expectedResource = new ExpNsResource(Exporter::getEncodedPageName($subobject->getSemanticData()->getSubject()) . '-23' . 'Foo', Exporter::getNamespaceUri('wiki'), 'wiki', $subobject->getSemanticData()->getSubject());
     $this->exportDataValidator->assertThatExportDataContainsResource($expectedResource, $expectedProperty, $exportData);
 }