【问题标题】:How to process SWRL rules using Openllet and OWL api?如何使用 Openllet 和 OWL api 处理 SWRL 规则?
【发布时间】:2018-07-17 21:15:44
【问题描述】:

我一直在尝试设置一个查询打印机,如下所示: https://github.com/owlcs/owlapi/wiki/DL-Queries-with-a-real-reasoner 如果我在曼彻斯特语法中给它一个查询,我可以得到一个反映我在 protege 中得到的回复。我用 Openllet 替换了 Hermit 推理器,它似乎无法再检索到任何个人。

出于某种原因,如果可能,我想远离耶拿。

OntController.java

public class OntController {
//declared variables here
    public OntController(String name) throws OWLOntologyCreationException, OWLOntologyStorageException, IOException{
        //initialized a bunch of other variables here
        manager = OWLManager.createOWLOntologyManager();
        reasonFactory = new OpenlletReasonerFactory();
    }
    public void reason(){
        reasoner = reasonFactory.createReasoner(ont);
        reasoner.precomputeInferences(InferenceType.OBJECT_PROPERTY_HIERARCHY, InferenceType.OBJECT_PROPERTY_ASSERTIONS);
    }

    public void infer(){
        reasoner.precomputeInferences();
        List<InferredAxiomGenerator<? extends OWLAxiom>> gens = new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>();
        gens.add(new InferredSubClassAxiomGenerator());
        InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner, gens);
        iog.fillOntology(manager.getOWLDataFactory(), ont);
    }

    public void query() throws IOException{
        reasoner = reasonFactory.createReasoner(ont);
        ShortFormProvider shortFormProvider = new SimpleShortFormProvider();
        DLQueryPrinter dlQueryPrinter = new DLQueryPrinter(new DLQueryEngine(reasoner,
            shortFormProvider), shortFormProvider);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
        while (true) {
            System.out.println("Type a class expression in Manchester Syntax and press Enter (or press q to exit):");
            //blah blah
        }
        dlQueryPrinter.askQuery(classExpression.trim());
        System.out.println();
    }

    //more unrelated methods here
}

DLQueryEngine

import java.util.Collections;
import java.util.Set;

import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLClassExpression;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.reasoner.Node;
import org.semanticweb.owlapi.reasoner.NodeSet;
//import org.semanticweb.owlapi.reasoner.OWLReasoner;
import org.semanticweb.owlapi.util.ShortFormProvider;

import openllet.owlapi.OpenlletReasoner;

class DLQueryEngine {
    private final OpenlletReasoner reasoner;
    private final DLQueryParser parser;

    public DLQueryEngine(OpenlletReasoner reasoner, ShortFormProvider shortFormProvider) {
        this.reasoner = reasoner;
        parser = new DLQueryParser(reasoner.getRootOntology(), shortFormProvider);
    }

public Set<OWLClass> getSuperClasses(String classExpressionString, boolean direct) {
    if (classExpressionString.trim().length() == 0) {
        return Collections.emptySet();
    }
    OWLClassExpression classExpression = parser
            .parseClassExpression(classExpressionString);
    NodeSet<OWLClass> superClasses = reasoner
            .getSuperClasses(classExpression, direct);
    return superClasses.getFlattened();
}

public Set<OWLClass> getEquivalentClasses(String classExpressionString) {
    if (classExpressionString.trim().length() == 0) {
        return Collections.emptySet();
    }
    OWLClassExpression classExpression = parser
            .parseClassExpression(classExpressionString);
    Node<OWLClass> equivalentClasses = reasoner.getEquivalentClasses(classExpression);
    Set<OWLClass> result = null;
    if (classExpression.isAnonymous()) {
        result = equivalentClasses.getEntities();
    } else {
        result = equivalentClasses.getEntitiesMinus(classExpression.asOWLClass());
    }
    return result;
    }

public Set<OWLClass> getSubClasses(String classExpressionString, boolean direct) {
    if (classExpressionString.trim().length() == 0) {
        return Collections.emptySet();
    }
    OWLClassExpression classExpression = parser
            .parseClassExpression(classExpressionString);
    NodeSet<OWLClass> subClasses = reasoner.getSubClasses(classExpression, direct);
    return subClasses.getFlattened();
    }

public Set<OWLNamedIndividual> getInstances(String classExpressionString,
        boolean direct) {
    if (classExpressionString.trim().length() == 0) {
        return Collections.emptySet();
    }
    OWLClassExpression classExpression = parser
            .parseClassExpression(classExpressionString);
    NodeSet<OWLNamedIndividual> individuals = reasoner.getInstances(classExpression,
            direct);
    return individuals.getFlattened();
    }
}

【问题讨论】:

  • 现在我们应该猜猜密码了吗?没有关于设置、使用的版本(OWL API、Openllet)等的信息......不可能给出任何建议。
  • 我无法共享代码,但我可以说我的应用程序中的 DL Query 打印机实际上与链接中的类相同。我只是想换掉推理者。 Openllet 版本是 2.6.4,OWL 版本是 5.1.0。你能澄清一下你所说的设置是什么意思吗?
  • 我可以给我的本体类的 sn-ps。现在正在编辑中。

标签: owl protege swrl pellet


【解决方案1】:

您正在使用推断的子类公理生成器。这不会为个人创建公理,因此我不希望生成的本体中有个人。如需更多建议,我们需要查看重现问题的代码和数据的 sn-p。

【讨论】:

  • 我认为这不是问题所在。当使用 Hermit 作为推理器时,整个打印机系统的东西在简单的查询上工作得很好。因此,假设我在我的应用程序中输入了三重“John worksFor StackOverflow”,我想查询 John 为谁工作。这适用于我的 Hermit 推理器,但不适用于我当前的 Openllet。虽然你所说的绝对适用于一阶逻辑,所以谢谢。
【解决方案2】:

看来问题出在我链接的代码上。在他们设置的查询打印机类中

Set<OWLNamedIndividual> individuals = dlQueryEngine.getInstances(
                        classExpression, true);

如果你想让个人出现,布尔值应该是假的,这真的让我失望。

【讨论】:

    猜你喜欢
    • 2013-06-06
    • 1970-01-01
    • 2021-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-24
    • 1970-01-01
    相关资源
    最近更新 更多