org.semanticweb.owlapi.reasoner.structural.StructuralReasonerFactory Java Examples
The following examples show how to use
org.semanticweb.owlapi.reasoner.structural.StructuralReasonerFactory.
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: QueryEngineStrictModeTest.java From sparql-dl-api with GNU Lesser General Public License v3.0 | 6 votes |
@BeforeClass public static void oneTimeSetUp() { try { // Create our ontology manager in the usual way. manager = OWLManager.createOWLOntologyManager(); OWLOntology ont = manager.loadOntologyFromOntologyDocument(IRI.create("http://www.w3.org/TR/owl-guide/wine.rdf")); // We need to create an instance of Reasoner. StructuralReasonerFactory factory = new StructuralReasonerFactory(); reasoner = factory.createReasoner(ont); reasoner.precomputeInferences(); } catch(UnsupportedOperationException exception) { System.out.println("Unsupported reasoner operation."); } catch(OWLOntologyCreationException e) { System.out.println("Could not load the wine ontology: " + e.getMessage()); } }
Example #2
Source File: OntologyHelper.java From BioSolr with Apache License 2.0 | 5 votes |
/** * Construct a new ontology helper instance. * * @param ontologyUri the URI giving the location of the ontology. * @param config the ontology configuration, containing the property URIs * for labels, synonyms, etc. * @throws OWLOntologyCreationException if the ontology cannot be read for * some reason - internal inconsistencies, etc. * @throws URISyntaxException if the URI cannot be parsed. */ public OntologyHelper(URI ontologyUri, OntologySettings config) throws OWLOntologyCreationException, URISyntaxException { this.config = config; if (!ontologyUri.isAbsolute()) { // Try to read as a file from the resource path LOGGER.debug("Ontology URI {} is not absolute - loading from classpath", ontologyUri); URL url = this.getClass().getClassLoader().getResource(ontologyUri.toString()); if (url != null) { ontologyUri = url.toURI(); } } this.ontologyUri = ontologyUri; LOGGER.info("Loading ontology from " + ontologyUri + "..."); OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); IRI iri = IRI.create(ontologyUri); this.ontology = manager.loadOntologyFromOntologyDocument(iri); // Use a buffering reasoner - not interested in ongoing changes this.reasoner = new StructuralReasonerFactory().createReasoner(ontology); // this.shortFormProvider = new SimpleShortFormProvider(); this.owlNothingIRI = manager.getOWLDataFactory().getOWLNothing().getIRI(); // Initialise the class map initialiseClassMap(); }
Example #3
Source File: OWLDataManager.java From BioSolr with Apache License 2.0 | 5 votes |
/** * Get the reasoner that should be used to access the ontology. * @return the reasoner. * @throws OntologyHelperException if the ontology is not available. */ public OWLReasoner getReasoner() throws OntologyHelperException { if (reasoner == null) { reasoner = new StructuralReasonerFactory().createReasoner(getOntology()); } return reasoner; }
Example #4
Source File: Example_Extended.java From sparql-dl-api with GNU Lesser General Public License v3.0 | 4 votes |
/** * @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 #5
Source File: Example_Basic.java From sparql-dl-api with GNU Lesser General Public License v3.0 | 4 votes |
/** * @param args */ public static void main(String[] args) { 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(); 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, 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()); } }
Example #6
Source File: Example_XML_JSON.java From sparql-dl-api with GNU Lesser General Public License v3.0 | 4 votes |
/** * @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()); } }
Example #7
Source File: SparqlDLQueryTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
@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(); } } }