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クラスを使用しようとしましたが、目的の出力を取得できませんでした。

4

1 に答える 1

0

どういう意味extract the properties associated with the classesですか?

これは、いくつものことを意味する可能性があります。つまり、そのクラスをドメイン/範囲として持つプロパティを単に見つけるということですか?

基盤となるAPIの単なるラッパーであるOntologyAPIを使用してこれを行うことはできませんが、次のように低レベルの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同様に、範囲としてクラスを持つプロパティを取得するために同じことを行うことができます

于 2012-03-04T19:55:35.880 に答える