首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于检索对象属性断言的Hermit和OWLApi

用于检索对象属性断言的Hermit和OWLApi
EN

Stack Overflow用户
提问于 2018-02-16 00:44:58
回答 1查看 292关注 0票数 0

我尝试从reasoner (hermit 1.3.8.4)和OWLApi (3.4.10)检索属性断言。在这张图片中,我想检索“Sergio Sandro,isGrandfather isGrandfather”。

Picture - object property assertions

我尝试在https://stackoverflow.com/a/37497541/3760251中使用Ignazio答案

以Horridge为例,但OWL API更改了签名,我不知道如何使用它。https://www.javatips.net/api/Owl-master/owlapi-master/tools/src/main/java/org/semanticweb/owlapi/util/InferredSubObjectPropertyAxiomGenerator.java

因此,如果您有来自InferredObjectPropertyAxiomGenerator的addAxioms方法的示例,我将不胜感激。

InferredObjectPropertyAxiomGenerator生成器=新InferredObjectPropertyAxiomGenerator() { @Override protected void addAxioms(OWLEntity entity,OWLReasoner reasoner,OWLDataFactory dataFactory,Set result) {}}

谢谢,

EN

回答 1

Stack Overflow用户

发布于 2018-02-16 01:33:35

我发现了来自Ignazio的一个很棒的代码:https://github.com/owlcs/owlapi/issues/643

我对你的代码做了一些小改动,并用OWLAPI4.3.1-SNAPSHOT和HermiT 1.3.8.431-SNAPSHOT运行它(这些版本包含问题#646中详细描述的修复)

输出文件包含对象属性:

代码语言:javascript
复制
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");
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48812279

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档