add query that deletes everything except the content graphs out of the conversation
package won.utils.goals;
-import org.apache.jena.query.Dataset;
-import org.apache.jena.query.DatasetFactory;
+import org.apache.jena.query.*;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Resource;
+import org.apache.jena.update.UpdateExecutionFactory;
+import org.apache.jena.update.UpdateFactory;
+import org.apache.jena.update.UpdateProcessor;
+import org.apache.jena.update.UpdateRequest;
import org.topbraid.shacl.validation.ValidationUtil;
import won.protocol.model.NeedGraphType;
import won.protocol.util.NeedModelWrapper;
@@ -24,7 +27,6 @@ public class GoalInstantiationProducer {
private Dataset need1;
private Dataset need2;
- private Dataset conversation;
private Model combinedModelWithoutGoals;
private String variableUriPrefix;
private String blendingUriPrefix;
@@ -42,7 +44,6 @@ public class GoalInstantiationProducer {
this.need1 = need1;
this.need2 = need2;
- this.conversation = conversation;
this.variableUriPrefix = variableUriPrefix;
this.blendingUriPrefix = blendingUriPrefix;
@@ -55,8 +56,17 @@ public class GoalInstantiationProducer {
Dataset combinedDataset = DatasetFactory.create();
combinedDataset.addNamedModel("need1", strippedNeed1);
combinedDataset.addNamedModel("need2", strippedNeed2);
- if(this.conversation != null){
- RdfUtils.addDatasetToDataset(combinedDataset, this.conversation, false);
+ if(conversation != null){
+ String sparqlQuery =
+ "PREFIX msg: <http://purl.org/webofneeds/message#> \n" +
+ "DELETE { GRAPH ?g { ?s ?p ?o } } where { { GRAPH ?g { ?s ?p ?o } GRAPH <urn:x-arq:UnionGraph> { ?msg msg:hasContent ?content } } filter (?g != ?content) }";
+
+ UpdateRequest update = UpdateFactory.create(sparqlQuery);
+
+ UpdateProcessor updateProcessor = UpdateExecutionFactory.create(update, conversation);
+ updateProcessor.execute();
+
+ RdfUtils.addDatasetToDataset(combinedDataset, conversation, false);
}
combinedModelWithoutGoals = RdfUtils.mergeAllDataToSingleModel(combinedDataset);
}
