简体   繁体   中英

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. 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. I need to get a original copy of onto1 in curOnto in each run of the for loop. Any help?

Thanks in advance.

The suggestion above (using org.apache.jena.rdf.model.ModelFactory#createModelForGraph ) is wrong. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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