我使用protege创建了一个本体。现在,我想编写一个使用dotNetRDF遍历本体的代码。通过遍历显示所有类、子类等.
我正在使用以下代码,但它提供了例外情况**
给定前缀'owl‘的命名空间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());
}此代码基于给定的答案( 这里 (http://answers.semanticweb.com/questions/19984/dotnetrdf-list-all-ontology-classes) )。
有人能让我知道我在上面的代码中遗漏了什么吗?dotNetRDF上的教程有什么好的网址吗?
发布于 2012-12-27 13:55:20
错误消息引用代码的以下部分:
g.CreateUriNode("owl:Class")这使用前缀名称作为完整URI的快捷方式,需要在图形中定义owl前缀。
如果您得到了它,那么您的RDF文件就不包括它,您可以这样定义如下:
g.NamespaceMap.AddNamespace("prefix", new Uri("http://some/namespace/"));我想OntologyGraph确实应该自动定义OWL名称空间,我将在下一个版本中添加这一点。
https://stackoverflow.com/questions/14051781
复制相似问题