本文整理汇总了Java中com.hp.hpl.jena.sparql.algebra.op.OpFilter.filter方法的典型用法代码示例。如果您正苦于以下问题:Java OpFilter.filter方法的具体用法?Java OpFilter.filter怎么用?Java OpFilter.filter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.hp.hpl.jena.sparql.algebra.op.OpFilter
的用法示例。
在下文中一共展示了OpFilter.filter方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createOpD2RQ
import com.hp.hpl.jena.sparql.algebra.op.OpFilter; //导入方法依赖的package包/类
public Op createOpD2RQ(OpBGP opBGP, ExprList filters) {
List<NodeRelation> tables = new GraphPatternTranslator(
opBGP.getPattern().getList(), mapping.compiledPropertyBridges(),
useAllOptimizations).translate();
if (useAllOptimizations) {
log.debug("NodeRelations before applying filters: " + tables.size());
ExprList copy = new ExprList(filters);
for (Expr filter: copy) {
tables = applyFilter(tables, filter, filters);
}
if (log.isDebugEnabled()) {
log.debug("NodeRelations after applying filters: " + tables.size());
}
}
Op op = OpUnionTableSQL.create(tables);
if (!filters.isEmpty()) {
op = OpFilter.filter(filters, op);
}
return op;
}
示例2: transform
import com.hp.hpl.jena.sparql.algebra.op.OpFilter; //导入方法依赖的package包/类
public Op transform(OpFilter opFilter, Op subOp) {
ExprList exprList = ExprList.splitConjunction(opFilter.getExprs());
ExprList cnfExprList = ExprList.splitConjunction(
TransformFilterCNF.translateFilterExpressionsToCNF(opFilter));
if (cnfExprList.size() > exprList.size()) {
return OpFilter.filter(cnfExprList, subOp);
}
return OpFilter.filter(exprList, subOp);
}
示例3: transform
import com.hp.hpl.jena.sparql.algebra.op.OpFilter; //导入方法依赖的package包/类
@Override
public Op transform(OpFilter opFilter, Op subOp) {
ExprList substitutedExprList = new ExprList();
for (Expr expr: opFilter.getExprs().getList()){
Map<String, Expr> substitutions = new HashMap<String, Expr>();
//for each expression see if it contains variables that are not mentioned within this clause
for (Var var: expr.getVarsMentioned()){
QueryVar mentionedQueryVar=this.mentionedVars.get(var);
if (mentionedQueryVar==null) {
//No mentioned variables so filter not relevant
return subOp;
}else
{
//Mentioned so add the new name to the substitutions set.
Var substitutedVar = Var.alloc(mentionedQueryVar.getLinkedName(this.queryClause.getDataset()));
substitutions.put(var.getName(), new ExprVar(substitutedVar));
}
}
//Only get here if all vars mentioned in expression are within clause
ExprTransformSubstitute exprTransformSubstitute = new ExprTransformSubstitute( substitutions );
Expr substitutedExpression = (Expr) ExprTransformer.transform(exprTransformSubstitute, expr);
substitutedExprList.add(substitutedExpression);
}
return OpFilter.filter(substitutedExprList, subOp);
}
示例4: checkMoveDownFilterExprAndVisitOpUnion
import com.hp.hpl.jena.sparql.algebra.op.OpFilter; //导入方法依赖的package包/类
/**
* Checks first if a filterexpression can be moved down. And after visits
* the operator
*/
private void checkMoveDownFilterExprAndVisitOpUnion(OpUnion opUnion) {
Op left = null;
Op right = null;
Op newOp;
List<Expr> filterExprBeforeOpUnion, filterExprAfterOpUnion, notMoveableFilterExpr;
// contains the filterexpressions that are valid before this op2
filterExprBeforeOpUnion = new ArrayList<Expr>(this.filterExpr);
// contains the filterexpressions that are valid after this op2
// this is needed because during the bottom-up-stepping all
// filterexpressions
// which could not be transformed down, must be inserted by means of an
// OpFilter
// above this op2
filterExprAfterOpUnion = new ArrayList<Expr>();
// check left subtree
if ((left = opUnion.getLeft()) != null) {
// calculate the set of filterexpressions that are also valid for
// the
// left subtree
this.filterExpr = calcValidFilterExpr(filterExprBeforeOpUnion, left);
filterExprAfterOpUnion.addAll(this.filterExpr);
// step down
opUnion.getLeft().visit(this);
left = stack.pop();
}
// check the right subtree
if ((right = opUnion.getRight()) != null) {
// calculate the set of filterexpressions that are also valid for
// the
// right subtree
this.filterExpr = calcValidFilterExpr(filterExprBeforeOpUnion,
right);
filterExprAfterOpUnion.addAll(this.filterExpr);
// step down
opUnion.getRight().visit(this);
right = stack.pop();
}
// note: filterExprAfterOpUnion contains now all filterexpressions which
// could
// be moved down
// now calculate all filterexpressions which were not moveable
notMoveableFilterExpr = new ArrayList<Expr>(filterExprBeforeOpUnion);
notMoveableFilterExpr.removeAll(filterExprAfterOpUnion);
// if there are some filterexpressions which could not be moved down,
// an opFilter must be inserted that contains this filterexpressions
if (!notMoveableFilterExpr.isEmpty()) {
// create the filter
newOp = OpFilter.filter(OpUnion.create(left, right));
// add the conditions
((OpFilter) newOp).getExprs().getList()
.addAll(notMoveableFilterExpr);
} else {
newOp = opUnion;
}
// restore filterexpressions
this.filterExpr = filterExprBeforeOpUnion;
this.stack.push(newOp);
}
示例5: checkMoveDownFilterExprAndVisitOpJoin
import com.hp.hpl.jena.sparql.algebra.op.OpFilter; //导入方法依赖的package包/类
/**
* Checks first if a filterexpression can be moved down. And after visits
* the operator
*/
private void checkMoveDownFilterExprAndVisitOpJoin(OpJoin opJoin) {
Op left = null;
Op right = null;
Op newOp;
List<Expr> filterExprBeforeOpJoin, filterExprAfterOpJoin, notMoveableFilterExpr;
// contains the filterexpressions that are valid before this op2
filterExprBeforeOpJoin = new ArrayList<Expr>(this.filterExpr);
// contains the filterexpressions that are valid after this op2
// this is needed because during the bottom-up-stepping all
// filterexpressions
// which could not be transformed down, must be inserted by means of an
// OpFilter
// above this op2
filterExprAfterOpJoin = new ArrayList<Expr>();
// check left subtree
if ((left = opJoin.getLeft()) != null) {
// calculate the set of filterexpressions that are also valid for
// the
// left subtree
this.filterExpr = calcValidFilterExpr(filterExprBeforeOpJoin, left);
filterExprAfterOpJoin.addAll(this.filterExpr);
// step down
opJoin.getLeft().visit(this);
left = stack.pop();
}
// check the right subtree
if ((right = opJoin.getRight()) != null) {
// calculate the set of filterexpressions that are also valid for
// the
// right subtree
this.filterExpr = calcValidFilterExpr(filterExprBeforeOpJoin, right);
filterExprAfterOpJoin.addAll(this.filterExpr);
// step down
opJoin.getRight().visit(this);
right = stack.pop();
}
// note: filterExprAfterOpUnion contains now all filterexpressions which
// could
// be moved down
// now calculate all filterexpressions which were not moveable
notMoveableFilterExpr = new ArrayList<Expr>(filterExprBeforeOpJoin);
notMoveableFilterExpr.removeAll(filterExprAfterOpJoin);
// if there are some filterexpressions which could not be moved down,
// an opFilter must be inserted that contains this filterexpressions
if (!notMoveableFilterExpr.isEmpty()) {
// create the filter
newOp = OpFilter.filter(OpJoin.create(left, right));
// add the conditions
((OpFilter) newOp).getExprs().getList()
.addAll(notMoveableFilterExpr);
} else {
// nothing must be done
newOp = opJoin;
}
// restore filterexpressions
this.filterExpr = filterExprBeforeOpJoin;
this.stack.push(newOp);
}
示例6: checkMoveDownFilterExprAndVisitOpDiff
import com.hp.hpl.jena.sparql.algebra.op.OpFilter; //导入方法依赖的package包/类
/**
* Checks first if a filterexpression can be moved down. And after visits
* the operator
*/
private void checkMoveDownFilterExprAndVisitOpDiff(Op2 opDiff) {
Op left = null;
Op right = null;
Op newOp;
List<Expr> filterExprBeforeOpUnionOpJoin, filterExprAfterOpUnionOpJoin, notMoveableFilterExpr;
// contains the filterexpressions that are valid before this op2
filterExprBeforeOpUnionOpJoin = new ArrayList<Expr>(this.filterExpr);
// contains the filterexpressions that are valid after this op2
// this is needed because during the bottom-up-stepping all
// filterexpressions
// which could not be transformed down, must be inserted by means of an
// OpFilter
// above this op2
filterExprAfterOpUnionOpJoin = new ArrayList<Expr>();
// check left subtree
if ((left = opDiff.getLeft()) != null) {
// calculate the set of filterexpressions that are also valid for
// the
// left subtree
this.filterExpr = calcValidFilterExpr(
filterExprBeforeOpUnionOpJoin, left);
filterExprAfterOpUnionOpJoin.addAll(this.filterExpr);
// step down
opDiff.getLeft().visit(this);
left = stack.pop();
}
// check the right subtree
if ((right = opDiff.getRight()) != null) {
// calculate the set of filterexpressions that are also valid for
// the
// right subtree
this.filterExpr = calcValidFilterExpr(
filterExprBeforeOpUnionOpJoin, right);
filterExprAfterOpUnionOpJoin.addAll(this.filterExpr);
// step down
opDiff.getRight().visit(this);
right = stack.pop();
}
// note: filterExprAfterOpUnion contains now all filterexpressions which
// could
// be moved down
// now calculate all filterexpressions which were not moveable
notMoveableFilterExpr = new ArrayList<Expr>(
filterExprBeforeOpUnionOpJoin);
notMoveableFilterExpr.removeAll(filterExprAfterOpUnionOpJoin);
// if there are some filterexpressions which could not be moved down,
// an opFilter must be inserted that contains this filterexpressions
if (!notMoveableFilterExpr.isEmpty()) {
// create the filter
newOp = OpFilter.filter(OpDiff.create(left, right));
// add the conditions
((OpFilter) newOp).getExprs().getList()
.addAll(notMoveableFilterExpr);
} else {
// nothing must be done
newOp = opDiff;
}
// restore filterexpressions
this.filterExpr = filterExprBeforeOpUnionOpJoin;
this.stack.push(newOp);
}
示例7: getQueryOp
import com.hp.hpl.jena.sparql.algebra.op.OpFilter; //导入方法依赖的package包/类
protected Op getQueryOp() {
Var sourceVar = Var.alloc("source");
Expr sourceExpr = new ExprVar(sourceVar);
Var targetVar = Var.alloc("target");
Expr targetExpr = new ExprVar(targetVar);
// FILTER (STR(?p1) < STR(?p2))
Expr filter = new E_LessThan(new E_Str(sourceExpr), new E_Str(
targetExpr));
Op op = OpFilter.filter(filter, new OpBGP(this.getCacheQueryPattern()));
return op;
}
示例8: getInnerQueryOp
import com.hp.hpl.jena.sparql.algebra.op.OpFilter; //导入方法依赖的package包/类
protected Op getInnerQueryOp() {
int rank = this.getPropertyPath().size() - 1;
Node rdfType = RDF.type.asNode();
Var memberVar = Var.alloc("member");
Expr memberExpr = new ExprVar(memberVar);
List<Var> intermediateVars = new ArrayList<Var>(rank);
List<Expr> intermediateExprs = new ArrayList<Expr>(rank);
for (int i = 0; i < rank; i++) {
intermediateVars.add(Var.alloc("intermediatevar" + i));
intermediateExprs.add(new ExprVar(intermediateVars.get(i)));
}
Var targetVar = Var.alloc("target");
// compile basic patterns
BasicPattern bp = new BasicPattern();
// ?p1 rdf:type core:Project.
bp.add(Triple.create(memberVar, rdfType, this.getTopic().asNode()));
// ?p2 rdf:type core:Project.
bp.add(Triple.create(targetVar, rdfType, this.getTopic().asNode()));
// FILTER (iv(i) != source)
List<Expr> intermediateFilters = new ArrayList<Expr>(rank);
for (int i = 0; i < rank; i++) {
intermediateFilters.add(new E_NotEquals(intermediateExprs.get(i),
memberExpr));
}
if (rank == 0) {
// ?source <prop(0)> ?target.
bp.add(Triple.create(memberVar, this.getPropertyPath().get(0)
.asNode(), targetVar));
} else {
// ?source <prop0> ?iv0
bp.add(Triple.create(memberVar, this.getPropertyPath().get(0)
.asNode(), intermediateVars.get(0)));
for (int i = 0; i < (rank - 1); i++) {
// ?ivs(i) <prop(i+1)> ?ivs(i+1)
bp.add(Triple.create(intermediateVars.get(i), this
.getPropertyPath().get(i + 1).asNode(),
intermediateVars.get(i + 1)));
}
// ?iv(rank) <prop(rank+1)> ?target.
bp.add(Triple.create(intermediateVars.get(rank - 1), this
.getPropertyPath().get(rank).asNode(), targetVar));
}
Op op = new OpBGP(bp);
for (Expr f : intermediateFilters) {
op = OpFilter.filter(f, op);
}
return op;
}
示例9: compileElementExists
import com.hp.hpl.jena.sparql.algebra.op.OpFilter; //导入方法依赖的package包/类
private Op compileElementExists(Op current, ElementExists elt2) {
Op op = compile(elt2.getElement()); // "compile", not "compileElement" -- do simpliifcation
Expr expr = new E_Exists(elt2, op);
return OpFilter.filter(expr, current);
}
示例10: compileElementNotExists
import com.hp.hpl.jena.sparql.algebra.op.OpFilter; //导入方法依赖的package包/类
private Op compileElementNotExists(Op current, ElementNotExists elt2) {
Op op = compile(elt2.getElement()); // "compile", not "compileElement" -- do simpliifcation
Expr expr = new E_Exists(elt2, op);
expr = new E_LogicalNot(expr);
return OpFilter.filter(expr, current);
}
示例11: applyConstraint
import com.hp.hpl.jena.sparql.algebra.op.OpFilter; //导入方法依赖的package包/类
@Override
public Op applyConstraint(Op op, Var reason) {
logger.debug("Applying constraint with value='" + this.getValue() + "' and expression=" + this.getExpression());
if (value == null || value.isEmpty()) {
return op;
}
Node rdfsLabel = RDFS.label.asNode();
Var reasonLabel = Var.alloc("reasonlabel");
Expr reasonLabelExpr = new ExprVar(reasonLabel);
Expr reasonExpr = new ExprVar(reason);
// create Triple
BasicPattern optionalPattern = new BasicPattern();
// ?source rdfs:label ?sourcelabel.
optionalPattern
.add(Triple.create(reason, rdfsLabel, reasonLabel));
op = OpLeftJoin.create(op, new OpBGP(optionalPattern),new ExprList());
Expr filter = new E_Conditional(
new E_IsIRI(reasonExpr),
reasonLabelExpr,
reasonExpr);
filter = this.getExpression().getFilter(filter, value);
if (filter == null) {
return op;
}
return OpFilter.filter(filter, op);
}