-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to make look more like the OWL API
The spec and the OWL use different names as far as I can see. But the OWL API looks more like the XML serialization. Currently broken
- Loading branch information
Showing
13 changed files
with
547 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
(clojure.core/load-file "ontology.clj") | ||
|
||
|
||
(defclass A) | ||
(defclass B) | ||
|
||
(clojure.core/let [ | ||
df (owl-data-factory) | ||
|
||
var (.getSWRLVariable | ||
df | ||
(iri-for-name o "x")) | ||
] | ||
(.applyChange | ||
(owl-ontology-manager) | ||
(org.semanticweb.owlapi.model.AddAxiom. | ||
o | ||
(.getSWRLRule | ||
df | ||
#{(.getSWRLClassAtom df A var)} | ||
#{(.getSWRLClassAtom df B var)})))) | ||
|
||
;; OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); | ||
;; // Let's create an ontology and name it | ||
;; // "http://www.co-ode.org/ontologies/testont.owl" We need to set up a | ||
;; // mapping which points to a concrete file where the ontology will be | ||
;; // stored. (It's good practice to do this even if we don't intend to | ||
;; // save the ontology). | ||
;; IRI ontologyIRI = IRI.create("http://www.co-ode.org/ontologies/", "testont.owl"); | ||
;; // Create a document IRI which can be resolved to point to where our | ||
;; // ontology will be saved. | ||
;; IRI documentIRI = IRI.create("file:/tmp/", "SWRLTest.owl"); | ||
;; // Set up a mapping, which maps the ontology to the document IRI | ||
;; SimpleIRIMapper mapper = new SimpleIRIMapper(ontologyIRI, documentIRI); | ||
;; manager.getIRIMappers().add(mapper); | ||
;; // Now create the ontology - we use the ontology IRI (not the physical | ||
;; // IRI) | ||
;; OWLOntology ontology = manager.createOntology(ontologyIRI); | ||
;; OWLDataFactory factory = manager.getOWLDataFactory(); | ||
;; // Get hold of references to class A and class B. Note that the ontology | ||
;; // does not contain class A or classB, we simply get referenc/mes to | ||
;; // objects from a data factory that represent class A and class B | ||
;; OWLClass classA = factory.getOWLClass(ontologyIRI + "#", "A"); | ||
;; OWLClass classB = factory.getOWLClass(ontologyIRI + "#", "B"); | ||
;; SWRLVariable var = factory.getSWRLVariable(ontologyIRI + "#", "x"); | ||
;; SWRLRule rule = | ||
;; factory.getSWRLRule(Collections.singleton(factory.getSWRLClassAtom(classA, var)), | ||
;; Collections.singleton(factory.getSWRLClassAtom(classB, var))); | ||
;; manager.applyChange(new AddAxiom(ontology, rule)); | ||
;; OWLObjectProperty objProp = factory.getOWLObjectProperty(ontologyIRI + "#", "propA"); | ||
;; OWLObjectProperty propB = factory.getOWLObjectProperty(ontologyIRI + "#", "propB"); | ||
;; SWRLObjectPropertyAtom propAtom = factory.getSWRLObjectPropertyAtom(objProp, var, var); | ||
;; SWRLObjectPropertyAtom propAtom2 = factory.getSWRLObjectPropertyAtom(propB, var, var); | ||
;; Set<SWRLAtom> antecedent = new HashSet<SWRLAtom>(); | ||
;; antecedent.add(propAtom); | ||
;; antecedent.add(propAtom2); | ||
;; SWRLRule rule2 = factory.getSWRLRule(antecedent, Collections.singleton(propAtom)); | ||
;; manager.applyChange(new AddAxiom(ontology, rule2)); | ||
;; // Now save the ontology. The ontology will be saved to the location | ||
;; // where we loaded it from, in the default ontology format | ||
;; manager.saveOntology(ontology); | ||
|
||
|
||
(save-all) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
(clojure.core/load-file "ontology.clj") | ||
|
||
|
||
(defclass A) | ||
(defclass A1) | ||
(defclass B) | ||
(defclass B1) | ||
|
||
(clojure.core/let [df (owl-data-factory) | ||
var (.getSWRLVariable | ||
df | ||
(iri-for-name o "x"))] | ||
(.applyChange | ||
(owl-ontology-manager) | ||
(org.semanticweb.owlapi.model.AddAxiom. | ||
o | ||
(.getSWRLRule | ||
df | ||
#{(.getSWRLClassAtom df A var)(.getSWRLClassAtom df A1 var)} | ||
#{(.getSWRLClassAtom df B var)(.getSWRLClassAtom df B1 var)})))) | ||
|
||
|
||
|
||
(save-all) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?xml version="1.0"?> | ||
<rdf:RDF xmlns="http://www.example.com/iri#" | ||
xml:base="http://www.example.com/iri" | ||
xmlns:o="http://www.example.com/iri#" | ||
xmlns:owl="http://www.w3.org/2002/07/owl#" | ||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | ||
xmlns:xml="http://www.w3.org/XML/1998/namespace" | ||
xmlns:xsd="http://www.w3.org/2001/XMLSchema#" | ||
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" | ||
xmlns:swrl="http://www.w3.org/2003/11/swrl#" | ||
xmlns:swrlb="http://www.w3.org/2003/11/swrlb#"> | ||
<owl:Ontology rdf:about="http://www.example.com/iri"> | ||
<owl:versionIRI rdf:resource="http://www.example.com/viri"/> | ||
</owl:Ontology> | ||
|
||
|
||
|
||
<!-- | ||
/////////////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Classes | ||
// | ||
/////////////////////////////////////////////////////////////////////////////////////// | ||
--> | ||
|
||
|
||
|
||
|
||
<!-- http://www.example.com/iri#A --> | ||
|
||
<owl:Class rdf:about="http://www.example.com/iri#A"/> | ||
|
||
|
||
|
||
<!-- http://www.example.com/iri#B --> | ||
|
||
<owl:Class rdf:about="http://www.example.com/iri#B"/> | ||
|
||
|
||
|
||
<!-- | ||
/////////////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Rules | ||
// | ||
/////////////////////////////////////////////////////////////////////////////////////// | ||
--> | ||
|
||
<rdf:Description rdf:about="http://www.example.com/iri#x"> | ||
<rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#Variable"/> | ||
</rdf:Description> | ||
<rdf:Description> | ||
<rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#Imp"/> | ||
<swrl:body> | ||
<rdf:Description> | ||
<rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#AtomList"/> | ||
<rdf:first> | ||
<rdf:Description> | ||
<rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#ClassAtom"/> | ||
<swrl:classPredicate rdf:resource="http://www.example.com/iri#A"/> | ||
<swrl:argument1 rdf:resource="http://www.example.com/iri#x"/> | ||
</rdf:Description> | ||
</rdf:first> | ||
<rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/> | ||
</rdf:Description> | ||
</swrl:body> | ||
<swrl:head> | ||
<rdf:Description> | ||
<rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#AtomList"/> | ||
<rdf:first> | ||
<rdf:Description> | ||
<rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#ClassAtom"/> | ||
<swrl:classPredicate rdf:resource="http://www.example.com/iri#B"/> | ||
<swrl:argument1 rdf:resource="http://www.example.com/iri#x"/> | ||
</rdf:Description> | ||
</rdf:first> | ||
<rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/> | ||
</rdf:Description> | ||
</swrl:head> | ||
</rdf:Description> | ||
</rdf:RDF> | ||
|
||
|
||
|
||
<!-- Generated by the OWL API (version 4.5.19) https://github.com/owlcs/owlapi --> | ||
|
Oops, something went wrong.