org.semanticweb.owlapi.reasoner.InferenceType Java Examples

The following examples show how to use org.semanticweb.owlapi.reasoner.InferenceType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProofTest.java    From elk-reasoner with Apache License 2.0 6 votes vote down vote up
@Test
public void emptyDisjointUnion() throws Exception {
	OWLOntologyManager owlManager = OWLManager
			.createConcurrentOWLOntologyManager();
	// creating an ontology
	final OWLOntology ontology = owlManager.createOntology();
	OWLClass a = factory.getOWLClass(IRI.create("http://example.org/A"));
	OWLClass b = factory.getOWLClass(IRI.create("http://example.org/B"));
	// DisjointUnion(A ) = EquivalentClasses(A owl:Nothing)
	owlManager.addAxiom(ontology, factory.getOWLDisjointUnionAxiom(a,
			Collections.<OWLClassExpression> emptySet()));
	owlManager.addAxiom(ontology, factory.getOWLSubClassOfAxiom(b, b));

	final OWLProver prover = OWLAPITestUtils.createProver(ontology);

	prover.precomputeInferences(InferenceType.CLASS_HIERARCHY);

	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(a, b));
}
 
Example #2
Source File: QueryingWithNamedClasses.java    From elk-reasoner with Apache License 2.0 6 votes vote down vote up
public QueryingWithNamedClasses() throws OWLOntologyCreationException {
	// Traditional setup with the OWL-API
	manager = OWLManager.createOWLOntologyManager();
	IRI ontologyIri = IRI.create(EL_ONTOLOGY);
	ontology = manager.loadOntologyFromOntologyDocument(ontologyIri);

	System.out.println("Loaded ontology: " + ontology.getOntologyID());
	// But we use the Elk reasoner (add it to the classpath)
	reasonerFactory = new ElkReasonerFactory();
	reasoner = reasonerFactory.createReasoner(ontology);
	// IMPORTANT: Precompute the inferences beforehand, otherwise no results
	// will be returned
	reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);
	// Ontologies are not easy to query with the full name of concept, so we
	// keep only the interesting bit ( = shortform)
	shortFormProvider = new SimpleShortFormProvider();

	Set<OWLOntology> importsClosure = ontology.getImportsClosure();
	mapper = new BidirectionalShortFormProviderAdapter(manager,
			importsClosure, shortFormProvider);
}
 
Example #3
Source File: RetrievingProofsForEntailment.java    From elk-reasoner with Apache License 2.0 6 votes vote down vote up
/**
 * @param args
 * @throws OWLOntologyCreationException
 */
public static void main(String[] args) throws OWLOntologyCreationException {
	OWLOntologyManager manager = OWLManager.createOWLOntologyManager();

	// Load your ontology.
	OWLOntology ont = manager.loadOntologyFromOntologyDocument(new File("/path/to/your/ontology/ontology.owl"));
	
	// Create an instance of ELK
	ElkProverFactory proverFactory = new ElkProverFactory();
	OWLProver prover = proverFactory.createReasoner(ont);		
	
	// Pre-compute classification
	prover.precomputeInferences(InferenceType.CLASS_HIERARCHY);

	// Pick the entailment for which we are interested in proofs
	OWLAxiom entailment = getEntailment();
	
	// Get the inferences used to prove the entailment 
	DynamicProof<? extends Inference<OWLAxiom>> proof = prover.getProof(entailment);
	
	// Now we can recursively request inferences and their premises. Print them to std.out in this example.
	unwindProof(proof, entailment);

	// Terminate the worker threads used by the reasoner.
	prover.dispose();
}
 
Example #4
Source File: ProofTest.java    From elk-reasoner with Apache License 2.0 6 votes vote down vote up
@Test
public void compositionReflexivity() throws Exception {
	// loading and classifying via the OWL API
	final OWLOntology ontology = loadOntology(ProofTest.class
			.getClassLoader()
			.getResourceAsStream(ElkTestUtils.TEST_INPUT_LOCATION
					+ "/classification/CompositionReflexivity.owl"));
	final OWLProver prover = OWLAPITestUtils.createProver(ontology);

	prover.precomputeInferences(InferenceType.CLASS_HIERARCHY);

	OWLClass sub = factory.getOWLClass(IRI.create("http://example.org/A"));
	OWLClass sup = factory.getOWLClass(IRI.create("http://example.org/B"));

	// printInferences(reasoner, sub, sup);

	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(sub, sup));
}
 
Example #5
Source File: ProofTest.java    From elk-reasoner with Apache License 2.0 6 votes vote down vote up
@Test
public void reflexiveRoles2() throws Exception {
	final OWLOntology ontology = loadOntology(
			ProofTest.class.getClassLoader()
					.getResourceAsStream(ElkTestUtils.TEST_INPUT_LOCATION
							+ "/classification/ReflexiveRole.owl"));
	final OWLProver prover = OWLAPITestUtils.createProver(ontology);

	prover.precomputeInferences(InferenceType.CLASS_HIERARCHY);

	OWLClass sub = factory.getOWLClass(IRI.create("http://example.org/C1"));
	OWLClass sup = factory.getOWLClass(IRI.create("http://example.org/F"));

	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(sub, sup));
}
 
Example #6
Source File: ProofTest.java    From elk-reasoner with Apache License 2.0 6 votes vote down vote up
@Test
public void reflexiveRoles() throws Exception {
	// loading and classifying via the OWL API
	final OWLOntology ontology = loadOntology(
			ProofTest.class.getClassLoader()
					.getResourceAsStream(ElkTestUtils.TEST_INPUT_LOCATION
							+ "/classification/ReflexiveRole.owl"));
	final OWLProver prover = OWLAPITestUtils.createProver(ontology);

	prover.precomputeInferences(InferenceType.CLASS_HIERARCHY);

	OWLClass sub = factory.getOWLClass(IRI.create("http://example.org/K"));
	OWLClass sup = factory.getOWLClass(IRI.create("http://example.org/L"));

	// printInferences(reasoner, sub, sup);

	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(sub, sup));
}
 
Example #7
Source File: EmptyImportTest.java    From elk-reasoner with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
	}

}
 
Example #8
Source File: ReasonOperation.java    From robot with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Given an ontology, a reasoner, and a map of options, use the reasoner to validate the ontology,
 * compute class hierarchy, and find equivalencies.
 *
 * @param ontology OWLOntology to reason over
 * @param reasoner OWLReasoner to use
 * @param options Map of reason options
 * @throws OntologyLogicException on invalid ontology
 */
private static void reason(
    OWLOntology ontology, OWLReasoner reasoner, Map<String, String> options)
    throws OntologyLogicException {
  long startTime = System.currentTimeMillis();
  logger.info("Starting reasoning...");

  // Validate and maybe dump the unsat classes into a file
  String dumpFilePath = OptionsHelper.getOption(options, "dump-unsatisfiable", null);
  ReasonerHelper.validate(reasoner, dumpFilePath);

  logger.info("Precomputing class hierarchy...");
  reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);

  EquivalentClassReasoningMode mode =
      EquivalentClassReasoningMode.from(options.getOrDefault("equivalent-classes-allowed", ""));
  logger.info("Finding equivalencies...");

  EquivalentClassReasoning equivalentReasoning =
      new EquivalentClassReasoning(ontology, reasoner, mode);
  boolean passesEquivalenceTests = equivalentReasoning.reason();
  equivalentReasoning.logReport(logger);
  if (!passesEquivalenceTests) {
    throw new OntologyLogicException(equivalentClassAxiomError);
  }

  float elapsedTime = System.currentTimeMillis() - startTime;
  long seconds = (int) Math.ceil(elapsedTime / 1000);
  logger.info("Reasoning took {} seconds.", seconds);
}
 
Example #9
Source File: OWLAPIIncrementalClassificationMultiDeltas.java    From elk-reasoner with Apache License 2.0 5 votes vote down vote up
@Override
public void run() throws TaskException {
	long ts = System.currentTimeMillis();
	
	reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);

	ts = System.currentTimeMillis() - ts;
	
	if (measureTime) {
		metrics.incrementRunCount();
		metrics.updateLongMetric("incremental update wall time", ts);
	}
}
 
Example #10
Source File: OWLAPIIncrementalClassificationMultiDeltas.java    From elk-reasoner with Apache License 2.0 5 votes vote down vote up
@Override
public void run() throws TaskException {
	try {
		reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);
	} catch (Exception e) {
		throw new TaskException("Exception during initial classification", e);
	}
}
 
Example #11
Source File: ProofTest.java    From elk-reasoner with Apache License 2.0 5 votes vote down vote up
@Test
public void emptyEnumeration() throws Exception {
	OWLOntologyManager owlManager = OWLManager
			.createConcurrentOWLOntologyManager();
	// creating an ontology
	final OWLOntology ontology = owlManager.createOntology();
	OWLClass a = factory.getOWLClass(IRI.create("http://example.org/A"));
	OWLClass b = factory.getOWLClass(IRI.create("http://example.org/B"));
	OWLClass c = factory.getOWLClass(IRI.create("http://example.org/C"));
	// ObjectOneOf() = owl:Nothing
	owlManager.addAxiom(ontology,
			factory.getOWLSubClassOfAxiom(a, factory.getOWLObjectOneOf()));
	owlManager.addAxiom(ontology,
			factory.getOWLSubClassOfAxiom(b, factory.getOWLNothing()));
	owlManager.addAxiom(ontology,
			factory.getOWLSubClassOfAxiom(factory.getOWLObjectOneOf(), c));

	final OWLProver prover = OWLAPITestUtils.createProver(ontology);

	prover.precomputeInferences(InferenceType.CLASS_HIERARCHY);

	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(a, b));
	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(b, a));
	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(a, c));
	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(b, c));
}
 
Example #12
Source File: ProofTest.java    From elk-reasoner with Apache License 2.0 5 votes vote down vote up
@Test
public void emptyDisjunction() throws Exception {
	OWLOntologyManager owlManager = OWLManager
			.createConcurrentOWLOntologyManager();
	// creating an ontology
	final OWLOntology ontology = owlManager.createOntology();
	OWLClass a = factory.getOWLClass(IRI.create("http://example.org/A"));
	OWLClass b = factory.getOWLClass(IRI.create("http://example.org/B"));
	OWLClass c = factory.getOWLClass(IRI.create("http://example.org/C"));
	// ObjectUnionOf() = owl:Nothing
	owlManager.addAxiom(ontology, factory.getOWLSubClassOfAxiom(a,
			factory.getOWLObjectUnionOf()));
	owlManager.addAxiom(ontology,
			factory.getOWLSubClassOfAxiom(b, factory.getOWLNothing()));
	owlManager.addAxiom(ontology, factory
			.getOWLSubClassOfAxiom(factory.getOWLObjectUnionOf(), c));

	final OWLProver prover = OWLAPITestUtils.createProver(ontology);

	prover.precomputeInferences(InferenceType.CLASS_HIERARCHY);

	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(a, b));
	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(b, a));
	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(a, c));
	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(b, c));
}
 
Example #13
Source File: ProofTest.java    From elk-reasoner with Apache License 2.0 5 votes vote down vote up
@Test
public void emptyConjunction() throws Exception {
	OWLOntologyManager owlManager = OWLManager
			.createConcurrentOWLOntologyManager();
	// creating an ontology
	final OWLOntology ontology = owlManager.createOntology();
	OWLClass a = factory.getOWLClass(IRI.create("http://example.org/A"));
	OWLClass b = factory.getOWLClass(IRI.create("http://example.org/B"));
	OWLClass c = factory.getOWLClass(IRI.create("http://example.org/C"));
	OWLClass d = factory.getOWLClass(IRI.create("http://example.org/D"));
	// ObjectInteresectionOf() = owl:Thing
	owlManager.addAxiom(ontology, factory.getOWLSubClassOfAxiom(a,
			factory.getOWLObjectIntersectionOf()));
	owlManager.addAxiom(ontology,
			factory.getOWLSubClassOfAxiom(b, factory.getOWLThing()));
	owlManager.addAxiom(ontology, factory.getOWLSubClassOfAxiom(
			factory.getOWLObjectIntersectionOf(), c));
	owlManager.addAxiom(ontology,
			factory.getOWLSubClassOfAxiom(factory.getOWLThing(), d));

	final OWLProver prover = OWLAPITestUtils.createProver(ontology);

	prover.precomputeInferences(InferenceType.CLASS_HIERARCHY);

	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(a, c));
	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(a, d));
	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(b, c));
	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(b, d));
}
 
Example #14
Source File: ProofCompletenessTest.java    From elk-reasoner with Apache License 2.0 5 votes vote down vote up
@Test
public void proofCompletenessTest() throws Exception {

	final OWLDataFactory factory = manager_.getOWLDataFactory();

	// loading and classifying via the OWL API
	final OWLOntology ontology = loadOntology(
			manifest_.getInput().getUrl().openStream());
	final OWLProver prover = OWLAPITestUtils.createProver(ontology);
	try {
		prover.precomputeInferences(InferenceType.CLASS_HIERARCHY);
	} catch (final InconsistentOntologyException e) {
		// we will explain it, too
	}

	try {
		// now do testing

		ProofTestUtils.visitAllSubsumptionsForProofTests(prover, factory,
				new ProofTestVisitor() {

					@Override
					public void visit(final OWLClassExpression subsumee,
							final OWLClassExpression subsumer) {
						ProofTestUtils.proofCompletenessTest(prover, factory
								.getOWLSubClassOfAxiom(subsumee, subsumer));
					}

				});

	} finally {
		prover.dispose();
	}

}
 
Example #15
Source File: ElkReasoner.java    From elk-reasoner with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isPrecomputed(InferenceType inferenceType) {
	LOGGER_.trace("isPrecomputed(InferenceType)");
	if (inferenceType.equals(InferenceType.CLASS_HIERARCHY))
		return reasoner_.doneTaxonomy();
	if (inferenceType.equals(InferenceType.CLASS_ASSERTIONS))
		return reasoner_.doneInstanceTaxonomy();
	if (inferenceType.equals(InferenceType.OBJECT_PROPERTY_HIERARCHY)) {
		return reasoner_.doneObjectPropertyTaxonomy();
	}

	return false;
}
 
Example #16
Source File: ElkReasoner.java    From elk-reasoner with Apache License 2.0 5 votes vote down vote up
@Override
public Set<InferenceType> getPrecomputableInferenceTypes() {
	LOGGER_.trace("getPrecomputableInferenceTypes()");
	return new HashSet<InferenceType>(Arrays.asList(
			InferenceType.CLASS_ASSERTIONS, InferenceType.CLASS_HIERARCHY,
			InferenceType.OBJECT_PROPERTY_HIERARCHY));
}
 
Example #17
Source File: IncrementalClassification.java    From elk-reasoner with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #18
Source File: SavingInferredAxioms.java    From elk-reasoner with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #19
Source File: RetrievingInstances.java    From elk-reasoner with Apache License 2.0 5 votes vote down vote up
/**
 * @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();
}
 
Example #20
Source File: SparqlDLQueryTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void testQuery() 
{
	OWLReasoner reasoner = null;
	try {
		// Create an ontology manager
		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();
		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, true);

		// Some queries which cover important basic language constructs of SPARQL-DL

		// All white wines (all individuals of the class WhiteWine and sub classes thereof)
		processQuery(
				"SELECT * WHERE {\n" +
						"Type(?x, <http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#WhiteWine>)" +
						"}"	
				);

		// The white wines (the individuals of WhiteWine but not of it's sub classes) 
		processQuery(
				"SELECT * WHERE {\n" +
						"DirectType(?x, <http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#RedTableWine>)" +
						"}"
				);

		// Is PinotBlanc a sub class of Wine?
		processQuery(
				"PREFIX wine: <http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#>\n" +
						"ASK {\n" +
						"SubClassOf(wine:PinotBlanc, wine:Wine)" +
						"}"
				);

		// The direct sub classes of FrenchWine
		processQuery(
				"PREFIX wine: <http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#>\n" +
						"SELECT ?x WHERE {\n" +
						"DirectSubClassOf(?x, wine:FrenchWine)" +
						"}"	
				);

		// All individuals
		processQuery(
				"PREFIX wine: <http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#>\n" +
						"SELECT * WHERE {\n" +
						"Individual(?x)" +
						"}"
				);

		// All functional ObjectProperties
		processQuery(
				"PREFIX wine: <http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#>\n" +
						"SELECT * WHERE {\n" +
						"ObjectProperty(?x), " +
						"Functional(?x)" +
						"}"
				);

		// The strict sub classes of DryWhiteWine (sub classes with are not equivalent to DryWhiteWine)
		processQuery(
				"PREFIX wine: <http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#>\n" +
						"SELECT ?x WHERE {\n" +
						"StrictSubClassOf(?x, wine:DryWhiteWine)" +
						"}"
				);

		// All the grapes from which RedTableWines are made from (without duplicates)
		processQuery(
				"PREFIX wine: <http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#>\n" + 
						"SELECT DISTINCT ?v WHERE {\n" +
						"Type(?i, wine:RedTableWine),\n" +
						"PropertyValue(?i, wine:madeFromGrape, ?v)" +
						"}"	
				);

	}
	catch(UnsupportedOperationException exception) {
		System.out.println("Unsupported reasoner operation.");
	}
	catch(OWLOntologyCreationException e) {
		System.out.println("Could not load the wine ontology: " + e.getMessage());
	}
	finally {
		if (reasoner != null) {
			reasoner.dispose();
		}
	}
}
 
Example #21
Source File: LazyExpressionMaterializingReasoner.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public Set<InferenceType> getPrecomputableInferenceTypes() {
	return getWrappedReasoner().getPrecomputableInferenceTypes();
}
 
Example #22
Source File: GraphReasoner.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void precomputeInferences(InferenceType... inferenceTypes)
throws ReasonerInterruptedException, TimeOutException,
InconsistentOntologyException {
	// TODO Auto-generated method stub

}
 
Example #23
Source File: GraphReasoner.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public boolean isPrecomputed(InferenceType inferenceType) {
	// TODO Auto-generated method stub
	return false;
}
 
Example #24
Source File: LazyExpressionMaterializingReasoner.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public boolean isPrecomputed(InferenceType inferenceType) {
	return getWrappedReasoner().isPrecomputed(inferenceType);
}
 
Example #25
Source File: GraphReasoner.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public Set<InferenceType> getPrecomputableInferenceTypes() {
	// TODO Auto-generated method stub
	return null;
}
 
Example #26
Source File: Example_Extended.java    From sparql-dl-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @param args
 */
public static void main(String[] args) 
{
	try {
		// Create our ontology manager in the usual way.
		OWLOntologyManager manager = OWLManager.createOWLOntologyManager();

		// Load a copy of the wine ontology.  We'll load the 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);
		
           // Some queries which demonstrate more sophisticated language constructs of SPARQL-DL

           // The empty ASK is true by default
           processQuery(
			"ASK {}"
		);

           // The response to an empty SELECT is an empty response
           processQuery(
			"SELECT * WHERE {}"
		);

           // There can't be an instance of owl:Nothing. Therefore this query has no solutions.
           processQuery(
               "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n" +
			"SELECT * WHERE { Type(?x,owl:Nothing) }"
		);

           // A complicated way to retrieve all individuals. Note that the WHERE keyword is optional.
           processQuery(
               "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n" +
			"SELECT DISTINCT ?x { Type(?x,?y), ComplementOf(owl:Nothing,?y) }"
		);

           // All wines which are OffDry
           processQuery(
               "PREFIX wine: <http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#>\n" +
               "PREFIX food: <http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#>\n" +
			"SELECT DISTINCT ?w WHERE { PropertyValue(?w, wine:hasWineDescriptor, food:OffDry) }"
		);

           // A query returning pairs of results, namely all sources and fillers of yearValue
           processQuery(
               "PREFIX wine: <http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#>\n" +
			"SELECT DISTINCT ?w ?g WHERE { PropertyValue(?w, wine:yearValue, ?g)" +
			"}"
		);

           // The most specific types of wines of all wineries
           processQuery(
               "PREFIX wine: <http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#>\n" +
			"SELECT DISTINCT ?x ?y WHERE {\n" +
                   "Type(?x, wine:Winery), \n" +
                   "DirectType(?z, ?y), \n" +
                   "PropertyValue(?x, wine:producesWine, ?z)" +
			"}"
		);

           // All entities which are either object properties or classes
		processQuery(
			"SELECT ?i WHERE {" +
			    "ObjectProperty(?i) " +
			"} OR WHERE {" +
                   "Class(?i)" +
               "}"
		);

           // Equivalent query to the one above
           processQuery(
			"SELECT * WHERE {" +
			    "ObjectProperty(?i) " +
			"} OR WHERE {" +
                   "Class(?j)" +
               "}"
		);

       }
       catch(UnsupportedOperationException exception) {
           System.out.println("Unsupported reasoner operation.");
       }
       catch(OWLOntologyCreationException e) {
           System.out.println("Could not load the pizza ontology: " + e.getMessage());
       }
}
 
Example #27
Source File: LazyExpressionMaterializingReasoner.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void precomputeInferences(InferenceType... inferenceTypes)
throws ReasonerInterruptedException, TimeOutException,
InconsistentOntologyException {
	getWrappedReasoner().precomputeInferences(inferenceTypes);
}
 
Example #28
Source File: ProofTest.java    From elk-reasoner with Apache License 2.0 4 votes vote down vote up
@Test
public void proofsUnderOntologyUpdate() throws Exception {
	// loading and classifying via the OWL API
	OWLOntology ontology = loadOntology(
			ProofTest.class.getClassLoader().getResourceAsStream(
					"ontologies/PropertyCompositionsWithHierarchy.owl"));
	final OWLProver prover = OWLAPITestUtils.createProver(ontology);

	prover.precomputeInferences(InferenceType.CLASS_HIERARCHY);

	OWLClass sub = factory.getOWLClass(IRI.create("http://example.org/A"));
	OWLClass sup = factory.getOWLClass(IRI.create("http://example.org/G"));

	// printInferences(reasoner, sub, sup);
	// OWLExpression root =
	// reasoner.getDerivedExpression(factory.getOWLSubClassOfAxiom(sub,
	// sup));
	// System.err.println(OWLProofUtils.printProofTree(root));
	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(sub, sup));

	// now convert C <= R3 some D to C < S3 some D
	OWLClass c = factory.getOWLClass(IRI.create("http://example.org/C"));
	OWLClass d = factory.getOWLClass(IRI.create("http://example.org/D"));
	OWLObjectProperty r3 = factory
			.getOWLObjectProperty(IRI.create("http://example.org/R3"));
	OWLObjectProperty s3 = factory
			.getOWLObjectProperty(IRI.create("http://example.org/S3"));
	OWLAxiom oldAx = factory.getOWLSubClassOfAxiom(c,
			factory.getOWLObjectSomeValuesFrom(r3, d));
	OWLAxiom newAx = factory.getOWLSubClassOfAxiom(c,
			factory.getOWLObjectSomeValuesFrom(s3, d));

	OWLOntologyManager manager = ontology.getOWLOntologyManager();

	manager.applyChanges(Arrays.asList(new RemoveAxiom(ontology, oldAx),
			new AddAxiom(ontology, newAx)));

	prover.precomputeInferences(InferenceType.CLASS_HIERARCHY);

	// printInferences(reasoner, sub, sup);
	// root =
	// reasoner.getDerivedExpression(factory.getOWLSubClassOfAxiom(sub,
	// sup));
	// System.err.println(OWLProofUtils.printProofTree(root));
	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(sub, sup));
}
 
Example #29
Source File: DelegatingOWLReasoner.java    From elk-reasoner with Apache License 2.0 4 votes vote down vote up
@Override
public Set<InferenceType> getPrecomputableInferenceTypes() {
	return delegate_.getPrecomputableInferenceTypes();
}
 
Example #30
Source File: DelegatingOWLReasoner.java    From elk-reasoner with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isPrecomputed(InferenceType inferenceType) {
	return delegate_.isPrecomputed(inferenceType);
}