2012-12-27 39 views
0

我創建了一個使用protege的本體論。現在我想編寫一個代碼來使用dotNetRDF遍歷本體。通過橫向的平均值,顯示所有類別中,我使用下面的代碼的子類等使用dotnetrdf遍歷一個本體論

,但它給異常**

空間URI爲給定的前綴「貓頭鷹」不是已知所述 在範圍內NamespaceMapper

OntologyGraph g = new OntologyGraph(); 
     FileLoader.Load(g, "humanontordf.owl"); 

     OntologyClass classOfClasses = g.CreateOntologyClass(g.CreateUriNode("owl:Class")); 

     //This iterates over the things that are a class 
     foreach (OntologyResource r in classOfClasses.Instances) 
     { 
      //Do what you want with the class 
      Console.WriteLine(r.ToString()); 
     } 

此代碼是上給出的答案基herehttp://answers.semanticweb.com/questions/19984/dotnetrdf-list-all-ontology-classes

任何人都可以讓我知道我在上面的代碼中缺少什麼?任何有關dotNetRDF教程的好網址?

回答

2

該錯誤消息是指代碼的以下部分:

g.CreateUriNode("owl:Class") 

這使用一個前綴名作爲完整的URI的快捷方式,需要在圖形中要定義的owl前綴。

如果您收到這則您的RDF文件不包括這一點,你可以像這樣定義的:

g.NamespaceMap.AddNamespace("prefix", new Uri("http://some/namespace/")); 

我想一個OntologyGraph真的應該自動定義OWL的名稱,我會在添加此下一個版本。

+1

添加提交https://bitbucket.org/dotnetrdf/dotnetrdf/commits/d87aeb97f5df63c78bfcbe3f32a920d0b06da492 – RobV

+0

感謝您的回覆,但它沒有奏效。我使用Protege和RDF/XML生成了本體。 – mqpasta

+0

之間我加了下面一行g.NamespaceMap.AddNamespace(「prefix」,new Uri(「http://www.qasimpasta.info/humanonto.owl#」)); – mqpasta