1

Hi I am referencing the material on http://www.dotnetrdf.org/content.asp?pageID=Querying%20with%20SPARQL, and I need a way to read the content of an RDF file using SPARQL.

How can I set the path for an exsiting RDF file?

Many Thanks,

4

2 回答 2

4

As @cygri notes you should look at the Reading RDF documentation.

Here is the first example from the Querying with SPARQL page which shows loading a file to query:

using System;
using VDS.RDF;
using VDS.RDF.Parsing;
using VDS.RDF.Query;

public class InMemoryTripleStoreExample
{
    public static void Main(String[] args)
    {
        TripleStore store = new TripleStore();

        //Load data from a file
        store.LoadFromFile("example.rdf");

        //Execute a raw SPARQL Query
        //Should get a SparqlResultSet back from a SELECT query
        Object results = store.ExecuteQuery("SELECT * WHERE {?s ?p ?o}");
        if (results is SparqlResultSet)
        {
            //Print out the Results
            SparqlResultSet rset = (SparqlResultSet)results;
            foreach (SparqlResult result in rset)
            {
                Console.WriteLine(result.ToString());
            }
        }

        //Use the SparqlQueryParser to give us a SparqlQuery object
        //Should get a Graph back from a CONSTRUCT query
        SparqlQueryParser sparqlparser = new SparqlQueryParser();
        SparqlQuery query = sparqlparser.ParseFromString("CONSTRUCT { ?s ?p ?o } WHERE {?s ?p ?o}");
        results = store.ExecuteQuery(query);
        if (results is IGraph)
        {
            //Print out the Results
            IGraph g = (IGraph)results;
            foreach (Triple t in g.Triples)
            {
                Console.WriteLine(t.ToString());
            }
            Console.WriteLine("Query took " + query.QueryExecutionTime.ToString());
        }
    }
}
于 2012-09-12T19:50:20.530 回答
3

Answer is probably here: Reading RDF

于 2012-09-11T18:13:26.963 回答