嗨我參考http://www.dotnetrdf.org/content.asp?pageID=Querying%20with%20SPARQL, 上的材料,我需要一種方法來使用SPARQL讀取RDF文件的內容。使用SPARQL查詢RDF
如何爲現有的RDF文件設置路徑?
非常感謝,
嗨我參考http://www.dotnetrdf.org/content.asp?pageID=Querying%20with%20SPARQL, 上的材料,我需要一種方法來使用SPARQL讀取RDF文件的內容。使用SPARQL查詢RDF
如何爲現有的RDF文件設置路徑?
非常感謝,
由於@cygri指出你應該看看Reading RDF文檔。
下面是從Querying with SPARQL網頁,其中顯示加載文件查詢第一個例子:
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());
}
}
}
非常感謝RobV – DafaDil