2012-03-02 195 views
1

我写我的代码从我的RDF文件..这是代码..我使用dotNetRDf库中提取类和子类..提取物的属性

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(); 
    } 
} 

}

但是现在我想提取与类关联的属性..我尝试使用OntologyProperty类,但无法获得所需的输出

回答

0

你是什么意思extract the properties associated with the classes

这可能意味着任何数量的东西,你的意思是简单地找到那个类作为一个域/范围的属性?

你不能做到这一点使用本体论的API,它仅仅是底层API周围的包装,但你可以使用较低级别的API,像这样:

//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 

同样,你可以用rdfs:range做同样的事情获得具有该级别的房产