本文整理汇总了Java中org.semanticweb.owlapi.reasoner.OWLReasoner.precomputeInferences方法的典型用法代码示例。如果您正苦于以下问题:Java OWLReasoner.precomputeInferences方法的具体用法?Java OWLReasoner.precomputeInferences怎么用?Java OWLReasoner.precomputeInferences使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.semanticweb.owlapi.reasoner.OWLReasoner
的用法示例。
在下文中一共展示了OWLReasoner.precomputeInferences方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generate
import org.semanticweb.owlapi.reasoner.OWLReasoner; //导入方法依赖的package包/类
@Override
public IndexSet generate(PTBox ptbox) {
Set<OWLClass> probSig = getProbabilisticSignature(ptbox.getDefaultConstraints());
//We need to create an OWLReasoner based on the KB instance
OWLReasoner reasoner = m_reasonerFactory.createReasoner( ptbox.getClassicalOntology() );
reasoner.precomputeInferences( new InferenceType[] {InferenceType.CLASS_HIERARCHY} );
return new ConceptTypeSet(generateConceptTypes( new ArrayList<OWLClass>(probSig), reasoner, m_limit ));
}
示例2: main
import org.semanticweb.owlapi.reasoner.OWLReasoner; //导入方法依赖的package包/类
/**
* @param args
* @throws OWLOntologyCreationException
*/
public static void main(String[] args) throws OWLOntologyCreationException {
OWLOntologyManager man = OWLManager.createOWLOntologyManager();
// Load your ontology.
OWLOntology ont = man
.loadOntologyFromOntologyDocument(new File(args[0]));
// Create an ELK reasoner.
OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
OWLReasoner reasoner = reasonerFactory.createReasoner(ont);
// Precompute instances for each named class in the ontology
reasoner.precomputeInferences(InferenceType.CLASS_ASSERTIONS);
// List representative instances for each class.
for (OWLClass clazz : ont.getClassesInSignature()) {
for (Node<OWLNamedIndividual> individual : reasoner.getInstances(
clazz, true)) {
System.out.println(clazz + "("
+ individual.getRepresentativeElement() + ")");
}
}
// Terminate the worker threads used by the reasoner.
reasoner.dispose();
}
示例3: main
import org.semanticweb.owlapi.reasoner.OWLReasoner; //导入方法依赖的package包/类
public static void main(String[] args) throws OWLOntologyStorageException,
OWLOntologyCreationException {
OWLOntologyManager inputOntologyManager = OWLManager.createOWLOntologyManager();
OWLOntologyManager outputOntologyManager = OWLManager.createOWLOntologyManager();
// Load your ontology.
OWLOntology ont = inputOntologyManager.loadOntologyFromOntologyDocument(new File("path-to-ontology"));
// Create an ELK reasoner.
OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
OWLReasoner reasoner = reasonerFactory.createReasoner(ont);
// Classify the ontology.
reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);
// To generate an inferred ontology we use implementations of
// inferred axiom generators
List<InferredAxiomGenerator<? extends OWLAxiom>> gens = new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>();
gens.add(new InferredSubClassAxiomGenerator());
gens.add(new InferredEquivalentClassAxiomGenerator());
// Put the inferred axioms into a fresh empty ontology.
OWLOntology infOnt = outputOntologyManager.createOntology();
InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner,
gens);
iog.fillOntology(outputOntologyManager.getOWLDataFactory(), infOnt);
// Save the inferred ontology.
outputOntologyManager.saveOntology(infOnt,
new FunctionalSyntaxDocumentFormat(),
IRI.create((new File("path-to-output").toURI())));
// Terminate the worker threads used by the reasoner.
reasoner.dispose();
}
示例4: main
import org.semanticweb.owlapi.reasoner.OWLReasoner; //导入方法依赖的package包/类
public static void main(String[] args) throws OWLOntologyStorageException,
OWLOntologyCreationException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
// Load your ontology
OWLOntology ont = manager.loadOntologyFromOntologyDocument(new File("path-to-ontology"));
// Create an ELK reasoner.
OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
OWLReasoner reasoner = reasonerFactory.createReasoner(ont);
// Classify the ontology.
reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);
OWLDataFactory factory = manager.getOWLDataFactory();
OWLClass subClass = factory.getOWLClass(IRI.create("http://www.co-ode.org/ontologies/galen#AbsoluteShapeState"));
OWLAxiom removed = factory.getOWLSubClassOfAxiom(subClass, factory.getOWLClass(IRI.create("http://www.co-ode.org/ontologies/galen#ShapeState")));
OWLAxiom added = factory.getOWLSubClassOfAxiom(subClass, factory.getOWLClass(IRI.create("http://www.co-ode.org/ontologies/galen#GeneralisedStructure")));
// Remove an existing axiom, add a new axiom
manager.addAxiom(ont, added);
manager.removeAxiom(ont, removed);
// This is a buffering reasoner, so you need to flush the changes
reasoner.flush();
// Re-classify the ontology, the changes should be accommodated
// incrementally (i.e. without re-inferring all subclass relationships)
// You should be able to see it from the log output
reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);
// Terminate the worker threads used by the reasoner.
reasoner.dispose();
}
示例5: testImport
import org.semanticweb.owlapi.reasoner.OWLReasoner; //导入方法依赖的package包/类
/**
* Testing loading of ontologies that have no axioms (but possibly import
* declarations).
*
* @see <a
* href="http://code.google.com/p/elk-reasoner/issues/detail?id=7">Issue 7<a>
* @throws OWLOntologyCreationException
* @throws URISyntaxException
*/
@Test
public void testImport() throws OWLOntologyCreationException,
URISyntaxException {
OWLOntologyManager man = TestOWLManager.createOWLOntologyManager();
// loading the root ontology
OWLOntology root = loadOntology(man, "root.owl");
// Create an ELK reasoner.
OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
OWLReasoner reasoner = reasonerFactory.createReasoner(root);
try {
// statistics about the root ontology
assertEquals(root.getAxiomCount(), 0);
// all two ontologies should be in the closure
assertEquals(root.getImportsClosure().size(), 2);
// all axioms from two ontologies should be in the closure
assertEquals(getAxioms(root).size(), 0);
// reasoner queries -- all subclasses are there
reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);
} finally {
reasoner.dispose();
}
}
示例6: createReasoner
import org.semanticweb.owlapi.reasoner.OWLReasoner; //导入方法依赖的package包/类
static OWLReasoner createReasoner(OWLOntology ontology) {
JcelReasonerFactory factory = new JcelReasonerFactory();
OWLReasoner reasoner = factory.createNonBufferingReasoner(ontology);
reasoner.precomputeInferences();
return reasoner;
}
示例7: tryOntology
import org.semanticweb.owlapi.reasoner.OWLReasoner; //导入方法依赖的package包/类
@Test
public void tryOntology() throws OWLOntologyCreationException, IOException {
AlternativeUelStarter starter = new AlternativeUelStarter(mainOntology);
// starter.setVerbose(true);
UnifierIterator iterator = (UnifierIterator) starter.modifyOntologyAndSolve(subsumptions, dissubsumptions,
variables, UnificationAlgorithmFactory.SAT_BASED_ALGORITHM);
Set<OWLAxiom> background = iterator.getUelModel().renderDefinitions();
Integer actualNumberOfUnifiers = 0;
while (iterator.hasNext()) {
actualNumberOfUnifiers++;
Set<OWLEquivalentClassesAxiom> unifier = iterator.next();
OWLOntology extendedOntology = ProcessorTest.createOntology(background, unifier);
// try {
// System.out.println();
// System.out.println("---" + actualNumberOfUnifiers);
// OWLManager.createOWLOntologyManager().saveOntology(extendedOntology,
// new FunctionalSyntaxDocumentFormat(), System.out);
// System.out.println();
// } catch (OWLOntologyStorageException e) {
// e.printStackTrace();
// }
OWLReasoner reasoner = new JcelReasonerFactory().createNonBufferingReasoner(extendedOntology);
reasoner.precomputeInferences();
for (OWLAxiom pos : subsumptions.getAxioms()) {
// System.out.println(pos + ": " + reasoner.isEntailed(pos));
Assert.assertTrue(reasoner.isEntailed(pos));
}
for (OWLAxiom neg : dissubsumptions.getAxioms()) {
// System.out.println(neg + ": " + reasoner.isEntailed(neg));
Assert.assertTrue(!reasoner.isEntailed(neg));
}
reasoner.dispose();
}
Assert.assertEquals(numberOfUnifiers, actualNumberOfUnifiers);
}
示例8: main
import org.semanticweb.owlapi.reasoner.OWLReasoner; //导入方法依赖的package包/类
/**
* @param args
*/
public static void main(String[] args)
{
try {
// Create an ontology manager in the usual way.
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
// Load the wine ontology from the web.
OWLOntology ont = manager.loadOntologyFromOntologyDocument(IRI.create("http://www.w3.org/TR/owl-guide/wine.rdf"));
// Create an instance of an OWL API reasoner (we use the OWL API built-in StructuralReasoner for the purpose of demonstration here)
StructuralReasonerFactory factory = new StructuralReasonerFactory();
OWLReasoner reasoner = factory.createReasoner(ont);
// Optionally let the reasoner compute the most relevant inferences in advance
reasoner.precomputeInferences(InferenceType.CLASS_ASSERTIONS,InferenceType.OBJECT_PROPERTY_ASSERTIONS);
// Create an instance of the SPARQL-DL query engine
engine = QueryEngine.create(manager, reasoner);
processQuery(
"PREFIX wine: <http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#>\n" +
"SELECT * WHERE {\n" +
"SubClassOf(wine:PinotBlanc, ?x),\n" +
"SubClassOf(?x, wine:Wine)\n" +
"}"
);
processQuery(
"PREFIX wine: <http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#>\n" +
"ASK {\n" +
"SubClassOf(wine:PinotBlanc, wine:Wine)\n" +
"}"
);
}
catch(UnsupportedOperationException exception) {
System.out.println("Unsupported reasoner operation.");
}
catch(OWLOntologyCreationException e) {
System.out.println("Could not load the ontology: " + e.getMessage());
}
}