简体   繁体   English

复制耶拿的OWL本体

[英]copy an OWL Ontology in Jena

I am trying to copy an OWL ontology using Jena API, add a new statement to that ontology everytime. 我正在尝试使用Jena API复制OWL本体,每次都向该本体添加一条新语句。 But at the beginning it should get the original ontology without the new statement. 但是在开始时,它应该具有原始本体,而无需新的声明。

The following code adds a new statement everytime, on top of the previous one. 以下代码每次都在前一个语句的顶部添加一个新语句。

this runs in a for loop{

        OntModel curOnto = onto1.getOntology();

        curOnto.add(s,p,o);

        /*printing the statement from onto1
        it seems it is adding new statement in onto1 on top of previous statement*/

        int lineNum = 0;
        for (StmtIterator i = onto1.getOntology().listStatements(); i.hasNext();) {
            Statement stmt = i.nextStatement();
            System.out.println( lineNum++ + " - " + PrintUtil.print(stmt));
        }
}

As suggested in other post I have tried to copy the ontology like this: 正如其他帖子中所建议的那样,我试图复制这样的本体:

Model copyOnto = ModelFactory.createModelForGraph(onto1.getOntology().getGraph());
OntModel curOnto = new OntModelImpl(onto1.getOntology().getSpecification(), copyOnto);

but still the same, it keeps adding the new statement in onto1. 但还是一样,它一直在on1中添加新语句。 I need to get a original copy of onto1 in curOnto in each run of the for loop. 我需要在for循环的每次运行中在curOnto中获取onto1的原始副本。 Any help? 有什么帮助吗?

Thanks in advance. 提前致谢。

The suggestion above (using org.apache.jena.rdf.model.ModelFactory#createModelForGraph ) is wrong. 上面的建议(使用org.apache.jena.rdf.model.ModelFactory#createModelForGraph )是错误的。 All information is kept in the Graph. 所有信息都保存在图表中。 So you need copy whole graph (all triples). 因此,您需要复制整个图形(所有三元组)。 It can be done (for example) by method org.apache.jena.graph.GraphUtil#addInto 可以(例如)通过org.apache.jena.graph.GraphUtil#addInto方法来完成

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

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