views:

31

answers:

1

Is there any Library for .NET that returns SPARQL results in some structured List instead of standard XML format? I am using SemWeb. I could not find any such method.

+1  A: 

SemWeb does appear to provide the building blocks for what you want. Looking at the documentation it seems QueryResultSink is what you want. You could build a list of results using that, or work directly with the results as they arrive.

Alternatively try dotnetrdf. This introduction shows that queries result in a SparqlResultSet that you can iterate through.

From the examples:

TripleStore store = new TripleStore();
// ...data...
Object results = store.ExecuteQuery("SELECT * WHERE {?s ?p ?o}");
if (results is SparqlResultSet) {
    SparqlResultSet rset = (SparqlResultSet)results; 
    foreach (SparqlResult result in rset) { 
        Console.WriteLine(result.ToString());
    }
}
Yes with SemWeb you can write your own QueryResultSink implementation to get the results back in some other form if you want a list of results. If you use my dotNetRDF library as comment_bot suggests you get a SparqlResultSet which you can iterate through and you can index into each SparqlResult object using variable names or integer index
RobV
@RobV is there a way to remove language tags like @en and type tags like ^^http://www.w3.org/2001/XMLSchema#int. from results?Offcource I can manipulate strings but is there any way availabel in library?
Taz
If you know that a value for one variable is a LiteralNode (try using the `NodeType` property or doing `x is LiteralNode`) you can cast it to a LiteralNode and then use the `Value` property to just get the string value excluding the datatype/language tag
RobV