我已编写代码从我的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 :(得分:0)
extract the properties associated with the classes
是什么意思?
这可能意味着任何数量的东西,你的意思是简单地找到将该类作为域/范围的属性吗?
你不能使用Ontology 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
执行相同的操作,以获取将类作为范围的属性