Skip to content

Graph and Triple Manipulation

Andrew Matthews edited this page Oct 1, 2025 · 1 revision

In Embedding SPARQL Queries I touch on the composition of graphs as sources for comprehensions. It makes it clear that construction and manipulation of RDF graphs, queries and triples is a vital syntactic component that can greatly add to the ease of working with RDF.

Here's an example:

rq1: query = <<{some query}>>;
rq2: query = <<{some other query}>>;

g1: graph = . . . ;
g2: graph = . . . ;
g3: graph = rq1 <- g1;
g4: graph = rq2 <- g2;
g5: graph = g3 + g4;

The clean format makes it easier to read and understand the code, and that's the point of all this syntactic sugar. So, the question is - how much language built-in support should there be for composition and manipulation of graphs, triples, stores, IRIs etc?

Here's a few random ideas:

t1: triple = <a:x, b:y, c:z>;   // construct a single triple
t2: triple = <a:m, b:n, c:o>;
g1: graph = t1+t2;              // construct a graph from one or more triples
ts: [triple] = [<a:q, b:e, i> from i in range(0, 20)];  // construct a list of triples, using C# variable
g2: graph = g1 + ts;            // add a list of triples to a graph
g3: graph = g2 - t1;            // remove triples from a graph (same as 'retract'?)
g4: graph = g3 - g1;            // remove all triples in g3 that are also in g1
g5: graph = store - g4;         // same, only for whole graph of a remote store
ts2: [triple] = g6;             // implicit cast of a graph into list of triples
ts3: [triple] = rq1 <- store;   // and implicit conversion in the other direction too

Implementation

Presumably this can all be achieved through the construction of a set of graph manipulation primitives (in the class KG) that can be bound to and lowered-from the arithmentic operators shown above. That is, g1 + g2 would be lowered to a call to KG.Merge(g1, g2).

Clone this wiki locally