Menu

Tree [cbaff8] main /
 History

HTTPS access


File Date Author Commit
 doc 2020-10-21 Kody Moodley Kody Moodley [68ff2c] initial commit
 src 2020-10-21 Kody Moodley Kody Moodley [68ff2c] initial commit
 .gitignore 2020-10-21 Kody Moodley Kody Moodley [68ff2c] initial commit
 LICENSE.md 2020-10-21 Kody Moodley Kody Moodley [68ff2c] initial commit
 README.md 2020-10-21 Kody Moodley Kody Moodley [cbaff8] Update README.md
 pom.xml 2020-10-21 Kody Moodley Kody Moodley [68ff2c] initial commit

Read Me

simpleOWLAPI

simpleOWLAPI is a light-weight wrapper for the OWLAPI that enables faster development of OWL ontologies with more concise code using the power of the Manchester OWL Syntax and related parsers. The wrapper does not make use of all the features of the more powerful OWLAPI. Rather, it is designed specifically for rapid and concise ontology construction in workflows involving semantic data engineering. It can also be used in contexts such as educational and demonstration settings in courses, workshops and tutorials. In particular, the library can also be used in Jupyter notebooks using a Java kernel such as the IJava kernel.

Usage in Jupyter notebooks

Requirements
  1. Jupyter notebooks
  2. IJava Jupyter kernel
  3. Java JDK 1.9+ linked to your IJava kernel
Importing

When using simpleOWLAPI with Jupyter notebooks using the IJava kernel, importing the library using %maven and %%loadFromPOM magics is known to cause problems due to .ivy2 caching conflicts. The solution is to download the .jar file of simpleOWLAPI with packaged dependencies from the releases section and import this file manually into your IJava notebook by running the %jars path/to/jar/file/simpleowlapi-[version].jar command from a single dedicated cell in the notebook.

Dependencies

The simpleOWLAPI release for Jupyter notebooks is bundled into one .jar file for convenience. This file includes the following dependencies (see pom.xml for specific versions):

  1. The OWL API released under both the GNU Lesser General Public License (LGPL) and the Apache 2.0 License.
  2. The HermiT OWL reasoner released under the GNU Lesser General Public License (LGPL).
  3. The JFact OWL reasoner released under the GNU Lesser General Public License (LGPL).
  4. The Pellet OWL reasoner released under a dual license GNU Affero for open source usage and under commercial licenses for commercial usage - in the latter case, the developers of Pellet need to be contacted.
  5. The ELK OWL reasoner released under the Apache 2.0 License.
Usage

For more information on how to use simpleOWLAPI, see the Javadocs and examples below.

Example usage: ontology editing

import org.semanticweb.owl.simpleowlapi.*;
import org.semanticweb.owlapi.model.*;

SimpleOWLAPIFactory s = SimpleOWLAPIFactory.getInstance(); // create a new SimpleOWLAPIFactory instance which allows the construction and manipulation of OWL ontologies (default OWL reasoner is JFACT)
SimpleOWLAPIFactory s2 = SimpleOWLAPIFactory.getInstance(SelectedReasoner.PELLET); // create a new SimpleOWLAPIFactory instance with the specified reasoner e.g. PELLET set for use
s.createOntology("http://com.kodymoodley/ontologies/2020/testontology#"); // create a new OWL ontology by specifying an IRI string and set it to the currently selected (active) ontology
s.createClasses("Penguin Peacock Bird Robin FlyingOrganism Fish Wing"); // create multiple class names (each separated by a space) and add them to the currently selected ontology
s.createOProperties("hasPart isPartOf hasGender knows eats hunts"); // create multiple object properties (each separated by a space) and add them to the currently selected ontology
s.createIndividuals("tweety woody nemo sharky sheila feather1"); // create multiple named individuals (each separated by a space) and add them to the currently selected ontology
s.createDProperties("hasWeight name bornOn"); // create multiple data properties (each separated by a space) and add them to the currently selected ontology

s.makeTransitive("eats"); // make an object property transitive
s.makeSymmetric("knows"); // make an object property symmetric
s.makeIRReflexive("hasGender"); // make an object property irreflexive
s.makeAntiSymmetric("hasGender"); // make an object property asymmetric

s.setFullIRIRendering(true); // set whether to render OWL entities (classes, individuals, properties, axioms etc.) using full IRIs or shortform label

s.createAxiom("tweety Type: hasWeight value \"300.56\"^^xsd:double"); // create an OWL data property assertion axiom and add it to the currently selected ontology
s.createAxiom("tweety Type: hasGender exactly 1 Gender"); // create an OWL class assertion axiom and add it to the currently selected ontology
s.createAxiom("woody Type: knows value nemo"); // create an OWL object property assertion axiom and add it to the currently selected ontology

s.createAxiom("eats subPropertyOf: hunts"); // create OWL subPropertyOf axiom and add it to the currently selected ontology
s.createAxiom("isPartOf inverseOf: hasPart"); // create inverse object property axiom and add it to the currently selected ontology
s.createAxiom("knows Domain: Person"); // create object property domain axiom and add it to the currently selected ontology
s.createAxiom("knows Range: Person"); // create object property range axiom and add it to the currently selected ontology

s.createAxiom("Penguin subClassOf eats some Fish"); // create OWL subClassOf axiom and add it to the currently selected ontology
s.createAxiom("Gender equivalentTo: Male or Female"); // create OWL equivalent classes axiom and add it to the currently selected ontology
s.createAxiom("Male disjointWith: Female"); // create OWL equivalent classes axiom and add it to the currently selected ontology
s.createAxiom("{tweety,woody} subClassOf Bird"); // create an OWL subClassOf axiom using nominals and add it to the currently selected ontology

s.createOntology("http://com.kodymoodley/ontologies/2020/testontology2#");
s.setOntology("http://com.kodymoodley/ontologies/2020/testontology2#"); // set / switch the "active" or currently selected ontology by specifying the IRI of the ontology to switch to
s.getOntology(); // prints to console the IRI of the currently selected ontology
s.getOntologies(); // prints to console the IRIs of all ontologies created / loaded within the current context (instance of the simpleOWLAPIFactory)
s.printOntology(); // prints to console a structured representation of the main OWL entities in the ontology
s.printOntologyStats(); // prints ontology metrics (e.g. number of classes, axioms of a certain type etc.)

s.saveOntology("testontology.owl"); // save currently selected ontology to local file using Manchester OWL syntax
s.loadFromURL("https://protege.stanford.edu/ontologies/pizza/pizza.owl"); // load an ontology into this context from a remote URL
s.loadFromFile("path/to/ontology.owl"); // load an ontology into this context from a local file path. WARNING: you cannot load multiple ontologies with the same IRI into the same context!
s.removeOntology(); // remove selected ontology from current context (simpleOWLAPIFactory instance) 
s.removeOntology("http://com.kodymoodley/ontologies/2020/testontology2#"); // remove ontology with specified IRI from current context (simpleOWLAPIFactory instance) 

s.resetOntology(); // remove all axioms from the currently selected ontology
s.removeClasses("Bird Penguin"); // remove multiple class names from currently selected ontology
s.removeOProperties("knows hasPart"); // remove multiple object properties from currently selected ontology
s.removeDProperties("hasWeight name"); // remove multiple data properties from currently selected ontology
s.removeIndividuals("tweety woody"); // remove multiple individual names from currently selected ontology
s.removeAxiom("Penguin subClassOf eats some Fish"); // remove an axiom from the currently selected ontology

Example usage: reasoning

SimpleOWLAPIFactory s = SimpleOWLAPIFactory.getInstance();

...

s.setOWLReasoner(SelectedReasoner.HERMIT); // Switch or set OWL reasoner 

s.owlReasoner.isConsistent(); // prints to console Yes if currently selected ontology is consistent, No otherwise
s.owlReasoner.explainInconsistency(); // computes and prints to console all explanations for the inconsistency of the selected ontology (provided it is inconsistent)

s.owlReasoner.isSatisfiable("Penguin"); // prints to console Yes if the given class expression is satisfiable, No otherwiseNo otherwise
s.owlReasoner.explainUnsatisfiability("Penguin"); // computes and prints to console all explanations for the unsatisfiability of the given class expression w.r.t. the selected ontology (provided it is indeed unsatisfiable)

s.owlReasoner.isEntailed("Robin subClassOf FlyingOrganism"); // prints to console Yes if the given axiom is entailed by the currently selected ontology, No otherwise
s.owlReasoner.explainEntailment("Robin subClassOf FlyingOrganism"); // computes and prints to console all explanations for the entailment of the given axiom w.r.t. the selected ontology (provided it is indeed entailed)

s.owlReasoner.getSuperClasses("Robin"); // computes and prints to console all super classes (indirect) for the given class expression
s.owlReasoner.getSubClasses("FlyingOrganism"); // computes and prints to console all sub classes (indirect) for the given class expression

s.owlReasoner.getTypes("tweety"); // computes and prints to console all class names for which the given individual is an instance
s.owlReasoner.getAllTypes(); // for each individual name in the selected ontology, computes and prints to console all class names such that this individual is an instance of the class name

s.owlReasoner.getOPropertyAssertions("knows"); // given an object property name R, prints to console all individual name pairs (a,b) such that R(a, b) is an object property assertion entailed by the selected ontology
s.owlReasoner.getAllOPropertyAssertions(); // for each object property R in the ontology, prints to console all individual name pairs (a,b) such that R(a, b) is an object property assertion entailed by the selected ontology

s.owlReasoner.getName(); // prints to console the name of the OWL reasoner which is currently being used by the simpleOWLAPIFactory instance
s.owlReasoner.getOWLProfile(); // prints to console the name of the OWL 2 profile which the selected OWL reasoner supports

For Developers: Building the library from source

Requirements:
  • Apache's Maven.
  • A tool for checking out a Git repository.
Steps:
  1. Get a copy of the code:

    git clone https://github.com/kodymoodley/simpleowlapi.git
    
  2. Change into the simpleowlapi/ directory.

  3. Type mvn clean package. On build completion, the target/ directory will contain two versions of the library: simpleowlapi-${version}.jar and simpleowlapi-${version}-jar-with-dependencies.jar.

License and contributions

The simpleOWLAPI library is copyrighted by Kody Moodley and released under the GNU Affero License.

Contributions and bug reports are helpful and welcome.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.