Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Scaffolding SPARQL query

Efimster edited this page May 5, 2014 · 19 revisions
  1. Create function for querying RDF source that takes query string and returns SPARQLQueryResults object.

Func <string, SPARQLQueryResults> queryingFunc;

see querying function details here
2. Create a dynamic object

dynamic dyno = DynamicSPARQL.CreateDyno(queryingFunc, [other parameters]);

see dynamic object creation topic here
3. Make a query

IEnumerable<dynamic> list = dyno.Select(
    prefixes: new[] { 
        SPARQL.Prefix("dc:", "http://purl.org/dc/elements/1.1/"),//prefix could be used with colon
        SPARQL.Prefix("ns", "http://example.org/ns#")//or without colon
    },
    projection: "?title ?price",
    where: SPARQL.Group(
                SPARQL.Triple("?x dc:title ?title"),
                SPARQL.Optional(
                    SPARQL.Triple("?x ns:price ?price"),
                    SPARQL.Filter("?price < 30"))
    )
);

see query patterns list [here] (https://github.com/Efimster/DynamicSPARQL/wiki/Query-patterns)
see more examples here

  1. Enumerate results:
    Assume projection: "?name ?surname ?age"
foreach(var obj in results)
{
   Console.WriteLine(string.Concat("Name:",obj.name,"; Surname:" obj.surname," ;Age:", obj.age));
}

Clone this wiki locally