Hermit и OWLApi для получения утверждений о свойствах объекта

Я пытаюсь получить утверждения о свойствах от разумного (отшельника 1.3.8.4) и OWLApi (3.4.10). На этой картинке я хочу получить "дедушка Сандро, дедушка Серхио".

Picture - утверждения свойств объекта

Я пытаюсь использовать ответ Игнацио в: /questions/30388969/poluchit-predpolagaemyie-svojstva-obekta-utverzhdeniya-otshelnika/30388970#30388970

На примере Horridge, но OWL API меняет подпись, и я не знаю, как ее использовать. https://www.javatips.net/api/Owl-master/owlapi-master/tools/src/main/java/org/semanticweb/owlapi/util/InferredSubObjectPropertyAxiomGenerator.java

Итак, если у вас есть пример для метода addAxioms из InferredObjectPropertyAxiomGenerator, я ценю.

InferredObjectPropertyAxiomGenerator generator = new InferredObjectPropertyAxiomGenerator () {@Override protected void addAxioms (сущность OWLEntity, аргумент OWLReasoner, OWLDataFactory dataFactory, установить результат) { } }

Спасибо,

1 ответ

Я нашел отличный код от Игнацио в: https://github.com/owlcs/owlapi/issues/643

Я сделал небольшие изменения в вашем коде и запустил его с OWLAPI 4.3.1-SNAPSHOT и HermiT 1.3.8.431-SNAPSHOT (эти версии содержат исправления, подробно описанные в выпуске № 646).

Выходной файл содержит свойства объекта:

public static void main(String[] args) throws Exception {
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    OWLOntology ontology = manager.loadOntology(
        IRI.create("https://raw.githubusercontent.com/owlcs/pizza-ontology/master/pizza.owl"));
    OWLDataFactory df = manager.getOWLDataFactory();

    Configuration configuration = new Configuration();
    configuration.ignoreUnsupportedDatatypes = true;
    ReasonerFactory rf = new ReasonerFactory();

    OWLReasoner reasoner = rf.createReasoner(ontology, configuration);
    boolean consistencyCheck = reasoner.isConsistent();
    if (consistencyCheck) {
        reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY,
            InferenceType.CLASS_ASSERTIONS, InferenceType.OBJECT_PROPERTY_HIERARCHY,
            InferenceType.DATA_PROPERTY_HIERARCHY, InferenceType.OBJECT_PROPERTY_ASSERTIONS);

        List<InferredAxiomGenerator<? extends OWLAxiom>> generators = new ArrayList<>();
        generators.add(new InferredSubClassAxiomGenerator());
        generators.add(new InferredClassAssertionAxiomGenerator());
        generators.add(new InferredDataPropertyCharacteristicAxiomGenerator());
        generators.add(new InferredEquivalentClassAxiomGenerator());
        generators.add(new InferredEquivalentDataPropertiesAxiomGenerator());
        generators.add(new InferredEquivalentObjectPropertyAxiomGenerator());
        generators.add(new InferredInverseObjectPropertiesAxiomGenerator());
        generators.add(new InferredObjectPropertyCharacteristicAxiomGenerator());

        // NOTE: InferredPropertyAssertionGenerator significantly slows down
        // inference computation
        generators.add(new org.semanticweb.owlapi.util.InferredPropertyAssertionGenerator());

        generators.add(new InferredSubClassAxiomGenerator());
        generators.add(new InferredSubDataPropertyAxiomGenerator());
        generators.add(new InferredSubObjectPropertyAxiomGenerator());
        List<InferredIndividualAxiomGenerator<? extends OWLIndividualAxiom>> individualAxioms =
            new ArrayList<>();
        generators.addAll(individualAxioms);

        generators.add(new InferredDisjointClassesAxiomGenerator());
        InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner, generators);
        OWLOntology inferredAxiomsOntology = manager.createOntology();
        iog.fillOntology(df, inferredAxiomsOntology);
        File inferredOntologyFile = new File("output.txt");
        // Now we create a stream since the ontology manager can then write to that stream.
        try (OutputStream outputStream = new FileOutputStream(inferredOntologyFile)) {
            // We use the same format as for the input ontology.
            manager.saveOntology(inferredAxiomsOntology, outputStream);
        }
    } // End if consistencyCheck
    else {
        System.out.println("Inconsistent input Ontology, Please check the OWL File");
    }
}
Другие вопросы по тегам