简体   繁体   English

隐士和OWLApi用于检索对象属性断言

[英]Hermit and OWLApi for retrieve object property assertions

I'm try to retrieve property assertions from reasoner (hermit 1.3.8.4) and OWLApi (3.4.10). 我尝试从推理程序(hermit 1.3.8.4)和OWLApi(3.4.10)中检索属性断言。 In this picture, I want to retrieve "isGrandfather Sandro, isGrandfather Sergio". 在这张照片中,我想检索“ isGrandfather Sandro,isGrandfather Sergio”。

Picture - object property assertions 图片-对象属性断言

I try to use Ignazio answer in: https://stackoverflow.com/a/37497541/3760251 我尝试在以下位置使用Ignazio答案: https : //stackoverflow.com/a/37497541/3760251

With Horridge example, but OWL API change the signature and I don't know how can I use it. 以Horridge为例,但是OWL API更改了签名,我不知道该如何使用它。 https://www.javatips.net/api/Owl-master/owlapi-master/tools/src/main/java/org/semanticweb/owlapi/util/InferredSubObjectPropertyAxiomGenerator.java https://www.javatips.net/api/Owl-master/owlapi-master/tools/src/main/java/org/semanticweb/owlapi/util/InferredSubObjectPropertyAxiomGenerator.java

So, if you have a example for addAxioms method from InferredObjectPropertyAxiomGenerator I appreciate. 因此,如果您有InferredObjectPropertyAxiomGenerator的addAxioms方法的示例,我将不胜感激。

InferredObjectPropertyAxiomGenerator generator = new InferredObjectPropertyAxiomGenerator() { @Override protected void addAxioms(OWLEntity entity, OWLReasoner reasoner, OWLDataFactory dataFactory, Set result) { } } InferredObjectPropertyAxiomGenerator generator = new InferredObjectPropertyAxiomGenerator(){@Override protected void addAxioms(OWLEntity实体,OWLReasoner推理程序,OWLDataFactory dataFactory,设置结果){}}

Thanks, 谢谢,

I found an great code from Ignazio in: https://github.com/owlcs/owlapi/issues/643 我在以下网址找到了来自Ignazio的出色代码: https//github.com/owlcs/owlapi/issues/643

I've made minor changes to your code and run it with OWLAPI 4.3.1-SNAPSHOT and HermiT 1.3.8.431-SNAPSHOT (these versions contain fixes detailed in issue #646 ) 我已经对您的代码进行了微小的更改,并使用OWLAPI 4.3.1-SNAPSHOT和HermiT 1.3.8.431-SNAPSHOT运行(这些版本包含在问题#646中详细介绍的修复程序)

The output file contains object properties: 输出文件包含对象属性:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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