Search in sources :

Example 1 with OpTriple

use of org.apache.jena.sparql.algebra.op.OpTriple in project webofneeds by researchstudio-sat.

the class SparqlMatcherUtils method createSearchQuery.

public static Op createSearchQuery(String searchString, Var resultName, int hops, boolean disjunctive, boolean tokenize) {
    Var textSearchTarget = Var.alloc("textSearchTarget");
    Optional<Op> union = IntStream.range(1, hops + 1).mapToObj(hopCount -> makePathBGPPattern(resultName, textSearchTarget, hopCount, op -> {
        Expr filterExpression = Arrays.stream(tokenize ? searchString.toLowerCase().split(" ") : new String[] { searchString.toLowerCase() }).<Expr>map(searchPart -> new E_StrContains(new E_StrLowerCase(new ExprVar(textSearchTarget)), new NodeValueString(searchPart))).reduce((left, right) -> disjunctive ? new E_LogicalOr(left, right) : new E_LogicalAnd(left, right)).orElse(new NodeValueBoolean(true));
        return OpFilter.filterBy(new ExprList(filterExpression), op);
    })).reduce((op1, op2) -> new OpUnion(op1, op2));
    Op maintriple = new OpTriple(new Triple(resultName, RDF.type.asNode(), WON.Atom.asNode()));
    Op mainOp = union.isPresent() ? OpJoin.create(maintriple, union.get()) : maintriple;
    return mainOp;
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) Transformer(org.apache.jena.sparql.algebra.Transformer) RDF(org.apache.jena.vocabulary.RDF) ResourceImpl(org.apache.jena.rdf.model.impl.ResourceImpl) OpModifier(org.apache.jena.sparql.algebra.op.OpModifier) OpVisitorBase(org.apache.jena.sparql.algebra.OpVisitorBase) BasicPattern(org.apache.jena.sparql.core.BasicPattern) ExprList(org.apache.jena.sparql.expr.ExprList) Random(java.util.Random) OpGraph(org.apache.jena.sparql.algebra.op.OpGraph) OpJoin(org.apache.jena.sparql.algebra.op.OpJoin) OpProject(org.apache.jena.sparql.algebra.op.OpProject) Walker(org.apache.jena.sparql.algebra.walker.Walker) OpUnion(org.apache.jena.sparql.algebra.op.OpUnion) Function(java.util.function.Function) OpDistinct(org.apache.jena.sparql.algebra.op.OpDistinct) OpService(org.apache.jena.sparql.algebra.op.OpService) OpConditional(org.apache.jena.sparql.algebra.op.OpConditional) E_LogicalOr(org.apache.jena.sparql.expr.E_LogicalOr) OpList(org.apache.jena.sparql.algebra.op.OpList) Op(org.apache.jena.sparql.algebra.Op) TransformCopy(org.apache.jena.sparql.algebra.TransformCopy) E_StrLowerCase(org.apache.jena.sparql.expr.E_StrLowerCase) ExprVar(org.apache.jena.sparql.expr.ExprVar) WONMATCH(won.protocol.vocabulary.WONMATCH) WON(won.protocol.vocabulary.WON) OpLeftJoin(org.apache.jena.sparql.algebra.op.OpLeftJoin) Op2(org.apache.jena.sparql.algebra.op.Op2) NodeValueString(org.apache.jena.sparql.expr.nodevalue.NodeValueString) Triple(org.apache.jena.graph.Triple) Expr(org.apache.jena.sparql.expr.Expr) E_NotExists(org.apache.jena.sparql.expr.E_NotExists) OpVisitorByTypeBase(org.apache.jena.sparql.algebra.OpVisitorByTypeBase) OpSlice(org.apache.jena.sparql.algebra.op.OpSlice) Var(org.apache.jena.sparql.core.Var) OpBGP(org.apache.jena.sparql.algebra.op.OpBGP) E_LogicalAnd(org.apache.jena.sparql.expr.E_LogicalAnd) NodeValueBoolean(org.apache.jena.sparql.expr.nodevalue.NodeValueBoolean) OpTriple(org.apache.jena.sparql.algebra.op.OpTriple) OpMinus(org.apache.jena.sparql.algebra.op.OpMinus) Optional(java.util.Optional) OpOrder(org.apache.jena.sparql.algebra.op.OpOrder) E_StrContains(org.apache.jena.sparql.expr.E_StrContains) OpFilter(org.apache.jena.sparql.algebra.op.OpFilter) OpReduced(org.apache.jena.sparql.algebra.op.OpReduced) ExprVar(org.apache.jena.sparql.expr.ExprVar) Op(org.apache.jena.sparql.algebra.Op) OpUnion(org.apache.jena.sparql.algebra.op.OpUnion) ExprVar(org.apache.jena.sparql.expr.ExprVar) Var(org.apache.jena.sparql.core.Var) NodeValueString(org.apache.jena.sparql.expr.nodevalue.NodeValueString) Triple(org.apache.jena.graph.Triple) OpTriple(org.apache.jena.sparql.algebra.op.OpTriple) E_LogicalAnd(org.apache.jena.sparql.expr.E_LogicalAnd) NodeValueBoolean(org.apache.jena.sparql.expr.nodevalue.NodeValueBoolean) Expr(org.apache.jena.sparql.expr.Expr) ExprList(org.apache.jena.sparql.expr.ExprList) E_StrLowerCase(org.apache.jena.sparql.expr.E_StrLowerCase) E_LogicalOr(org.apache.jena.sparql.expr.E_LogicalOr) OpTriple(org.apache.jena.sparql.algebra.op.OpTriple) E_StrContains(org.apache.jena.sparql.expr.E_StrContains)

Aggregations

Arrays (java.util.Arrays)1 Optional (java.util.Optional)1 Random (java.util.Random)1 Function (java.util.function.Function)1 IntStream (java.util.stream.IntStream)1 Triple (org.apache.jena.graph.Triple)1 ResourceImpl (org.apache.jena.rdf.model.impl.ResourceImpl)1 Op (org.apache.jena.sparql.algebra.Op)1 OpVisitorBase (org.apache.jena.sparql.algebra.OpVisitorBase)1 OpVisitorByTypeBase (org.apache.jena.sparql.algebra.OpVisitorByTypeBase)1 TransformCopy (org.apache.jena.sparql.algebra.TransformCopy)1 Transformer (org.apache.jena.sparql.algebra.Transformer)1 Op2 (org.apache.jena.sparql.algebra.op.Op2)1 OpBGP (org.apache.jena.sparql.algebra.op.OpBGP)1 OpConditional (org.apache.jena.sparql.algebra.op.OpConditional)1 OpDistinct (org.apache.jena.sparql.algebra.op.OpDistinct)1 OpFilter (org.apache.jena.sparql.algebra.op.OpFilter)1 OpGraph (org.apache.jena.sparql.algebra.op.OpGraph)1 OpJoin (org.apache.jena.sparql.algebra.op.OpJoin)1 OpLeftJoin (org.apache.jena.sparql.algebra.op.OpLeftJoin)1