简体   繁体   English

在耶拿使用OWL.sameAs链接概念

[英]Linking concepts using OWL.sameAs in Jena

I am trying to tie up two identical individuals from different sources. 我试图将来自不同来源的两个相同的人捆绑在一起。 My idea is that, if IndividualA has a missing property P but is tied up to IndividualB with an existing P using OWL.sameAs, then the inferencer should output that IndividualA has P! 我的想法是,如果IndividualA具有缺失的属性P,但使用OWL.sameAs将其与已有的P捆绑在一起,则推断者应输出IndividualA具有P! I am confused why this isn't working. 我很困惑为什么这不起作用。 This is my code. 这是我的代码。

public class Main {

static String NS_A = "http://www.namespacea.com/ontoa.owl#";
static String NS_B = "http://www.namespaceb.com/ontob.owl#";
static String NS_C = "http://www.namespacec.com/ontoc.owl#";

public static void main(String[] args) {

    OntModelSpec spec = OntModelSpec.OWL_MEM_MINI_RULE_INF;

    OntModel modelA = ModelFactory.createOntologyModel(spec);
    OntModel modelB = ModelFactory.createOntologyModel(spec);
    OntModel modelC = ModelFactory.createOntologyModel(spec);

    // Populate Model A
    OntClass animal = modelA.createClass(NS_A + "Animal");
    OntProperty hasFeathers = modelA.createOntProperty(NS_A + "hasFeathers");
    hasFeathers.addDomain(animal);
    hasFeathers.addRange(XSD.xboolean);

    // Populate Model B
    OntClass duck = modelB.createClass(NS_B + "Duck");
    duck.setSuperClass(animal);
    Individual donaldA = modelB.createIndividual(NS_B + "DonaldDuck", duck);

    // NEXT LINE IS REMOVED ON PURPOSE
    //donaldA.addLiteral(hasFeathers, true);

    //Populate Model C
    Individual donaldB = modelC.createIndividual(NS_C + "DonaldDuck", duck);

    // Donald hasFeathers IS DECLARED HERE
    donaldB.addLiteral(hasFeathers, true);

    // THIS TIES UP THE TWO INDIVIDUALS
    donaldA.addProperty(OWL.sameAs, donaldB);

    // Query
    System.out.println(
        "Does " + donaldA.getLocalName() +
        " have feathers? " + "Ans. " + donaldA.getPropertyValue(hasFeathers).asLiteral().getValue()
    );
}
}

The result is a NullPointerException. 结果是NullPointerException。 How do you solve this problem? 你怎么解决这个问题?

A more difficult scenario that I've thought of is, if there are Individuals A, B, C, D and E st A isSameAs B, B isSameAs C, and so forth, where E has P = true. 我想到的一个更困难的情况是,如果存在个体A,B,C,D和E,则st是isSameAs B,B isSameAs C,依此类推,其中E具有P = true。 Then asking if A has P = true should say TRUE! 然后询问A是否具有P = true应该说TRUE!

Ok, I have posted the same question in the jena mailing list. 好的,我已经在耶拿邮件列表中发布了相同的问题。 Thanks for the update Ian. 感谢您的更新伊恩。 According to Dave Reynolds, The reasoner works within a model and not across different models. 根据Dave Reynolds的说法,推理机在模型中工作,而不是在不同模型中工作。

Therefore the answer should be to use say, only modelA for instance so that all of the individuals are stored within it. 因此,答案应该是仅使用例如modelA这样,以便所有个人都存储在其中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM