Java Code Examples for org.eclipse.rdf4j.query.algebra.And#setRightArg()
The following examples show how to use
org.eclipse.rdf4j.query.algebra.And#setRightArg() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FilterUtils.java From CostFed with GNU Affero General Public License v3.0 | 6 votes |
public static ValueExpr toFilter(ConjunctiveFilterExpr filterExpr) throws FilterConversionException { List<FilterExpr> expressions = filterExpr.getExpressions(); if (expressions.size()==2) { return new And(expressions.get(0).getExpression(), expressions.get(0).getExpression()); } And and = new And(); and.setLeftArg( expressions.get(0).getExpression() ); And tmp = and; int idx; for (idx=1; idx<expressions.size()-1; idx++) { And _a = new And(); _a.setLeftArg( expressions.get(idx).getExpression() ); tmp.setRightArg(_a); tmp = _a; } tmp.setRightArg( expressions.get(idx).getExpression()); return and; }
Example 2
Source File: FilterUtils.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static ValueExpr toFilter(ConjunctiveFilterExpr filterExpr) throws FilterConversionException { List<FilterExpr> expressions = filterExpr.getExpressions(); if (expressions.size() == 2) { return new And(expressions.get(0).getExpression(), expressions.get(0).getExpression()); } And and = new And(); and.setLeftArg(expressions.get(0).getExpression()); And tmp = and; int idx; for (idx = 1; idx < expressions.size() - 1; idx++) { And _a = new And(); _a.setLeftArg(expressions.get(idx).getExpression()); tmp.setRightArg(_a); tmp = _a; } tmp.setRightArg(expressions.get(idx).getExpression()); return and; }
Example 3
Source File: BasicGroup.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
private ValueExpr filtersAsAnd() { ValueExpr aExpr = null; for (ValueExpr aValEx : mFilters) { if (aExpr == null) { aExpr = aValEx; } else { And aAnd = new And(); aAnd.setLeftArg(aValEx); aAnd.setRightArg(aExpr); aExpr = aAnd; } } return aExpr; }
Example 4
Source File: FilterOptimizer.java From CostFed with GNU Affero General Public License v3.0 | 4 votes |
@Override public void meet(Filter filter) { if (filter.getArg() instanceof EmptyResult) { log.debug("Argument of filter expression does not yield results at the provided sources, replacing Filter node."); filter.replaceWith(filter.getArg()); return; } /* * TODO idea: * if we have a FILTER such as ?s='a' OR ?s='b' OR ?s='c' handle this appropriately */ ValueExpr valueExpr = filter.getCondition(); /* * TODO transform condition into some normal form, e.g. CNF */ // determine conjunctive expressions List<ValueExpr> conjunctiveExpressions = new ArrayList<ValueExpr>(); getConjunctiveExpressions(valueExpr, conjunctiveExpressions); FilterExprInsertVisitor filterExprVst = new FilterExprInsertVisitor(); List<ValueExpr> remainingExpr = new ArrayList<ValueExpr>(conjunctiveExpressions.size()); for (ValueExpr cond : conjunctiveExpressions) { /* * Determine if this filter is applicable for optimization. * Currently only leaf expressions are applicable, i.e. * not combined expressions. */ if (isCompatibleExpr(cond)) { HashSet<String> exprVars = new VarFinder().findVars(cond); FilterExpr filterExpr = new FilterExpr(cond, exprVars); filterExprVst.initialize(filterExpr); filter.getArg().visit(filterExprVst); // if the filter expr. is handled in the stmt we do not have to keep it if (filterExprVst.canRemove()) continue; remainingExpr.add(filterExpr.getExpression()); } else { remainingExpr.add(cond); } } if (remainingExpr.size()==0) { filter.replaceWith(filter.getArg()); // remove the filter } else if (remainingExpr.size()==1) { filter.setCondition(remainingExpr.get(0)); // just apply the remaining condition } else { // construct conjunctive value expr And root = new And(); root.setLeftArg(remainingExpr.get(0)); And tmp = root; for (int i=1; i<remainingExpr.size()-1; i++) { And _a = new And(); _a.setLeftArg(remainingExpr.get(i)); tmp.setRightArg(_a); tmp = _a; } tmp.setRightArg(remainingExpr.get(remainingExpr.size()-1)); filter.setCondition(root); } }
Example 5
Source File: FilterOptimizer.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void meet(Filter filter) { if (filter.getArg() instanceof EmptyResult) { log.debug( "Argument of filter expression does not yield results at the provided sources, replacing Filter node."); filter.replaceWith(filter.getArg()); return; } /* * TODO idea: if we have a FILTER such as ?s='a' OR ?s='b' OR ?s='c' handle this appropriately */ ValueExpr valueExpr = filter.getCondition(); /* * TODO transform condition into some normal form, e.g. CNF */ // determine conjunctive expressions List<ValueExpr> conjunctiveExpressions = new ArrayList<>(); getConjunctiveExpressions(valueExpr, conjunctiveExpressions); FilterExprInsertVisitor filterExprVst = new FilterExprInsertVisitor(); List<ValueExpr> remainingExpr = new ArrayList<>(conjunctiveExpressions.size()); for (ValueExpr cond : conjunctiveExpressions) { /* * Determine if this filter is applicable for optimization. Currently only leaf expressions are applicable, * i.e. not combined expressions. */ if (isCompatibleExpr(cond)) { HashSet<String> exprVars = new VarFinder().findVars(cond); FilterExpr filterExpr = new FilterExpr(cond, exprVars); filterExprVst.initialize(filterExpr); filter.getArg().visit(filterExprVst); // if the filter expr. is handled in the stmt we do not have to keep it if (filterExprVst.canRemove()) { continue; } remainingExpr.add(filterExpr.getExpression()); } else { remainingExpr.add(cond); } } if (remainingExpr.isEmpty()) { filter.replaceWith(filter.getArg()); // remove the filter } else if (remainingExpr.size() == 1) { filter.setCondition(remainingExpr.get(0)); // just apply the remaining condition } else { // construct conjunctive value expr And root = new And(); root.setLeftArg(remainingExpr.get(0)); And tmp = root; for (int i = 1; i < remainingExpr.size() - 1; i++) { And _a = new And(); _a.setLeftArg(remainingExpr.get(i)); tmp.setRightArg(_a); tmp = _a; } tmp.setRightArg(remainingExpr.get(remainingExpr.size() - 1)); filter.setCondition(root); } }