Author Archive for donal

Querying Named Graphs in Construct (Some Examples)

The next release of Construct contains named graphs. These allow you to store information that describes your RDF statements. I’ll give a simple run through of how to query Construct using named graphs (if you want more detail check out the w3c recommendation ).

When querying named graphs in Construct using SPARQL and the QueryService you need to add the GRAPH keyword to pattern match against graphs in the dataset. Lets start with the easiest example, selecting all the graphs and all the statements…

  1. SELECT * WHERE { GRAPH ?graph { ?s ?p ?o } }

So now your resultset is going to be able to return four pieces of info for every statement.

Graphs in Construct probably don’t confer too much useful information on their own however, as they are just unique ids, created by the data store.

It is useful though to know what graph(s) a statement or set of statements appears in. You could use something like this…

  1. SELECT DISTINCT ?graph WHERE { GRAPH ?graph { <http://construct-infrastructure.org/subject> ?p ?o } }

Now you’ve got the graph(s) that your statement(s) appears in, suppose you wanted to find all the metadata associated with those statements. All you have to do is add the following query…

  1. SELECT ?p ?o FROM NAMED <$GRAPH_URI> WHERE { GRAPH ?graph { ?graph ?p ?o } }

where $GRAPH_URI corresponds to the name of the graph(s) returned by the previous query. Now you’ve got all the metadata associated with your statement(s). This is only a small example of what kind of SPARQL queries can get the most out of the new data storage technique - all that’s left is to have a go!