예제 #1
0
 /**
  * Create a Condition from a ConceptDescription
  *
  * @param ConceptDescription $description
  * @param string $joinVariable
  * @param DIProperty|null $orderByProperty
  *
  * @return Condition
  */
 public function buildCondition(Description $description, $joinVariable, $orderByProperty = null)
 {
     $conceptDescription = $this->getConceptDescription($description->getConcept());
     if ($conceptDescription === '') {
         return new FalseCondition();
     }
     return $this->compoundConditionBuilder->mapDescriptionToCondition($conceptDescription, $joinVariable, $orderByProperty);
 }
 private function doResolveSubDescriptionsRecursively($subDescriptions, $joinVariable, $orderByProperty)
 {
     // Using a stdClass as data container for simpler handling in follow-up tasks
     // and as the class is not exposed publicly we don't need to create
     // an extra "real" class to manage its elements
     $subConditionElements = new \stdClass();
     $subConditionElements->unionCondition = '';
     $subConditionElements->filter = '';
     $namespaces = $weakConditions = array();
     $hasSafeSubconditions = false;
     foreach ($subDescriptions as $subDescription) {
         $this->compoundConditionBuilder->setJoinVariable($joinVariable);
         $this->compoundConditionBuilder->setOrderByProperty(null);
         $subCondition = $this->compoundConditionBuilder->mapDescriptionToCondition($subDescription);
         if ($subCondition instanceof FalseCondition) {
             // empty parts in a disjunction can be ignored
         } elseif ($subCondition instanceof TrueCondition) {
             return $this->compoundConditionBuilder->newTrueCondition($joinVariable, $orderByProperty);
         } elseif ($subCondition instanceof WhereCondition) {
             $hasSafeSubconditions = $hasSafeSubconditions || $subCondition->isSafe();
             $subConditionElements->unionCondition .= ($subConditionElements->unionCondition ? ' UNION ' : '') . "{\n" . $subCondition->condition . "}";
         } elseif ($subCondition instanceof FilterCondition) {
             $subConditionElements->filter .= ($subConditionElements->filter ? ' || ' : '') . $subCondition->filter;
         } elseif ($subCondition instanceof SingletonCondition) {
             $hasSafeSubconditions = $hasSafeSubconditions || $subCondition->isSafe();
             $matchElement = $subCondition->matchElement;
             if ($matchElement instanceof ExpElement) {
                 $matchElementName = TurtleSerializer::getTurtleNameForExpElement($matchElement);
             } else {
                 $matchElementName = $matchElement;
             }
             if ($matchElement instanceof ExpNsResource) {
                 $namespaces[$matchElement->getNamespaceId()] = $matchElement->getNamespace();
             }
             if ($subCondition->condition === '') {
                 $subConditionElements->filter .= ($subConditionElements->filter ? ' || ' : '') . "?{$joinVariable} = {$matchElementName}";
             } else {
                 $subConditionElements->unionCondition .= ($subConditionElements->unionCondition ? ' UNION ' : '') . "{\n" . $subCondition->condition . " FILTER( ?{$joinVariable} = {$matchElementName} ) }";
             }
             // Relates to wikipage [[Foo::~*a*||~*A*]] in value regex disjunction
             // where a singleton is required to search against the sortkey but
             // replacing the filter with the condition temporary stored in
             // weakconditions
             if ($subConditionElements->unionCondition && $subCondition->weakConditions !== array()) {
                 $weakCondition = array_shift($subCondition->weakConditions);
                 $subConditionElements->unionCondition = str_replace("FILTER( ?{$joinVariable} = {$matchElementName} )", $weakCondition, $subConditionElements->unionCondition);
             }
         }
         $namespaces = array_merge($namespaces, $subCondition->namespaces);
         $weakConditions = array_merge($weakConditions, $subCondition->weakConditions);
     }
     $subConditionElements->namespaces = $namespaces;
     $subConditionElements->weakConditions = $weakConditions;
     $subConditionElements->hasSafeSubconditions = $hasSafeSubconditions;
     return $subConditionElements;
 }
 /**
  * @since 2.2
  *
  * {@inheritDoc}
  */
 public function interpretDescription(Description $description)
 {
     $joinVariable = $this->compoundConditionBuilder->getJoinVariable();
     $orderByProperty = $this->compoundConditionBuilder->getOrderByProperty();
     $conceptDescription = $this->getConceptDescription($description->getConcept());
     if ($conceptDescription === '') {
         return new FalseCondition();
     }
     $hash = 'concept-' . $conceptDescription->getQueryString();
     $this->compoundConditionBuilder->getCircularReferenceGuard()->mark($hash);
     if ($this->compoundConditionBuilder->getCircularReferenceGuard()->isCircularByRecursionFor($hash)) {
         $this->compoundConditionBuilder->addError(wfMessage('smw-query-condition-circular', $conceptDescription->getQueryString())->text());
         return new FalseCondition();
     }
     $this->compoundConditionBuilder->setJoinVariable($joinVariable);
     $this->compoundConditionBuilder->setOrderByProperty($orderByProperty);
     $condition = $this->compoundConditionBuilder->mapDescriptionToCondition($conceptDescription);
     $this->compoundConditionBuilder->getCircularReferenceGuard()->unmark($hash);
     return $condition;
 }
예제 #4
0
 private function doResolveInnerConditionRecursively(DIProperty $property, Description $description)
 {
     $innerOrderByProperty = null;
     // Find out if we should order by the values of this property
     if (array_key_exists($property->getKey(), $this->compoundConditionBuilder->getSortKeys())) {
         $innerOrderByProperty = $property;
     }
     // Prepare inner condition
     $innerJoinVariable = $this->compoundConditionBuilder->getNextVariable();
     $innerCondition = $this->compoundConditionBuilder->mapDescriptionToCondition($description, $innerJoinVariable, $innerOrderByProperty);
     return array($innerOrderByProperty, $innerCondition, $innerJoinVariable);
 }
 private function doResolveSubDescriptionsRecursively($subDescriptions, $joinVariable)
 {
     // Using a stdClass as data container for simpler handling in follow-up tasks
     // and as the class is not exposed publicly we don't need to create
     // an extra "real" class to manage its elements
     $subConditionElements = new \stdClass();
     $subConditionElements->condition = '';
     $subConditionElements->filter = '';
     $subConditionElements->singletonMatchElement = null;
     $namespaces = $weakConditions = $orderVariables = array();
     $singletonMatchElementName = '';
     $hasSafeSubconditions = false;
     foreach ($subDescriptions as $subDescription) {
         $this->compoundConditionBuilder->setJoinVariable($joinVariable);
         $this->compoundConditionBuilder->setOrderByProperty(null);
         $subCondition = $this->compoundConditionBuilder->mapDescriptionToCondition($subDescription);
         if ($subCondition instanceof FalseCondition) {
             return new FalseCondition();
         } elseif ($subCondition instanceof TrueCondition) {
             // ignore true conditions in a conjunction
         } elseif ($subCondition instanceof WhereCondition) {
             $subConditionElements->condition .= $subCondition->condition;
         } elseif ($subCondition instanceof FilterCondition) {
             $subConditionElements->filter .= ($subConditionElements->filter ? ' && ' : '') . $subCondition->filter;
         } elseif ($subCondition instanceof SingletonCondition) {
             $matchElement = $subCondition->matchElement;
             if ($matchElement instanceof ExpElement) {
                 $matchElementName = TurtleSerializer::getTurtleNameForExpElement($matchElement);
             } else {
                 $matchElementName = $matchElement;
             }
             if ($matchElement instanceof ExpNsResource) {
                 $namespaces[$matchElement->getNamespaceId()] = $matchElement->getNamespace();
             }
             if ($subConditionElements->singletonMatchElement !== null && $singletonMatchElementName !== $matchElementName) {
                 return new FalseCondition();
             }
             $subConditionElements->condition .= $subCondition->condition;
             $subConditionElements->singletonMatchElement = $subCondition->matchElement;
             $singletonMatchElementName = $matchElementName;
         }
         $hasSafeSubconditions = $hasSafeSubconditions || $subCondition->isSafe();
         $namespaces = array_merge($namespaces, $subCondition->namespaces);
         $weakConditions = array_merge($weakConditions, $subCondition->weakConditions);
         $orderVariables = array_merge($orderVariables, $subCondition->orderVariables);
     }
     $subConditionElements->hasSafeSubconditions = $hasSafeSubconditions;
     $subConditionElements->namespaces = $namespaces;
     $subConditionElements->weakConditions = $weakConditions;
     $subConditionElements->orderVariables = $orderVariables;
     return $subConditionElements;
 }
 private function doResolveSubDescriptionsRecursively($subDescriptions, $joinVariable, $orderByProperty)
 {
     // Using a stdClass as data container for simpler handling in follow-up tasks
     // and as the class is not exposed publicly we don't need to create
     // an extra "real" class to manage its elements
     $subConditionElements = new \stdClass();
     $subConditionElements->unionCondition = '';
     $subConditionElements->filter = '';
     $namespaces = $weakConditions = array();
     $hasSafeSubconditions = false;
     foreach ($subDescriptions as $subDescription) {
         $subCondition = $this->compoundConditionBuilder->mapDescriptionToCondition($subDescription, $joinVariable, null);
         if ($subCondition instanceof FalseCondition) {
             // empty parts in a disjunction can be ignored
         } elseif ($subCondition instanceof TrueCondition) {
             return $this->compoundConditionBuilder->buildTrueCondition($joinVariable, $orderByProperty);
         } elseif ($subCondition instanceof WhereCondition) {
             $hasSafeSubconditions = $hasSafeSubconditions || $subCondition->isSafe();
             $subConditionElements->unionCondition .= ($subConditionElements->unionCondition ? ' UNION ' : '') . "{\n" . $subCondition->condition . "}";
         } elseif ($subCondition instanceof FilterCondition) {
             $subConditionElements->filter .= ($subConditionElements->filter ? ' || ' : '') . $subCondition->filter;
         } elseif ($subCondition instanceof SingletonCondition) {
             $hasSafeSubconditions = $hasSafeSubconditions || $subCondition->isSafe();
             $matchElement = $subCondition->matchElement;
             if ($matchElement instanceof ExpElement) {
                 $matchElementName = TurtleSerializer::getTurtleNameForExpElement($matchElement);
             } else {
                 $matchElementName = $matchElement;
             }
             if ($matchElement instanceof ExpNsResource) {
                 $namespaces[$matchElement->getNamespaceId()] = $matchElement->getNamespace();
             }
             if ($subCondition->condition === '') {
                 $subConditionElements->filter .= ($subConditionElements->filter ? ' || ' : '') . "?{$joinVariable} = {$matchElementName}";
             } else {
                 $subConditionElements->unionCondition .= ($subConditionElements->unionCondition ? ' UNION ' : '') . "{\n" . $subCondition->condition . " FILTER( ?{$joinVariable} = {$matchElementName} ) }";
             }
         }
         $namespaces = array_merge($namespaces, $subCondition->namespaces);
         $weakConditions = array_merge($weakConditions, $subCondition->weakConditions);
     }
     $subConditionElements->namespaces = $namespaces;
     $subConditionElements->weakConditions = $weakConditions;
     $subConditionElements->hasSafeSubconditions = $hasSafeSubconditions;
     return $subConditionElements;
 }