6
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 によって形成されます。このフクロウでは、例-マルゲリータはマルゲリータ クラスの個体です。ですから、フクロウファイルにはすでに書かれています。ただし、問題は、推論者がマルゲリータの例もベジタリアン ピザであると推論する必要があることです。Protege のように、個人の可能な推論クラスを見つける方法を示す例を誰か教えてください。

4

1 に答える 1

10

私は私の質問を解決しました。私のオントロジーに問題があったと思います。したがって、個人を推論する別のオントロジーを作成しました。私が作成したオントロジーには、 Person と Person のサブクラス : MalePerson 、 FemalePerson 、および MarriedPerson が含まれています。また、2 つのオブジェクト プロパティ (hasSpouse、hasSibling) と 1 つのデータ型プロパティ (hasAge) があります。そして、3個体を作成しました。John - MalePerson - hasAge(20) - hasSibling(Jane) Jane - FemalePerson - hasSibling(John) - hasSpouse(Bob) Bob - MalePerson - hasSpouse(Jane)

そして、MalePerson クラスと FemalePerson クラスに 2 つの制限を加えました。MalePerson の場合: hasSpouse max 1 hasSpouse のみ MalePerson FemalePerson の場合: hasSpouse max 1 hasSpouse のみ FemalePerson

最後に、MarriedPerson を定義済みクラスにしました。推論する前に、MarriedPerson には個人がありません。ただし、モデルは Jane と Bob が結婚していると推測する必要があります。したがって、最後に、MarriedPerson クラスには 2 つの個体が必要です。

Jena を使用して 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
于 2010-06-12T12:41:44.947 に答える