/// <summary> /// Converts a <see cref="GraphDiffReport">diff</see> to an equivalent <see cref="ModifyCommand">SPARQL Update INSERT/DELETE command</see>. /// </summary> /// <param name="diff">The <see cref="GraphDiffReport">diff</see> to convert.</param> /// <param name="graphUri">Optional <see cref="Uri">URI</see> of the affected graph.</param> /// <param name="prefixes">Optional <see cref="INamespaceMapper">mapper</see> used to resolve prefixes.</param> /// <returns>A <see cref="ModifyCommand">SPARQL Update INSERT/DELETE command</see> that represents the <see cref="GraphDiffReport">diff</see>.</returns> public static ModifyCommand AsUpdate(this GraphDiffReport diff, Uri graphUri = null, INamespaceMapper prefixes = null) { var delete = new GraphPatternBuilder(); var insert = new GraphPatternBuilder(); var where = new GraphPatternBuilder(); // Removed ground triples are added as is to both delete and where clauses foreach (var t in diff.RemovedTriples) { delete.AddTriplePattern(t); where.AddTriplePattern(t); } foreach (var g in diff.RemovedMSGs) { // Blank nodes in removed non-ground triples are converted to variables and added to both delete and where clauses foreach (var t in g.Triples) { delete.AddVariablePattern(t); where.AddVariablePattern(t); } // An ISBLANK filter is added for each blank node in removed non-ground triples foreach (var n in g.BlankNodes()) { where.AddBlankNodeFilter(n); } } // Added triples (ground or not) are added as is to the insert clause foreach (var t in diff.AllAddedTriples()) { insert.AddTriplePattern(t); } return(new ModifyCommand( delete.BuildGraphPattern(prefixes), insert.BuildGraphPattern(prefixes), where.BuildGraphPattern(prefixes), graphUri)); }
/// <summary> /// Converts a <see cref="GraphDiffReport">diff</see> to an equivalent <see cref="ModifyCommand">SPARQL Update query</see> /// </summary> /// <param name="diff">The <see cref="GraphDiffReport">diff</see> to convert</param> /// <returns>A <see cref="ModifyCommand">SPARQL Update query</see> that represents the <see cref="GraphDiffReport">diff</see></returns> internal static ModifyCommand AsUpdate(this GraphDiffReport diff) { var delete = new GraphPatternBuilder(); var insert = new GraphPatternBuilder(); var where = new GraphPatternBuilder(); // Groud removed triples are added as is to both delete and where clauses foreach (var t in diff.RemovedTriples) { delete.AddTriplePattern(t); where.AddTriplePattern(t); } foreach (var g in diff.RemovedMSGs) { // Blank nodes in non-ground removed triples are converted to variables and added to both delete and where clauses foreach (var t in g.Triples) { delete.AddVariablePattern(t); where.AddVariablePattern(t); } // An ISBLANK filter is added for each blank node in non-ground removed triples foreach (var n in g.BlankNodes()) { where.AddBlankNodeFilter(n); } } // Added triples (ground or not) are added as is to the insert clause foreach (var t in diff.AllAddedTriples()) { insert.AddTriplePattern(t); } return(new ModifyCommand( delete.BuildGraphPattern(), insert.BuildGraphPattern(), where.BuildGraphPattern())); }