1

I have written my code to extract classes and Subclasses from my RDF file.. This is the code.. I am using dotNetRDf library..

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using System.Linq;
using VDS.RDF;
using VDS.RDF.Ontology;
using VDS.RDF.Parsing;


namespace ConsoleApplication1
{
class Program
{
    static void Main(string[] args)
    {
    //
        OntologyGraph g = new OntologyGraph();
        FileLoader.Load(g, "D:\\SBIRS.owl");
        OntologyClass someClass = g.CreateOntologyClass(new    
        Uri("http://www.semanticweb.org/ontologies/2012/0/SBIRS.owl#Shape"));

                  //Write out Super Classes

        foreach (OntologyClass c in someClass.SuperClasses)
        {
           Console.WriteLine("Super Class: " + c.Resource.ToString());
        }
        //Write out Sub Classes



        foreach (OntologyClass c in someClass.SubClasses)
        {

            Console.WriteLine("Sub Class: " + c.Resource.ToString());
        }
        Console.Read();
    }
}

}

But now i want to extract the properties associated with classes.. I tried to use OntologyProperty class but was not able to get desired output

RobV
  • 28,022
  • 11
  • 77
  • 119
pitumalkani
  • 127
  • 1
  • 1
  • 7

1 Answers1

0

What do you mean by extract the properties associated with the classes?

This could mean any number of things, do you mean simply find the properties which have that class as a domain/range?

You can't do this using the Ontology API which is just a wrapper around the underlying APIs but you can use the lower level API like so:

//Assuming you've already set up your Graph and Class as above...

//Find properties who have this class as a domain
INode domain = g.CreateUriNode(new Uri(NamespaceMapper.RDFS + "domain"));
IEnumerable<OntologyProperty> ps = g.GetTriplesWithPredicateObject(domain, someClass).Select(t => new OntologyProperty(t.Subject, g));

//Now iterate over ps and do what you want with the properties

Equally you could do the same things with rdfs:range to get properties which have the class as a range

RobV
  • 28,022
  • 11
  • 77
  • 119