使用OWL API保存Pellet推断

时间:2015-07-30 14:38:43

标签: owl owl-api pellet

我正在使用最新版本的pellet推理器和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);

管理员加载了几个本体。现在我需要在文件中保存Pellet为管理器加载的所有本体所做的所有推论,但我找不到任何示例。有人可以帮帮我吗?谢谢!

2 个答案:

答案 0 :(得分:1)

我已经解决了:

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"))); 

答案 1 :(得分:0)

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();
        }
    }

您可以使用此api将本体保存到文件。另外,为了您对工作的详细了解,您可以浏览以下链接: - tells about the working of a pellet reasoner and swrl rules