Created
June 5, 2014 13:45
-
-
Save kowey/e1bef02fde8eb9e003e1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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