views:

386

answers:

4

What is an effective means of implementing an in memory semantic web triple store using the basic .NET collection classes using F#?

Are there any F# examples or projects already doing this?

A: 

I know this doesn't directly answer your question, but you could use 4store which is a stable, proven triplestore, and write a client for it in .Net, instead of developing your own triplestore.

Related questions

Mauricio Scheffer
+1  A: 

Intellidimension offers a .NET based in-memory triple store as part of their Semantics SDK. They often provide free licenses for research/education if you contact them.

I use their technology every single day from C# and PowerShell though and I really enjoy it.

//disclaimer: really the first time I have used F# so this may not be any good...
//but it does work

open Intellidimension.Rdf
open System.IO

let rdfXml = File.ReadAllText(@"C:\ontology.owl")
let gds = new GraphDataSource()
gds.Read(rdfXml) |> ignore
let tbl = gds.Query("select ?s ?p ?o where {?s ?p ?o} limit 10")

System.Console.Write(tbl.RowCount)
System.Console.ReadLine() |> ignore
spoon16
+1  A: 

There is also SemWeb which is a C# library which provides it's own SQL based Triple Store - http://razor.occams.info/code/semweb/

I'm working on a new C# library for RDF called dotNetRDF and have just released the latest Alpha http://www.dotnetrdf.org.

Here's an equivalent program to the one spoon16 showed:

open System
open VDS.RDF
open VDS.RDF.Parsing
open VDS.RDF.Query

//Get a Graph and fill it from a file
let g = new Graph()
let parser = new TurtleParser()
parser.Load(g, "test.ttl")

//Place into a Triple Store and query
let store = new TripleStore()
store.Load(g)
let results = store.ExecuteQuery("SELECT ?s ?p ?o WHERE {?s ?p ?o} LIMIT 10") :?> SparqlResultSet

//Output the results
Console.WriteLine(results.Count.ToString() ^ " Results")
for result in results.Results do
  Console.WriteLine(result.ToString())
done

//Wait for user to hit enter so they can see the results
Console.ReadLine() |> ignore

My library currently supports my own SQL databases, AllegroGraph, 4store, Joseki, Sesame, Talis and Virtuoso as backing stores

RobV
+1  A: 

Check out LinqToRdf which, in addition to simple VS.NET hosted modeling tools, provides a full LINQ query provider and round-tripping data when dealing with in-memory databases:

var ctx = new MusicDataContext(@"http://localhost/linqtordf/SparqlQuery.aspx");
var q = (from t in ctx.Tracks
     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);
}
Andrew Matthews
PS: being .NET compatible it should work fine with F#...
Andrew Matthews