質問

InfModel infmodel = ModelFactory.createInfModel(reasoner, m);
Resource vegetarian = infmodel.getResource(source + "Vegetarian");
Resource margherita = infmodel.getResource(source + "Example-Margherita");
if (infmodel.contains(margherita, RDF., vegetarian)) {
        System.out.println("Margherita is a memberOf Vegetarian pizza");
    }

上記の例は、正式なPizza.owlによって形成されます。このフクロウでは、Margheritaの例はMargheritaクラスの個人です。したがって、すでにOWLファイルで書かれています。ただし、問題は、Margherita-Exampleもベジタリアンピザであるべきであると推測する必要があるということです。プロテジェのような個人の可能性のあるクラスを見つける方法を示す例を教えてください。

役に立ちましたか?

解決

私は自分の質問を解決しました。私のオントロジーに問題があったと思います。したがって、私は個人を推測するために別のオントロジーを作成しました。私が作成したオントロジーには、人の人とサブクラスが含まれています。また、2つのオブジェクトプロパティ(ハスパウス、ハシング)と1つのデータ型プロパティ(Hasage)があります。そして、私は3人の個人を作成しました。ジョン - マレパーソン - ハシェージ(20) - ハシブリング(ジェーン)ジェーン - フェマーペーソン - ハシブリング(ジョン) - ハスパウス(ボブ)ボブ - マレパソン - ハスパウス(ジェーン)

そして、私はMalePersonとFemalePersonのクラスに2つの制限を設けました。 MalePerson:Hasspouse Max 1 Hasspouse Femalepersonのマレパーソンのみ:ハスパウスマックス1ハスパウスのみの女性

最後に、私は既婚者を定義されたクラスにしました。推論する前に、既婚者には個人がいません。ただし、モデルはジェーンとボブが結婚していると推測する必要があります。したがって、最後に、既婚者クラスには2人の個人が必要です。

イエナを使用してJavaでこのコードを実行したとき、2人の推測された個人を得ました。

OntModel ontModel = ModelFactory.createOntologyModel();
    InputStream in = FileManager.get().open(inputFileName);
    if (in == null) {
        throw new IllegalArgumentException( "File: " + inputFileName + " not found");
    }
    ontModel.read(in, "");


    Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
    reasoner = reasoner.bindSchema(ontModel);
    // Obtain standard OWL-DL spec and attach the Pellet reasoner
    OntModelSpec ontModelSpec = OntModelSpec.OWL_DL_MEM;
    ontModelSpec.setReasoner(reasoner);
    // Create ontology model with reasoner support
    OntModel model = ModelFactory.createOntologyModel(ontModelSpec, ontModel);

    // MarriedPerson has no asserted instances
    // However, if an inference engine is used, two of the three
    // individuals in the example presented here will be
    // recognized as MarriedPersons
            //ns is the uri
    OntClass marPerson = model.getOntClass(ns + "OWLClass_00000003866036241880"); // this is the uri for MarriedPerson class
    ExtendedIterator married = marPerson.listInstances();
    while(married.hasNext()) {
        OntResource mp = (OntResource)married.next();
        System.out.println(mp.getURI());
    } // this code returns 2 individuals with the help of reasoner
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top