Search code examples
rdfsparqlsemanticsdotnetrdf

how to create and pass rdf graphs from memory to DOTNETRDF


If I have RDF Triples say that they are held in Redis as Hash Key where each triple is represented as Key : S:Value P:Value O:Value.

How to pass collection of such triples to the DOTNETRDF and represent them as graph so that I can run SPARQL Queries on them ?

I do understand that SPARQL Engine in DOTNETRDF can operate on stores only , but if I create a class that implement IGraph Interface , then its possible to run the SPARQL Queries on the triples


Solution

  • In fact I tried to implement the IGraph interface in way I defined a data structure for passing the triples , but it seems that the only way to apply sparql engine is by storing these triples in a triple store

    You can put any IGraph implementation in the standard TripleStore instance so implementing IGraph is sufficient to get you started. It is generally easiest to extend from BaseGraph if you aren't already as that will give you a lot of implementation for free.

    So yes you can run queries on an arbitrary IGraph implementation:

    IGraph g = new MyCustomGraph();
    TripleStore store = new TripleStore();
    store.Add(g);
    
    // Run query on the store as normal
    

    However if you want to integrate more deeply then you need to look at implementing the ISparqlDataset interface which is the actual interface used internally by the query engine (IGraph and ITripleStore end up wrapped inside this). Again there are base implementations like BaseDataset and BaseQuadDataset which will give you chunks of the implementation.

    You may want to look at the open source BrightstarDB for an existing example of another triple store that uses dotNetRDF's SPARQL engine