Finished context matching via filter.
@@ -137,20 +137,19 @@ public class SparqlMatcherActor extends UntypedActor {
return OpExtend.create(OpLeftJoin.create(op, new OpTriple(matchTriple), filter), variableAssignment);
}
- public Op hasOverlappingContext(Op op, Var variable, List<Node> contexts) {
- Var tmpVar = Var.alloc(hashFunction(variable));
+ public Op hasOverlappingContext(Op op, Set<String> contexts) {
+ Var tmpVar = Var.alloc("overlappingContext");
if(contexts.isEmpty()) {
- return OpExtend.create(op, new VarExprList(variable, new NodeValueBoolean(false)));
+ return op;
}
- List<Expr> contextExpressions = contexts.stream().map(NodeValueNode::new).collect(Collectors.toList());
+ List<Expr> contextExpressions = contexts.stream().map(NodeValueString::new).collect(Collectors.toList());
Triple matchTriple = new Triple(resultName.asNode(), NodeFactory.createURI("http://purl.org/webofneeds/model#hasMatchingContext"), tmpVar);
- ExprList filter = new ExprList(new E_OneOf(new ExprVar(tmpVar), new ExprList(contextExpressions));
- VarExprList variableAssignment = new VarExprList(variable, new E_Bound(new ExprVar(tmpVar)));
+ ExprList filter = new ExprList(new E_OneOf(new ExprVar(tmpVar), new ExprList(contextExpressions)));
- return null;
+ return OpFilter.filter(filter, OpJoin.create(op, new OpTriple(matchTriple)));
}
@@ -279,6 +278,9 @@ public class SparqlMatcherActor extends UntypedActor {
queries.add(createSearchQuery(searchString));
}
+ Set<String> contexts = model.listObjectsOfProperty(model.createResource(needURI),
+ model.createProperty("http://purl.org/webofneeds/model#hasMatchingContext")).toList().stream().map(rdfNode -> rdfNode.asLiteral().getString()).collect(Collectors.toSet());
+
queries.stream().reduce((left, right) -> new OpUnion(left, right))
.ifPresent((union) -> {
BasicPattern nodeUriBGP = new BasicPattern();
@@ -289,14 +291,15 @@ public class SparqlMatcherActor extends UntypedActor {
new OpDistinct(
new OpProject(
relevantTimeFilter(
+ hasOverlappingContext(
createHintQuery(
OpJoin.create(
new OpBGP(nodeUriBGP),
union),
need.hasFlag(WON.NO_HINT_FOR_ME),
need.hasFlag(WON.NO_HINT_FOR_COUNTERPART)
- )
- ),
+ ), contexts
+ )),
Arrays.asList(new Var[]{resultName, wonNodeVar, hint1, hint2})
)
),
