本文介绍了使用耶拿推断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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构成的.在这只猫头鹰中,Example-Margherita是Margherita类的个人.因此,它已经被写入owl文件中.但是,问题在于推理者应该推断玛格丽特的例子也应该是素食比萨.任何人都可以举一个例子来说明如何找到一个人的可能的推断类,例如在Protege中吗?(Protege正确地推断Example-Margherita是素食比萨.但是,我无法通过程序推断)

The example given above is formed by formal pizza.owl. In this owl, Example-Margherita is an individual of Margherita class. So, it is already written in owl file. However, the problem is that the reasoner should infer that margherita-example should be also an vegetarian pizza.Could anyone please give an example that shows how to find an individual's possible inferred classes like in Protege ?(Protege correctly infers that Example-Margherita is a Vegetarian Pizza. However, I can't infer programmatically)

推荐答案

我解决了我的问题.我认为本体存在问题.因此,我创建了另一个本体来推断个人.我创建的本体包含Person和Person的子类:MalePerson,FemalePerson和MarriedPerson.并且,有两个对象属性(hasSpouse,hasSibling)和一个数据类型属性(hasAge).而且,我创建了3个人.John-MalePerson-hasAge(20)-hasSibling(Jane)简-女人物-hasSibling(John)-hasSpouse(Bob)Bob-MalePerson-hasSpouse(Jane)

I solved my question. I think there was a problem with my ontology. Therefore, I created another ontology to infer individuals. The ontology that I created contains Person and subclasses of Person : MalePerson, FemalePerson and MarriedPerson. And, there are two object properties(hasSpouse, hasSibling) and one data type property(hasAge).And, I created 3 individuals.John - MalePerson - hasAge(20) - hasSibling(Jane)Jane - FemalePerson - hasSibling(John) - hasSpouse(Bob)Bob - MalePerson - hasSpouse(Jane)

并且,我对MalePerson和FemalePerson类设置了两个限制.对于MalePerson:hasSpouse最大1hasSpouse only MalePerson对于FemalePerson:hasSpouse最大1hasSpouse only FemalePerson

And, I put two restrictions for MalePerson and FemalePerson classes.For MalePerson :hasSpouse max 1hasSpouse only MalePersonFor FemalePerson :hasSpouse max 1hasSpouse only FemalePerson

最后,我使MarriedPerson成为一个已定义的类.在推理之前,MarriedPerson没有个人.但是,模型应该推断出简和鲍勃已婚.因此,最后,MarriedPerson类应该有2个人.

Lastly, I made MarriedPerson to be a defined class. Before reasoning, MarriedPerson has no individual. However, the model should infer that Jane and Bob are married. Therefore, at the end, MarriedPerson class should have 2 individuals.

当我使用Jena在Java中运行此代码时,我得到了2个推断出的个体.

When I ran this code in Java using Jena, I got 2 inferred individuals.

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

这篇关于使用耶拿推断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-10 00:25