public static Function constructNewFunction(List<Function> subAtoms, Predicate functionSymbol) { List<Term> subTerms = (List<Term>)(List<?>) subAtoms; return constructNewFunction(functionSymbol, subTerms); }
public Expression foldBooleanConditions(java.util.List<Function> booleanAtoms) { return foldBooleanConditions(List.iterableList(booleanAtoms)); }
@Override public Boolean f(Function atom) { return isDataOrLeftJoinOrJoinAtom(atom); } };
protected AtomClassification(List<Function> atoms, DatalogTools datalogTools) throws DatalogProgram2QueryConverterImpl.InvalidDatalogProgramException { dataAndCompositeAtoms = datalogTools.filterDataAndCompositeAtoms(atoms); List<Function> otherAtoms = datalogTools.filterNonDataAndCompositeAtoms(atoms); booleanAtoms = datalogTools.filterBooleanAtoms(otherAtoms); if (dataAndCompositeAtoms.isEmpty()) throw new DatalogProgram2QueryConverterImpl.InvalidDatalogProgramException("No data or composite atom in " + atoms); /* * May throw a NotSupportedConversionException */ checkNonDataOrCompositeAtomSupport(otherAtoms, booleanAtoms); }
if (isRealJoin(subAtoms)) { Function joiningCondition = DatalogTools.foldBooleanConditions(normalizationResult.getPushableBoolAtoms()); Function normalizedJoinMetaAtom = foldJoin(normalizationResult.getNonPushableAtoms(),joiningCondition);
@Inject private DatalogTools(TermFactory termFactory, DatalogFactory datalogFactory) { this.termFactory = termFactory; this.datalogFactory = datalogFactory; ValueConstant valueTrue = termFactory.getBooleanConstant(true); TRUE_EQ = termFactory.getFunctionEQ(valueTrue, valueTrue); IS_DATA_OR_LJ_OR_JOIN_ATOM_FCT = this::isDataOrLeftJoinOrJoinAtom; IS_NOT_DATA_OR_COMPOSITE_ATOM_FCT = atom -> !isDataOrLeftJoinOrJoinAtom(atom); IS_BOOLEAN_ATOM_FCT = atom -> atom.isOperation() || isXsdBoolean(atom.getFunctionSymbol()); }
/** * Folds a list of data/composite atoms and joining conditions into a JOIN(...) with a 3-arity. * */ public static Function foldJoin(List<Function> dataOrCompositeAtoms, Function joiningCondition) { int length = dataOrCompositeAtoms.length(); if (length < 2) { throw new IllegalArgumentException("At least two atoms should be given"); } Function firstAtom = dataOrCompositeAtoms.head(); Function secondAtom = foldJoin(dataOrCompositeAtoms.tail()); return DATALOG_FACTORY.getSPARQLJoin(firstAtom, secondAtom, joiningCondition); }
/** * Folds a list of boolean atoms into one AND(AND(...)) boolean atom. */ public static Expression foldBooleanConditions(List<Function> booleanAtoms) { if (booleanAtoms.length() == 0) return TRUE_EQ; Expression firstBooleanAtom = convertOrCastIntoBooleanAtom( booleanAtoms.head()); return booleanAtoms.tail().foldLeft(new F2<Expression, Function, Expression>() { @Override public Expression f(Expression previousAtom, Function currentAtom) { return TERM_FACTORY.getFunctionAND(previousAtom, currentAtom); } }, firstBooleanAtom); }
public Boolean isDataOrLeftJoinOrJoinAtom(Function atom) { return atom.isDataFunction() || isLeftJoinOrJoinAtom(atom); }
protected AtomClassification(List<Function> atoms) throws DatalogProgram2QueryConverterImpl.InvalidDatalogProgramException { dataAndCompositeAtoms = DatalogTools.filterDataAndCompositeAtoms(atoms); List<Function> otherAtoms = DatalogTools.filterNonDataAndCompositeAtoms(atoms); booleanAtoms = DatalogTools.filterBooleanAtoms(otherAtoms); if (dataAndCompositeAtoms.isEmpty()) throw new DatalogProgram2QueryConverterImpl.InvalidDatalogProgramException("No data or composite atom in " + atoms); optionalGroupAtom = extractOptionalGroupAtom(otherAtoms); /* * May throw a NotSupportedConversionException */ checkNonDataOrCompositeAtomSupport(otherAtoms, booleanAtoms, optionalGroupAtom); }
/** * Folds a list of boolean atoms into one AND(AND(...)) boolean atom. */ public Expression foldBooleanConditions(List<Function> booleanAtoms) { if (booleanAtoms.length() == 0) return TRUE_EQ; Expression firstBooleanAtom = convertOrCastIntoBooleanAtom( booleanAtoms.head()); return booleanAtoms.tail().foldLeft(new F2<Expression, Function, Expression>() { @Override public Expression f(Expression previousAtom, Function currentAtom) { return termFactory.getFunctionAND(previousAtom, currentAtom); } }, firstBooleanAtom); }
public static Boolean isDataOrLeftJoinOrJoinAtom(Function atom) { return atom.isDataFunction() || isLeftJoinOrJoinAtom(atom); }
public static Expression foldBooleanConditions(java.util.List<Function> booleanAtoms) { return foldBooleanConditions(List.iterableList(booleanAtoms)); }
@Override public Boolean f(Function atom) { return !isDataOrLeftJoinOrJoinAtom(atom); } };
Function newFunctionalTerm = constructNewFunction(functionalTerm.getFunctionSymbol(), newSubTerms);
private Optional<ImmutableExpression> createFilterExpression(List<Function> booleanAtoms) { if (booleanAtoms.isEmpty()) return Optional.empty(); return Optional.of(termFactory.getImmutableExpression(datalogTools.foldBooleanConditions(booleanAtoms))); }
@Override public Boolean f(Function atom) { return isDataOrLeftJoinOrJoinAtom(atom); } });
private static Optional<ImmutableExpression> createFilterExpression(List<Function> booleanAtoms) { if (booleanAtoms.isEmpty()) return Optional.empty(); return Optional.of(TERM_FACTORY.getImmutableExpression(DatalogTools.foldBooleanConditions(booleanAtoms))); }
public static P2<List<Function>, List<Function>> splitLeftJoinSubAtoms(List<Function> ljSubAtoms) { // TODO: make it static (performance improvement). F<Function, Boolean> isNotDataOrCompositeAtomFct = atom -> !(isDataOrLeftJoinOrJoinAtom(atom)); /** * Left: left of the first data/composite atom (usually empty). * * The first data/composite atom is thus the first element of the right list. */ P2<List<Function>, List<Function>> firstDataAtomSplit = ljSubAtoms.span(isNotDataOrCompositeAtomFct); Function firstDataAtom = firstDataAtomSplit._2().head(); /** * Left: left of the second data/composite atom starting just after the first data/composite atom. * * Right: right part of the left join (includes the joining conditions, no problem). */ P2<List<Function>, List<Function>> secondDataAtomSplit = firstDataAtomSplit._2().tail().span( isNotDataOrCompositeAtomFct); List<Function> leftAtoms = firstDataAtomSplit._1().snoc(firstDataAtom).append(secondDataAtomSplit._1()); List<Function> rightAtoms = secondDataAtomSplit._2(); return P.p(leftAtoms, rightAtoms); }
return termFactory.getFunctionIsNotNull(uriTemplate); else return datalogTools.foldBooleanConditions( variables.stream() .map(termFactory::getFunctionIsNotNull)