Discipulos
Discipulos

Reputation: 469

Save Pellet inferences using OWL API

i'am using the last version of pellet reasoner with OWL API:

 OWLOntologyManager manager=OWLManager.createOWLOntologyManager();
 OWLOntology fist_ontology=manager.loadOntologyFromOntologyDocument.........
 ................
 OWLOntology last_ontology=manager.loadOntologyFromOntologyDocument..........

 reasoner=PelletReasonerFactory.getInstance().createReasoner(last_ontology);
 manager.addOntologyChangeListener(reasoner);

Several ontologies are loaded with the manager. Now I need to save in a file all of the inferences made by Pellet for all of the ontologies loaded with the manager, but I can not find any example. Someone can help me ? Thank you !

Upvotes: 1

Views: 621

Answers (2)

Batman22
Batman22

Reputation: 366

public void flushToFile() {
        reasoner.flush();
        //System.out.println(reasoner.isEntailed(ax5));
        InferredOntologyGenerator gen = new InferredOntologyGenerator(reasoner);
        gen.fillOntology(factory, newOntology);
        try {
            manager.saveOntology(newOntology, new FileOutputStream(new File("D:\\XYZ\\OutputNew.owl")));
        } catch (OWLOntologyStorageException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

You can use this api for saving the ontology to a file. Also for your detailed understanding regarding the working you can go through this link :- tells about the working of a pellet reasoner and swrl rules

Upvotes: 0

Discipulos
Discipulos

Reputation: 469

I have resolved:

List<InferredAxiomGenerator<? extends OWLAxiom>> gens = new ArrayList<>();
         gens.add(new InferredSubClassAxiomGenerator());  
         gens.add(new InferredClassAssertionAxiomGenerator());
         gens.add( new InferredDisjointClassesAxiomGenerator());
         gens.add( new InferredEquivalentClassAxiomGenerator());
         gens.add( new InferredEquivalentDataPropertiesAxiomGenerator());
         gens.add( new InferredEquivalentObjectPropertyAxiomGenerator());
         gens.add( new InferredInverseObjectPropertiesAxiomGenerator());
         gens.add( new InferredObjectPropertyCharacteristicAxiomGenerator());
         gens.add( new InferredPropertyAssertionGenerator());
         gens.add( new InferredSubDataPropertyAxiomGenerator());
         gens.add( new InferredSubObjectPropertyAxiomGenerator());

         InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner, gens);
         OWLOntology infOnt = manager.createOntology();
         iog.fillOntology(datafactory, infOnt);
         manager.saveOntology(infOnt,new RDFXMLDocumentFormat(),IRI.create(new File("D://file.owl"))); 

Upvotes: 1

Related Questions