EditIntroduction
LINQ to RDF project (or LinqToRdf for short) started in May 2007, and is led by Andrew Matthews. It is now in beta, supporting query facilities and insertion of objects for in-memory triple stores. The roadmap includes full CRUD behaviour and remote query support using the SPARQL query language. The purpose of the project is to make it easy for .NET developers to query classes that have been defined using either RDFS (RDF Schema) or OWL (Web Ontology Language). These standards were produced by the W3C and form the foundation of the W3Cs vision of the
semantic web. Currently there is little or no support (or interest) within the .NET community for the semantic web. It is hoped that with full LINQ support for RDF, the semantic web will gather more interest from those who are unfamiliar with these emerging technologies. the project includes visual studio extensions that allow the visual modeling of ontologies using the familiar experience of the VS.NET class designer.
The system is tested against both in-memory triple stores and remote triple stores using the SPARQL query language and transport protocol. LinqToRdf has been tested on both the
Joseki and the OpenLink
Virtuoso platforms.
EditMore Information
The project is hosted on the
google code web site, where SVN access will allow code to be downloaded. The current featured release is
LinqToRdf 0.6. The code targets VS.NET 2008 with .NET 3.5. In addition to the basic runtime query provider, the project also provides a VS.NET 2008 Domain Specific Language (DSL) extension called LinqToRdf Designer (which is now included in the main LinqToRdf installer. The designer allows visual modeling of ontologies, and supports both the production of RDF files (using N3 notation) and C# files for the .NET domain model. the DSL setup file also provides project and item templates to make getting up to speed on LinqToRdf easier.
You can find more information about the design and genesis of LinqToRdf on Andrew Matthews' blog, with posts related to
LINQ and
Semantic Web.
EditCode Sample
This is an example of the type of queries that are currently supported. Where, Select, Distinct, Take, Skip etc are supported. This works on the assumption (like LINQ to SQL) that entity classes and their properties are annotated with Attributes that give the RDF URIs of the class definition in an ontology. See Andrew Matthews' blog for more details.
[Test]
public void SparqlQueryWithTheLot()
{
var ctx = new MusicDataContext("http://musicdb.com/SparqlQuery.aspx");
var q = (from t in qry
where t.Year == "2006" &&
t.GenreName == "History 5 | Fall 2006 | UC Berkeley"
orderby t.FileLocation
select new
{
t.Title,
t.FileLocation
})
.Skip(10)
.Take(5);
foreach (var track in q)
{
Console.WriteLine(track.Title + ": " + track.FileLocation);
}
}
Here's a typical example of a domain class that has been annotated for using in LinqToRdf
[OwlResource(OntologyName = "Tasks", RelativeUriReference = "Project")]
public class Project : OwlInstanceSupertype
{
[OwlResource(OntologyName = "Tasks", RelativeUriReference = "name")]
public string Name { get; set; }
[OwlResource(OntologyName = "Tasks", RelativeUriReference = "hasTask")]
public EntitySet<Task> Tasks { get; set; }
[OwlResource(OntologyName = "Tasks", RelativeUriReference = "usesResource")]
public EntitySet<ProjectResource> ResourcesUsed { get; set; }
}
There are two kinds of attributes needed - An OwlOntologyAttribute and an OwlResourceAttribute, which you can see being used above. The OwlOntologyAttrinbute is used like this:
[assembly: Ontology(
BaseUri = "http://musicdb.com/ontologies/2007/04/music#",
Name = "Music",
Prefix = "music",
UrlOfOntology = "http://musicdb.com/ontologies/2007/04/music/music.n3")]
Because of the simplicity of RDF itself, we don't need great complexity in referring to elements in the model. In RDF everything is a resource. Likewise, in LinqToRdf everything gets annotated by a resource.
EditResources