1

我正在使用带有 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 对管理器加载的所有本体所做的所有推论保存在一个文件中,但我找不到任何示例。有人可以帮助我吗?谢谢 !

4

2 回答 2

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"))); 
于 2015-08-03T15:30:35.343 回答
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 将本体保存到文件中。此外,为了您对工作的详细了解,您可以通过此链接:-讲述颗粒推理器和 swrl 规则的工作

于 2015-09-14T07:50:52.060 回答