-1

我是语义网络主题的新手,我创建了一个本体,我需要开发一个网站,该网站可以读取本体并从 OWL 文件中提取信息并将其显示在网站上我对我需要哪个库进行了一些研究使用,所以我发现最好的库中的 RDFdotnet 我需要用它来读取 owl 文件,我还找到了一个代码,但我需要有人解释或帮助我使用这个代码来读取我的 owl 文件。我想使用下拉列表和按钮请任何建议???

这是代码

//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);
}
4

1 回答 1

3

对于您的 ASP.NET 应用程序,您可能需要一个比 dotNetRDF 生成的 RDF 图更抽象的模型。当您解析 OWL 文件时,您会得到一个包含三元组集合的图形,但对于您的应用程序,您可能需要更像是一个列表或对象字典,代表您正在显示的本体的位。

在 dotNetRDF API 中有多种方法可以从图中读取三元组,您可以使用这些方法来查找 OWL 类及其属性。有关使用 IGraph 界面的更多信息,请参阅https://bitbucket.org/dotnetrdf/dotnetrdf/wiki/UserGuide/Working%20with%20Graphs 。或者,您可以使用 SPARQL 查询从图中提取信息(请参阅https://bitbucket.org/dotnetrdf/dotnetrdf/wiki/UserGuide/Querying%20with%20SPARQL)。

因此,总而言之,dotNetRDF 提供了将您的 OWL 文件解析为图形然后查询或导航该图形以从中提取信息的工具。从那里我认为完全取决于您如何根据您的应用程序需求为您的应用程序构建模型。

于 2016-08-09T15:59:03.680 回答