我一直在尝试设置查询打印机,如下所示: https://github.com/owlcs/owlapi/wiki/DL-Queries-with-a-real-reasoner 如果我以曼彻斯特语法向它查询,我会得到一个响应,该响应反映了我将重新获得蛋白质的机会。我用Openllet换了隐士推理机,它似乎再也找不到任何人了。
出于某些原因,如果可能,我想远离耶拿。
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();
}
}
答案 0 :(得分:1)
您正在使用推断的子类公理生成器。这不会为个人创建公理,因此,我不会期望生成的本体中存在个人。要获得更多建议,我们需要查看一段代码和数据来重现该问题。
答案 1 :(得分:0)
似乎问题出在我链接的代码上。他们在查询打印机类中设置
Set<OWLNamedIndividual> individuals = dlQueryEngine.getInstances(
classExpression, true);
如果您希望个人出现并且真的让我失望,则布尔值应该为false。