use of org.apache.jena.sparql.algebra.op.OpUnion in project webofneeds by researchstudio-sat.
the class SparqlMatcherActor method defaultQuery.
private Optional<Op> defaultQuery(AtomModelWrapper atom) {
Model model = atom.getAtomModel();
String atomURI = atom.getAtomUri();
ArrayList<Op> queries = new ArrayList<>(3);
Statement seeks = model.getProperty(model.createResource(atomURI), model.createProperty("https://w3id.org/won/matching#seeks"));
if (seeks != null) {
Op seeksQuery = createAtomQuery(model, seeks);
if (seeksQuery != null) {
queries.add(seeksQuery);
}
}
Statement search = model.getProperty(model.createResource(atomURI), model.createProperty("https://w3id.org/won/matching#searchString"));
if (search != null) {
String searchString = search.getString();
queries.add(SparqlMatcherUtils.createSearchQuery(searchString, resultName, 2, true, true));
}
return queries.stream().reduce((left, right) -> new OpUnion(left, right)).map((union) -> new OpDistinct(new OpProject(union, Arrays.asList(new Var[] { resultName }))));
}
use of org.apache.jena.sparql.algebra.op.OpUnion 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;
}
Aggregations