LinqToRdf – SPARQL Query Generation

Progress with the LINQ to RDF Query Provider is continuing apace. I have been pretty tightly focused for the last few days, so I haven’t ad time to post an update. I’ve lately been working on a SPARQL query, which will allow me a much richer palette to play with. Here’s the current version of the LINQ query I’m using to test the RdfSparqlQuery class.

public void SparqlQuery()
    string urlToRemoteSparqlEndpoint = @http://someUri;
    TripleStore ts = new TripleStore();
    ts.EndpointUri = urlToRemoteSparqlEndpoint;
    ts.QueryType = QueryType.RemoteSparqlStore;
    IRdfQuery<Track> qry = new RDF(ts).ForType<Track>(); 
    var q = from t in qry
        where t.Year == 2006 &&
        t.GenreName == "History 5 | Fall 2006 | UC Berkeley" 
        select new {t.Title, t.FileLocation};
    foreach(var track in q){
        Trace.WriteLine(track.Title + ": " + track.FileLocation);

And here’s what it’s producing as output:

@prefix a: <> .

SELECT ?Title, ?FileLocation
?Track <> ?Title .
?Track <> ?ArtistName .
?Track <> ?AlbumName .
?Track <> ?Year .
?Track <> ?GenreName .
?Track <> ?Comment .
?Track <> ?FileLocation .
?Track <> ?Rating .
    ((t.Year)=(2006^^xsdt:int))&&((t.GenreName)=(“History 5 | Fall 2006 | UC Berkeley”^^xsdt:string))

as you can see, the query is fairly close. I just have to:

  • Convert the property names in the filters to use the free variable name chosen for the object of a property assertion.
  • Restrict the variables enumerated in the graph definition to just those required for the projection (if there is a projection)
  • Use the UNION operator to allow disjunctions (OrElse expression types)
  • Add the XSDT (XML Schema Datatypes) namespace to the prefixes
  • Use standard SPARQL variable syntax for the ?Track

I also need to find a fast back-end SPARQL enabled triple store that I can start to run these queries against. A month or two ago I did a .NET conversion of Jena using IKVM. I may end up going back to that. Any other suggestions would be welcome.

If you want to have a play with it, or take a look at how to produce a LINQ Query provider, then you can use Subversion to get the code from Google. Use the command below:

svn checkout linqtordf


Comments are closed.

Create a website or blog at

Up ↑

%d bloggers like this: