@Override public IQTree applyDescendingSubstitution(ImmutableSubstitution<? extends VariableOrGroundTerm> descendingSubstitution, Optional<ImmutableExpression> constraint, IQTree child) { return iqFactory.createUnaryIQTree(this, child.applyDescendingSubstitution(descendingSubstitution, constraint)); }
@Override public IQTree applyDescendingSubstitutionWithoutOptimizing( ImmutableSubstitution<? extends VariableOrGroundTerm> descendingSubstitution, IQTree child) { return iqFactory.createUnaryIQTree(this, child.applyDescendingSubstitutionWithoutOptimizing(descendingSubstitution)); }
@Override public IQTree propagateDownConstraint(ImmutableExpression constraint, IQTree child) { return iqFactory.createUnaryIQTree(this, child.propagateDownConstraint(constraint)); }
@Override public IQTree applyDescendingSubstitution(ImmutableSubstitution<? extends VariableOrGroundTerm> descendingSubstitution, Optional<ImmutableExpression> constraint, IQTree child) { return iqFactory.createUnaryIQTree(this, child.applyDescendingSubstitution(descendingSubstitution, constraint)); }
@Override public IQTree applyDescendingSubstitutionWithoutOptimizing( ImmutableSubstitution<? extends VariableOrGroundTerm> descendingSubstitution, IQTree child) { return iqFactory.createUnaryIQTree(this, child.applyDescendingSubstitutionWithoutOptimizing(descendingSubstitution)); }
/** * TODO: implement it seriously */ private IQTree liftSliceChild(SliceNode newChildRoot, IQTree newChild, IQProperties currentIQProperties) { return iqFactory.createUnaryIQTree(this, newChild, currentIQProperties.declareLifted()); }
@Override public IQTree propagateDownConstraint(ImmutableExpression constraint, IQTree child) { try { Optional<ImmutableExpression> childConstraint = computeChildConstraint(substitution, Optional.of(constraint)); IQTree newChild = childConstraint .map(child::propagateDownConstraint) .orElse(child); return iqFactory.createUnaryIQTree(this, newChild); } catch (EmptyTreeException e) { return iqFactory.createEmptyNode(projectedVariables); } }
/** * Lifts the construction node above and updates the order comparators */ private IQTree liftChildConstructionNode(ConstructionNode newChildRoot, UnaryIQTree newChild, IQProperties liftedProperties) { UnaryIQTree newOrderByTree = iqFactory.createUnaryIQTree( applySubstitution(newChildRoot.getSubstitution()), newChild.getChild(), liftedProperties); return iqFactory.createUnaryIQTree(newChildRoot, newOrderByTree, liftedProperties); }
@Override public IQTree applyDescendingSubstitution(ImmutableSubstitution<? extends VariableOrGroundTerm> descendingSubstitution, Optional<ImmutableExpression> constraint, IQTree child) { OrderByNode newOrderByTree = applySubstitution(descendingSubstitution); IQTree newChild = child.applyDescendingSubstitution(descendingSubstitution, constraint); return iqFactory.createUnaryIQTree(newOrderByTree, newChild); }
private static IQ createFact(ConstructionNode topConstructionNode, Optional<ImmutableQueryModifiers> optionalModifiers, DistinctVariableOnlyDataAtom projectionAtom, IntermediateQueryFactory iqFactory) { IQTree constructionTree = iqFactory.createUnaryIQTree(topConstructionNode, iqFactory.createTrueNode()); IQTree tree = optionalModifiers .map(m -> m.insertAbove(constructionTree, iqFactory)) .orElse(constructionTree); return iqFactory.createIQ(projectionAtom, tree); }
@Override public IQTree insertAbove(IQTree childTree, IntermediateQueryFactory iqFactory) { ImmutableList<UnaryOperatorNode> modifierNodes = extractModifierNodes(iqFactory); return modifierNodes.reverse().stream() .reduce(childTree, (t, n) -> iqFactory.createUnaryIQTree(n, t), (t1, t2) -> {throw new MinorOntopInternalBugException("Merging should never been executed"); }); }
@Override public IQTree applyDescendingSubstitutionWithoutOptimizing( ImmutableSubstitution<? extends VariableOrGroundTerm> descendingSubstitution, IQTree child) { OrderByNode newOrderByTree = applySubstitution(descendingSubstitution); IQTree newChild = child.applyDescendingSubstitutionWithoutOptimizing(descendingSubstitution); return iqFactory.createUnaryIQTree(newOrderByTree, newChild); }
private UnaryIQTree liftUnary(UnaryIQTree queryTree, VariableGenerator variableGenerator) { IQTree newChild = liftTree(queryTree.getChild(), variableGenerator); return newChild.equals(queryTree.getChild()) ? queryTree : iqFactory.createUnaryIQTree(queryTree.getRootNode(), newChild); }
private IQTree getIntensionalCanonizedTree(IQ assertion, DistinctVariableOnlyDataAtom projAtom, IntensionalDataNode intensionalDataNode) { return iqFactory.createUnaryIQTree( iqFactory.createConstructionNode(projAtom.getVariables()), iqFactory.createNaryIQTree( iqFactory.createInnerJoinNode(), ImmutableList.of( assertion.getTree(), intensionalDataNode ))); }
@Override public IQTree applyDescendingSubstitutionWithoutOptimizing( ImmutableSubstitution<? extends VariableOrGroundTerm> descendingSubstitution, IQTree child) { FilterNode newFilterNode = iqFactory.createFilterNode( descendingSubstitution.applyToBooleanExpression(getFilterCondition())); return iqFactory.createUnaryIQTree(newFilterNode, child.applyDescendingSubstitutionWithoutOptimizing(descendingSubstitution)); }
@Override public IQTree replaceSubTree(IQTree subTreeToReplace, IQTree newSubTree) { if (equals(subTreeToReplace)) return newSubTree; return iqFactory.createUnaryIQTree(getRootNode(), getChild().replaceSubTree(subTreeToReplace, newSubTree)); }
private IQ insertFilter(IQ originalQuery, ImmutableSet<ImmutableSet<Variable>> nullableVariables) { FilterNode filterNode = iQFactory.createFilterNode(computeFilterExpression(nullableVariables)); UnaryIQTree newTree = iQFactory.createUnaryIQTree(filterNode, originalQuery.getTree()); // TODO: normalize it return iQFactory.createIQ(originalQuery.getProjectionAtom(), newTree); } }
private IQTree liftBindingAfterPropagatingCondition(IQTree childIQTree, VariableGenerator variableGenerator, IQProperties currentIQProperties) { IQTree liftedChildIQTree = childIQTree.liftBinding(variableGenerator); QueryNode childRoot = liftedChildIQTree.getRootNode(); if (childRoot instanceof ConstructionNode) return liftBinding((ConstructionNode) childRoot, (UnaryIQTree) liftedChildIQTree, currentIQProperties, variableGenerator); else if (liftedChildIQTree.isDeclaredAsEmpty()) { return liftedChildIQTree; } else return iqFactory.createUnaryIQTree(this, liftedChildIQTree, currentIQProperties.declareLifted()); }
@Override public IQTree liftBinding(IQTree childIQTree, VariableGenerator variableGenerator, IQProperties currentIQProperties) { IQTree liftedChildIQTree = childIQTree.liftBinding(variableGenerator); QueryNode liftedChildRoot = liftedChildIQTree.getRootNode(); if (liftedChildRoot instanceof ConstructionNode) return liftBinding((ConstructionNode) liftedChildRoot, (UnaryIQTree) liftedChildIQTree, currentIQProperties); else if (liftedChildIQTree.isDeclaredAsEmpty()) { return iqFactory.createEmptyNode(projectedVariables); } else return iqFactory.createUnaryIQTree(this, liftedChildIQTree, currentIQProperties.declareLifted()); }
private IQTree liftBinding(ConstructionNode childConstructionNode, UnaryIQTree childIQ, IQProperties currentIQProperties) { AscendingSubstitutionNormalization ascendingNormalization = normalizeAscendingSubstitution( childConstructionNode.getSubstitution().composeWith(substitution), projectedVariables); ImmutableSubstitution<ImmutableTerm> newSubstitution = ascendingNormalization.getAscendingSubstitution(); IQTree grandChildIQTree = ascendingNormalization.normalizeChild(childIQ.getChild()); ConstructionNode newConstructionNode = iqFactory.createConstructionNode(projectedVariables, newSubstitution); return iqFactory.createUnaryIQTree(newConstructionNode, grandChildIQTree, currentIQProperties.declareLifted()); }