如何使用Openllet和OWLapi处理SWRL规则?

How to process SWRL rules using Openllet and OWL api?

我一直在尝试像这样设置查询打印机: 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();
    }
}

您正在使用推断子类公理生成器。这不会为个体创建公理,所以我不希望生成的 ontology 中有个体。如需更多建议,我们需要查看重现该问题的代码片段和数据。

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

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

如果您希望个人出现,布尔值应该为 false,这让我很反感。