本文整理汇总了Java中org.semanticweb.owlapi.reasoner.OWLReasoner.getSuperClasses方法的典型用法代码示例。如果您正苦于以下问题:Java OWLReasoner.getSuperClasses方法的具体用法?Java OWLReasoner.getSuperClasses怎么用?Java OWLReasoner.getSuperClasses使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.semanticweb.owlapi.reasoner.OWLReasoner
的用法示例。
在下文中一共展示了OWLReasoner.getSuperClasses方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.semanticweb.owlapi.reasoner.OWLReasoner; //导入方法依赖的package包/类
public static void main(String[] args) throws OWLOntologyCreationException {
OWLOntologyManager man = OWLManager.createOWLOntologyManager();
OWLDataFactory dataFactory = man.getOWLDataFactory();
// Load your ontology.
OWLOntology ont = man.loadOntologyFromOntologyDocument(new File(
"c:/ontologies/ontology.owl"));
// Create an ELK reasoner.
OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
OWLReasoner reasoner = reasonerFactory.createReasoner(ont);
// Create your desired query class expression. In this example we
// will query ObjectIntersectionOf(A ObjectSomeValuesFrom(R B)).
PrefixManager pm = new DefaultPrefixManager("http://example.org/");
OWLClass A = dataFactory.getOWLClass(":A", pm);
OWLObjectProperty R = dataFactory.getOWLObjectProperty(":R", pm);
OWLClass B = dataFactory.getOWLClass(":B", pm);
OWLClassExpression query = dataFactory.getOWLObjectIntersectionOf(A,
dataFactory.getOWLObjectSomeValuesFrom(R, B));
// Create a fresh name for the query.
OWLClass newName = dataFactory.getOWLClass(IRI.create("temp001"));
// Make the query equivalent to the fresh class
OWLAxiom definition = dataFactory.getOWLEquivalentClassesAxiom(newName,
query);
man.addAxiom(ont, definition);
// Remember to either flush the reasoner after the ontology change
// or create the reasoner in non-buffering mode. Note that querying
// a reasoner after an ontology change triggers re-classification of
// the whole ontology which might be costly. Therefore, if you plan
// to query for multiple complex class expressions, it will be more
// efficient to add the corresponding definitions to the ontology at
// once before asking any queries to the reasoner.
reasoner.flush();
// You can now retrieve subclasses, superclasses, and instances of
// the query class by using its new name instead.
reasoner.getSubClasses(newName, true);
reasoner.getSuperClasses(newName, true);
reasoner.getInstances(newName, false);
// After you are done with the query, you should remove the definition
man.removeAxiom(ont, definition);
// You can now add new definitions for new queries in the same way
// After you are done with all queries, do not forget to free the
// resources occupied by the reasoner
reasoner.dispose();
}
示例2: getInferences
import org.semanticweb.owlapi.reasoner.OWLReasoner; //导入方法依赖的package包/类
static Set<OWLAxiom> getInferences(OWLGraphWrapper graph, String reasonerName) throws OWLException {
graph.mergeImportClosure();
InferenceBuilder builder = new InferenceBuilder(graph, reasonerName);
try {
Set<OWLAxiom> inferredAxioms = new HashSet<OWLAxiom>();
OWLOntology ontology = graph.getSourceOntology();
OWLDataFactory dataFactory = ontology.getOWLOntologyManager().getOWLDataFactory();
OWLReasoner reasoner = builder.getReasoner(ontology);
for (OWLClass cls : ontology.getClassesInSignature()) {
NodeSet<OWLClass> scs = reasoner.getSuperClasses(cls, true);
for (Node<OWLClass> scSet : scs) {
for (OWLClass sc : scSet) {
if (sc.isOWLThing()) {
continue; // do not report subclasses of owl:Thing
}
// we do not want to report inferred subclass links
// if they are already asserted in the ontology
boolean isAsserted = false;
for (OWLClassExpression asc : OwlHelper.getSuperClasses(cls, ontology)) {
if (asc.equals(sc)) {
// we don't want to report this
isAsserted = true;
}
}
// include any inferred axiom that is NOT already asserted in the ontology
if (!isAsserted) {
inferredAxioms.add(dataFactory.getOWLSubClassOfAxiom(cls, sc));
}
}
}
}
return inferredAxioms;
}
finally {
builder.dispose();
}
}