2

我使用 dotNetRDF 库来编写 sparql 查询。我使用“http://dbpedia.org/sparql”作为 DBPedia SPARQL 端点和“http://dbpedia.org”作为默认图形 URI 定义远程端点:

 SparqlRemoteEndpoint endpoint = new SparqlRemoteEndpoint(new Uri("http://dbpedia.org/sparql"), "http://dbpedia.org");

这很好用 但是我需要使用我的 rdf 文件作为默认图形 URI“myuniversity.rdf” 我将它添加到网站 参数是什么而不是“http://dbpedia.org”?

你能帮我吗,我应该将它传递给构造函数来做到这一点的正确参数是什么?

4

1 回答 1

1

您显示的方法仅用于通过 HTTP 查询远程端点。

如果您只想查询本地文件,请使用以下内容:

//Define your Graph here - it may be better to use a QueryableGraph if you plan
//on making lots of Queries against this Graph as that is marginally more performant
IGraph g = new Graph();

//Load some data into your Graph using the LoadFromFile() extension method
g.LoadFromFile("myfile.rdf");

//Use the extension method ExecuteQuery() to make the query against the Graph
try
{
  Object results = g.ExecuteQuery("SELECT * WHERE { ?s a ?type }");
  if (results is SparqlResultSet)
  {
     //SELECT/ASK queries give a SparqlResultSet
     SparqlResultSet rset = (SparqlResultSet)results;
     foreach (SparqlResult r in rset)
     {
       //Do whatever you want with each Result
     }
  } 
  else if (results is IGraph)
  {
     //CONSTRUCT/DESCRIBE queries give a IGraph
     IGraph resGraph = (IGraph)results;
     foreach (Triple t in resGraph.Triples)
     {
        //Do whatever you want with each Triple
     }
  }
  else
  {
     //If you don't get a SparqlResutlSet or IGraph something went wrong 
     //but didn't throw an exception so you should handle it here
     Console.WriteLine("ERROR");
  }
}
catch (RdfQueryException queryEx)
{
   //There was an error executing the query so handle it here
   Console.WriteLine(queryEx.Message);
}

有关更多文档,请参阅使用 SPARQL 进行查询,其中涵盖了进行 SPARQL 查询的各种方式。

如果您有多个图表,那么您将需要使用 IInMemoryQueryableStore 或带有 ISparqlDataset 的 LeviathanQueryProcessor。

如果您遇到困难,您可以随时在邮件列表上寻求帮助 - dotNetRDF-support@lists.sourceforge.net

于 2011-04-14T09:59:18.360 回答