@Override public ImmutableExpression normalize(ImmutableExpression expression) { OperationPredicate functionSymbol = expression.getFunctionSymbol(); if (functionSymbol instanceof ExpressionOperation) { switch((ExpressionOperation)functionSymbol) { case ADD: case MULTIPLY: //case AND: //case OR: case EQ: case NEQ: return normalizeCommutative(functionSymbol, expression.getTerms()); default: return normalizeArguments(functionSymbol, expression.getTerms()); } } else { return expression; } }
/** * This method takes a immutable boolean term and convert it into an old mutable boolean function. */ public static Expression convertToMutableBooleanExpression(ImmutableExpression booleanExpression) { OperationPredicate pred = (OperationPredicate) booleanExpression.getFunctionSymbol(); ImmutableList<Term> otherTerms = booleanExpression.getTerms(); List<Term> mutableList = new ArrayList<>(); Iterator<Term> iterator = otherTerms.iterator(); while (iterator.hasNext()) { Term nextTerm = iterator.next(); if (nextTerm instanceof ImmutableFunctionalTerm) { ImmutableFunctionalTerm term2Change = (ImmutableFunctionalTerm) nextTerm; Function newTerm = convertToMutableFunction(term2Change); mutableList.add(newTerm); } else { mutableList.add(nextTerm); } } Expression mutFunc = TERM_FACTORY.getExpression(pred, mutableList); return mutFunc; }
/** * TODO: inject termFactory and typeFactory * */ default Optional<TermType> getOptionalTermType() throws IncompatibleTermException { try { OperationPredicate predicate = getFunctionSymbol(); return predicate.inferType(getTerms()); } catch (IncompatibleTermException e) { throw new IncompatibleTermException(this, e); } }
/** * This method takes a immutable boolean term and convert it into an old mutable boolean function. */ public Expression convertToMutableBooleanExpression(ImmutableExpression booleanExpression) { OperationPredicate pred = booleanExpression.getFunctionSymbol(); return termFactory.getExpression(pred, convertToMutableTerms(booleanExpression.getTerms())); }
private LeftJoinNode liftCondition(LeftJoinNode leftJoinNode, QueryNode leftChild, DataNode rightChild, ImmutableSet<Variable> requiredVariablesAboveLJ, QueryTreeComponent treeComponent, Optional<ImmutableSubstitution<ImmutableTerm>> remainingRightSubstitution, VariableGenerator variableGenerator, IntermediateQuery query) { ImmutableExpression ljCondition = leftJoinNode.getOptionalFilterCondition() .orElseThrow(() -> new IllegalArgumentException("The LJ is expected to have a joining condition")); ImmutableSet<Variable> leftVariables = query.getVariables(leftChild); ImmutableSet<Variable> requiredRightVariables = requiredVariablesAboveLJ.stream() .filter(v -> !leftVariables.contains(v)) .collect(ImmutableCollectors.toSet()); // Special case: ljCondition = IS_NOT_NULL(x) and x is a specific right variable // --> x will not be affected by the condition ImmutableSet<Variable> rightVariablesToUpdate = Optional.of(ljCondition) .filter(c -> c.getFunctionSymbol().equals(IS_NOT_NULL)) .map(c -> c.getTerms().get(0)) .filter(t -> t instanceof Variable) .map(v -> (Variable) v) .map(specialVariable -> requiredRightVariables.stream() .filter(v -> !v.equals(specialVariable)) .collect(ImmutableCollectors.toSet())) .orElse(requiredRightVariables); LeftJoinNode newLeftJoinNode = leftJoinNode.changeOptionalFilterCondition(Optional.empty()); treeComponent.replaceNode(leftJoinNode, newLeftJoinNode); return (rightVariablesToUpdate.isEmpty() && (!remainingRightSubstitution.isPresent())) ? newLeftJoinNode : updateConditionalVariables(rightVariablesToUpdate, rightChild, newLeftJoinNode, ljCondition, query, treeComponent, remainingRightSubstitution, variableGenerator); }
.filter(e -> e.getFunctionSymbol().equals(EQ)) .filter(e -> { ImmutableList<? extends ImmutableTerm> arguments = e.getTerms(); return arguments.stream().allMatch(t -> t instanceof NonFunctionalTerm) && arguments.stream().anyMatch(rightVariables::contains); expressions.stream() .filter(e -> (!downSubstitutionExpressions.contains(e)) || e.getTerms().stream().anyMatch(rightSpecificVariables::contains))) .map(downSubstitution::applyToBooleanExpression);
ImmutableList<Optional<TermType>> argumentTypes = expression.getTerms().stream() .map(t -> getCastTypeFromSubRule(t, bodyDataAtoms, alreadyKnownCastTypes)) .map(Optional::of)
.filter(e -> e.getFunctionSymbol().equals(EQ)) .filter(e -> { ImmutableList<? extends ImmutableTerm> arguments = e.getTerms(); return arguments.stream().allMatch(t -> t instanceof NonFunctionalTerm); })