Question

I have created an ontology using protege. Now I want to write a code to traverse ontology using dotNetRDF. By mean of traverse is displaying all classes, sub-classes etc.

I am using following code but it is giving exception **

The Namespace URI for the given Prefix 'owl' is not known by the in-scope 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());
        }

This code is base on answer given here (http://answers.semanticweb.com/questions/19984/dotnetrdf-list-all-ontology-classes)

Can anyone let me know what am I missing in above code? any good URL for tutorial on dotNetRDF?

Was it helpful?

Solution

The error message refers to the following part of your code:

g.CreateUriNode("owl:Class")

This uses a prefixed name as a shortcut for the full URI which requires the owl prefix to be defined in your graph.

If you are getting this then your RDF file does not include this, you can define this like so:

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

I guess an OntologyGraph should really define the OWL namespace automatically, I'll add this in the next release.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top