/** * Create an Condition from a NamespaceDescription * * @param NamespaceDescription $description * @param string $joinVariable * @param DIProperty|null $orderByProperty * * @return Condition */ public function buildCondition(Description $description, $joinVariable, $orderByProperty = null) { $nspropExpElement = $this->exporter->getSpecialNsResource('swivt', 'wikiNamespace'); $nsExpElement = new ExpLiteral(strval($description->getNamespace()), 'http://www.w3.org/2001/XMLSchema#integer'); $nsName = TurtleSerializer::getTurtleNameForExpElement($nsExpElement); $condition = "{ ?{$joinVariable} " . $nspropExpElement->getQName() . " {$nsName} . }\n"; $result = new WhereCondition($condition, true, array()); $this->compoundConditionBuilder->addOrderByDataForProperty($result, $joinVariable, $orderByProperty, DataItem::TYPE_WIKIPAGE); return $result; }
/** * Create an Condition from an ClassDescription. * * @param ClassDescription $description * @param string $joinVariable * @param DIProperty|null $orderByProperty * * @return Condition */ public function buildCondition(Description $description, $joinVariable, $orderByProperty = null) { list($condition, $namespaces) = $this->mapCategoriesToConditionElements($description->getCategories(), $joinVariable); // empty disjunction: always false, no results to order if ($condition === '') { return new FalseCondition(); } $result = new WhereCondition($condition, true, $namespaces); $this->compoundConditionBuilder->addOrderByDataForProperty($result, $joinVariable, $orderByProperty, DataItem::TYPE_WIKIPAGE); return $result; }
/** * @since 2.2 * * {@inheritDoc} */ public function interpretDescription(Description $description) { $joinVariable = $this->compoundConditionBuilder->getJoinVariable(); $orderByProperty = $this->compoundConditionBuilder->getOrderByProperty(); $subDescriptions = $description->getDescriptions(); $result = $this->doPreliminarySubDescriptionCheck($subDescriptions, $joinVariable, $orderByProperty); if ($result !== null) { return $result; } $subConditionElements = $this->doResolveSubDescriptionsRecursively($subDescriptions, $joinVariable); if ($subConditionElements instanceof FalseCondition) { return $subConditionElements; } $result = $this->createConditionFromSubConditionElements($subConditionElements); $result->weakConditions = $subConditionElements->weakConditions; $result->orderVariables = $subConditionElements->orderVariables; $this->compoundConditionBuilder->addOrderByDataForProperty($result, $joinVariable, $orderByProperty); return $result; }
/** * @since 2.2 * * {@inheritDoc} */ public function interpretDescription(Description $description) { $joinVariable = $this->compoundConditionBuilder->getJoinVariable(); $orderByProperty = $this->compoundConditionBuilder->getOrderByProperty(); $property = $description->getProperty(); list($innerOrderByProperty, $innerCondition, $innerJoinVariable) = $this->doResolveInnerConditionRecursively($property, $description->getDescription()); if ($innerCondition instanceof FalseCondition) { return new FalseCondition(); } $namespaces = $innerCondition->namespaces; $objectName = $this->findObjectNameFromInnerCondition($innerCondition, $innerJoinVariable, $namespaces); list($subjectName, $objectName, $nonInverseProperty) = $this->doExchangeForWhenInversePropertyIsUsed($property, $objectName, $joinVariable); $propertyName = $this->getPropertyNameByUsingTurtleSerializer($property, $nonInverseProperty, $namespaces); $condition = $this->concatenateToConditionString($subjectName, $propertyName, $objectName, $innerCondition); $result = new WhereCondition($condition, true, $namespaces); // Record inner ordering variable if found $result->orderVariables = $innerCondition->orderVariables; if ($innerOrderByProperty !== null && $innerCondition->orderByVariable !== '') { $result->orderVariables[$property->getKey()] = $innerCondition->orderByVariable; } $this->compoundConditionBuilder->addOrderByDataForProperty($result, $joinVariable, $orderByProperty, DataItem::TYPE_WIKIPAGE); return $result; }
private function createConditionForRegexComparator($dataItem, $joinVariable, $orderByProperty, $comparator) { if (!$dataItem instanceof DIBlob && !$dataItem instanceof DIWikiPage && !$dataItem instanceof DIUri) { return $this->compoundConditionBuilder->buildTrueCondition($joinVariable, $orderByProperty); } if ($dataItem instanceof DIBlob) { $search = $dataItem->getString(); } else { $search = $dataItem->getSortKey(); } $pattern = '^' . str_replace(array('https://', 'http://', '%2A', '^', '.', '\\', '+', '{', '}', '(', ')', '|', '^', '$', '[', ']', '*', '?', '"'), array('', '', '*', '\\^', '\\.', '\\\\', '\\+', '\\{', '\\}', '\\(', '\\)', '\\|', '\\^', '\\$', '\\[', '\\]', '.*', '.', '\\"'), $search) . '$'; $condition = $this->createFilterConditionToMatchRegexPattern($dataItem, $joinVariable, $comparator, $pattern); $this->compoundConditionBuilder->addOrderByDataForProperty($condition, $joinVariable, $orderByProperty, $dataItem->getDIType()); return $condition; }
/** * Recursively create an Condition from an Disjunction * * @param Disjunction $description * @param string $joinVariable * @param DIProperty|null $orderByProperty * * @return Condition */ public function buildCondition(Description $description, $joinVariable, $orderByProperty = null) { $subDescriptions = $description->getDescriptions(); $result = $this->doPreliminarySubDescriptionCheck($subDescriptions, $joinVariable, $orderByProperty); if ($result !== null) { return $result; } $subConditionElements = $this->doResolveSubDescriptionsRecursively($subDescriptions, $joinVariable, $orderByProperty); if ($subConditionElements instanceof TrueCondition) { return $subConditionElements; } if ($subConditionElements->unionCondition === '' && $subConditionElements->filter === '') { return new FalseCondition(); } $result = $this->createConditionFromSubConditionElements($subConditionElements, $joinVariable); $result->weakConditions = $subConditionElements->weakConditions; $this->compoundConditionBuilder->addOrderByDataForProperty($result, $joinVariable, $orderByProperty); return $result; }
private function createConditionForRegexComparator($dataItem, $joinVariable, $orderByProperty, $comparator) { if (!$dataItem instanceof DIBlob && !$dataItem instanceof DIWikiPage && !$dataItem instanceof DIUri) { return $this->compoundConditionBuilder->newTrueCondition($joinVariable, $orderByProperty); } if ($dataItem instanceof DIBlob) { $search = $dataItem->getString(); } else { $search = $dataItem->getSortKey(); } // @codingStandardsIgnoreStart phpcs, ignore --sniffs=Generic.Files.LineLength $pattern = '^' . str_replace(array('https://', 'http://', '%2A', '.', '+', '{', '}', '(', ')', '|', '^', '$', '[', ']', '*', '?', "'", '\\\\.', '\\', '"', '\\\\\\\\"'), array('', '', '*', '\\.', '\\+', '\\{', '\\}', '\\(', '\\)', '\\|', '\\^', '\\$', '\\[', '\\]', '.*', '.', "\\'", '\\\\\\.', '\\\\', '\\\\\\"', '\\\\\\\\\\\\"'), $search) . '$'; // @codingStandardsIgnoreEnd $condition = $this->createFilterConditionToMatchRegexPattern($dataItem, $joinVariable, $comparator, $pattern); $redirectByVariable = $this->compoundConditionBuilder->tryToFindRedirectVariableForDataItem($dataItem); if ($redirectByVariable !== null) { $condition->matchElement = $redirectByVariable; } $this->compoundConditionBuilder->addOrderByDataForProperty($condition, $joinVariable, $orderByProperty, $dataItem->getDIType()); return $condition; }