private function doMapSomeProperty(SomeProperty $description, &$exact)
 {
     $result = new ExpData(new ExpResource(''));
     $result->addPropertyObjectValue($this->exporter->getSpecialNsResource('rdf', 'type'), new ExpData($this->exporter->getSpecialNsResource('owl', 'Restriction')));
     $property = $description->getProperty();
     if ($property->isInverse()) {
         $property = new DIProperty($property->getKey());
     }
     $result->addPropertyObjectValue($this->exporter->getSpecialNsResource('owl', 'onProperty'), new ExpData($this->exporter->getResourceElementForProperty($property)));
     $subdata = $this->getExpDataFromDescription($description->getDescription(), $exact);
     if ($description->getDescription() instanceof ValueDescription && $description->getDescription()->getComparator() === SMW_CMP_EQ) {
         $result->addPropertyObjectValue($this->exporter->getSpecialNsResource('owl', 'hasValue'), $subdata);
     } else {
         if ($subdata === false) {
             $owltype = $this->exporter->getOWLPropertyType($description->getProperty()->findPropertyTypeID());
             if ($owltype == 'ObjectProperty') {
                 $subdata = new ExpData($this->exporter->getSpecialNsResource('owl', 'Thing'));
             } elseif ($owltype == 'DatatypeProperty') {
                 $subdata = new ExpData($this->exporter->getSpecialNsResource('rdfs', 'Literal'));
             } else {
                 // no restrictions at all with annotation properties ...
                 return new ExpData($this->exporter->getSpecialNsResource('owl', 'Thing'));
             }
         }
         $result->addPropertyObjectValue($this->exporter->getSpecialNsResource('owl', 'someValuesFrom'), $subdata);
     }
     return $result;
 }
 protected function getResourceElementHelperForProperty($property)
 {
     $key = 'resource:builder:aux:' . $property->getKey();
     if (($resourceElement = $this->inMemoryPoolCache->fetch($key)) !== false) {
         return $resourceElement;
     }
     $resourceElement = $this->exporter->getResourceElementForProperty($property, true);
     $this->inMemoryPoolCache->save($key, $resourceElement);
     return $resourceElement;
 }
 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;
 }