0

I've been trying to set up a query printer a lot like this: https://github.com/owlcs/owlapi/wiki/DL-Queries-with-a-real-reasoner where if I give it a query in Manchester syntax I can get a response that mirrors what I would get back in protege. I swapped out the Hermit reasoner with Openllet and it can't seem to retrieve any of the individuals anymore.

For reasons, I would like to stay away from Jena if possible.

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();
    }
}
topfoxrider
  • 143
  • 10
  • And now we should guess the code ? no information about the setup, the versions used (OWL API, Openllet) etc...it's impossible to give any advice. – UninformedUser Jul 18 '18 at 06:44
  • I can't share the code but I can say that the DL Query printer in my application is practically identical to the classes in the link. I'm just trying to swap out the reasoners. Openllet version is 2.6.4 and OWL version is 5.1.0. Can you clarify what you mean by setup? – topfoxrider Jul 18 '18 at 13:33
  • I can give snippets of my ontology class however. It's in the edit now. – topfoxrider Jul 18 '18 at 14:09

2 Answers2

1

You are using the inferred subclass axioms generator. This will not create axioms for individuals, so I would not expect individuals in the generated ontology. For more advice we need to see a snippet of code and data reproducing the problem.

Ignazio
  • 10,504
  • 1
  • 14
  • 25
  • I don't think that is the problem. When using Hermit as the reasoner this whole printer system thing works fine on simple queries. So let's say I inputted into my app the triple "John worksFor StackOverflow" and I want to query who John works for. This would have worked with my Hermit reasoner but not my current Openllet. Though what you said definitely applies to first order logic so thanks. – topfoxrider Jul 18 '18 at 17:44
0

It seems that the problem is with the code that I had linked. In the Query Printer class they set

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

the boolean should be false if you want individuals to appear and that really threw me off.

topfoxrider
  • 143
  • 10