Skip to content

Instantly share code, notes, and snippets.

@kowey
Created June 5, 2014 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kowey/e1bef02fde8eb9e003e1 to your computer and use it in GitHub Desktop.
Save kowey/e1bef02fde8eb9e003e1 to your computer and use it in GitHub Desktop.
ckage org.ontologyengineering.owltoy;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.util.DefaultPrefixManager;
import java.io.File;
/**
* Create a simple ontology with a few classes, a property, and an
* object property restriction
*/
public class Main {
public static void simpleOntology() throws OWLOntologyCreationException, OWLOntologyStorageException {
final OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
final OWLDataFactory factory = manager.getOWLDataFactory();
final OWLOntology ontology = manager.createOntology();
final PrefixManager pm = new DefaultPrefixManager(
"http://ontologyengineering.org/example/owltoy#");
final OWLClass clsLecturer = factory.getOWLClass(":Lecturer", pm);
final OWLClass clsModule = factory.getOWLClass(":Module", pm);
final OWLProperty propTeaches = factory.getOWLObjectProperty(":teaches", pm);
final OWLObjectPropertyExpression propExpTeaches =
factory.getOWLObjectProperty(":teaches", pm);
// ∀ teaches . Module
final OWLClassExpression clsExpTeachesOnlyModules =
factory.getOWLObjectAllValuesFrom(propExpTeaches, clsModule);
manager.addAxiom(ontology,
factory.getOWLDeclarationAxiom(clsLecturer));
manager.addAxiom(ontology,
factory.getOWLDeclarationAxiom(clsModule));
manager.addAxiom(ontology,
factory.getOWLDeclarationAxiom(propTeaches));
manager.addAxiom(ontology, // Lecturer ⊑ ∀ teaches . Module
factory.getOWLSubClassOfAxiom(clsLecturer, clsExpTeachesOnlyModules));
final File file = new File("/tmp/local.owl");
manager.saveOntology(ontology, IRI.create(file.toURI()));
}
public static void main(String [] args) throws Exception {
simpleOntology();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment