Skip to content

Commit

Permalink
Merge pull request #1 from ngrewe/refactor/tawny-owl-2.0
Browse files Browse the repository at this point in the history
refactor: Upgrade to tawny-owl 2.3.3 and BFO 2020
  • Loading branch information
ngrewe authored May 24, 2024
2 parents c14b5d6 + d865942 commit 09cf7f1
Show file tree
Hide file tree
Showing 6 changed files with 1,771 additions and 6,871 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies {
implementation 'org.clojure:clojure:1.11.1'
testRuntimeOnly 'dev.clojurephant:jovial:0.4.2'
devImplementation 'org.clojure:tools.namespace:1.3.0'
implementation 'uk.org.russet:tawny-owl:1.4.0'
implementation 'uk.org.russet:tawny-owl:2.3.3'
implementation 'danlentz:clj-uuid:0.1.6'
}

Expand Down
26 changes: 18 additions & 8 deletions src/main/clojure/de/halbordnung/ontologies/tqme/base.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,44 @@
(:require [clj-uuid :as uuid]
[tawny.read :as r]
[tawny.memorise]
[tawny.owl])
[tawny.owl :as o])
(:use tawny.owl)
(:import (org.semanticweb.owlapi.model IRI OWLOntology)))

(defonce ^String bfo-iri "http://purl.obolibrary.org/obo/bfo.owl")

(defn resource-iri "Get a reference to the local BFO copy" ^IRI []
(defonce ^String tawny-iri "http://www.purl.org/ontolink/tawny")


(defn bfo-resource-iri "Get a reference to the local BFO copy" ^IRI []
(IRI/create (clojure.java.io/resource "bfo.owl")))

(defn tawny-resource-iri "Get a reference to the local tawny.owl copy" ^IRI []
(IRI/create (clojure.java.io/resource "tawny.owl")))

(defn -scoped "Generate a v5 UUID in the tqme namespace" [^String n]
; The namespace here must be kept as is in order to keep IRIs stable
(uuid/v5 (uuid/v5 uuid/+namespace-url+ "http://www.halbordnung.de/ontologies/tqc.owl")
n))
(defdontfn iri-generate
(o/defno iri-generate
"Generate IRIs for the determinist names"
[o name]
(iri (str (.getOntologyIRI (.getOntologyID ^OWLOntology o)) "#" (-scoped name))))
(iri (str (.get (.getOntologyIRI (.getOntologyID ^OWLOntology o))) "#" (-scoped name))))

(r/defread bfo
:location (resource-iri)
:location (bfo-resource-iri)
:prefix "bfo"
:iri bfo-iri
:viri "http://purl.obolibrary.org/obo/bfo/2014-05-03/bfo.owl"
:viri "http://purl.obolibrary.org/obo/bfo/2020/bfo.owl"
:filter
(clojure.core/partial tawny.read/iri-starts-with-filter "http://purl.obolibrary.org/obo/BFO")
:transform
(clojure.core/comp r/stop-characters-transform
r/exception-nil-label-transform))
(tawny.memorise/remember bfo (clojure.java.io/resource "bfo_memo.clj"))

(tawny.memorise/remember (clojure.java.io/resource "bfo_memo.clj"))

(r/defread tawny
:location (tawny-resource-iri)
:prefix "tawny"
:iri tawny-iri
)
118 changes: 86 additions & 32 deletions src/main/clojure/de/halbordnung/ontologies/tqme/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
:iri-gen b/iri-generate)

(owl-import b/bfo)
(owl-import b/tawny)

(defclass tqme
:label "temporally qualified material entity"
Expand All @@ -22,7 +23,7 @@
)
)

(add-superclass b/material_entity tqme)
(add-superclass tqme-ontology b/material_entity tqme)

(defclass phase
:label "minimal history segment"
Expand All @@ -40,12 +41,8 @@
" (they only occur at instants)"
" * They pertain to a single entity."))

;; Match the history axiom
(add-superclass phase (owl-only b/part_of_occurrent (owl-not b/process_profile)))

(defoproperty phase-of
:label "minimal history segment of"
:super b/specifically_depends_on_at_all_times
:domain phase
:range tqme
:characteristic :functional)
Expand All @@ -55,12 +52,12 @@
:inverse phase-of
:characteristic :inversefunctional)

(as-equivalent phase (owl-and (owl-some b/part_of_occurrent b/history)
(as-equivalent phase (owl-and (owl-some b/occurrent_part_of b/history)
(owl-some b/exists_at b/zero-dimensional_temporal_region)))

(add-superclass phase (owl-some phase-of o/owl-thing))
(add-superclass tqme-ontology phase (owl-some phase-of o/owl-thing))

(add-superclass b/material_entity (owl-some b/has_history b/history))
(add-superclass tqme-ontology b/material_entity (owl-some b/has_history b/history))


(defoproperty has-min-tqme
Expand All @@ -71,7 +68,7 @@
)
)

(add-subchain has-min-tqme [b/has_history b/has_occurrent_part phase-of])
(add-subchain tqme-ontology has-min-tqme [b/has_history b/has_occurrent_part phase-of])

(defoproperty min-tqme-of
:label "minimal temporally qualified material entity of"
Expand All @@ -84,23 +81,47 @@
:comment "the relation between a temporally qualified material entity and a maximal one"
)

(add-subchain has-max-tqme [has-phase b/part_of_occurrent b/history_of])
(add-subchain tqme-ontology has-max-tqme [has-phase b/occurrent_part_of b/history_of])

(defoproperty max-tqme-of
:label "maximal material entity of"
:domain b/material_entity
:inverse has-max-tqme)

(add-subproperty min-tqme-of has-max-tqme)
(add-subproperty has-min-tqme max-tqme-of)
(add-subproperty tqme-ontology min-tqme-of has-max-tqme)
(add-subproperty tqme-ontology has-min-tqme max-tqme-of)

;; we steal a bit of stuff from tawny.owl to build our generators
(defmontfn
(defn
guess-type-args
{:doc "Broadcasting version of guess-type"
{:doc "Broadcasting version of guess-type"
:private true}
[o & args]
(guess-type o args))
;; unwind to avoid variadic args for the most common calls.
([a]
(guess-type a))
([a b]
(or
(guess-type a)
(guess-type b)))
([a b c]
(or
(guess-type a)
(guess-type b)
(guess-type c)))
([a b c d]
(or
(guess-type a)
(guess-type b)
(guess-type c)
(guess-type d)))
([a b c d & args]
(or
(guess-type a)
(guess-type b)
(guess-type c)
(guess-type d)
;; guess-type already copes with collections
(guess-type args))))

(defmulti phase-perm-spec
"Returns a restriction on an phase that is scoped as permanently specific"
Expand All @@ -114,47 +135,80 @@
(defmethod phase-perm-spec nil [& rest]
(apply guess-type-error rest))

(defmontfn ophase-perm-spec
(defno ophase-perm-spec
{:doc "Returns a restriction on an phase that is scoped as permanently specific."
:arglists '([& clazzes] [ontology & clazzes])}
[o class]
(owl-some o phase-of class))
(owl-some phase-of class))

(defmethod phase-perm-spec :tawny.owl/object [& rest]
(apply ophase-perm-spec rest))


(defmontfn object-perm-spec
(defno object-perm-spec
{:doc "Returns a restriction on a material entity that is scoped as permanently specific."
:arglists '([& clazzes] [ontology & clazzes])}
[o class]
(owl-some o b/has_history (phase-perm-spec o class)))
(owl-some b/has_history (phase-perm-spec o class)))

(defn perm-spec
[o class]
[class]
class)

(defn temp
[o ctor relation class]
(owl-some o
[ctor relation class]
(owl-some
has-max-tqme
(owl-some o
(owl-some
has-min-tqme
(ctor o
(ctor
relation
(owl-some o min-tqme-of class)
(owl-some min-tqme-of class)
)
)
)
)

(defn perm-gen
[o ctor relation class]
[ctor relation class]
(owl-and
(owl-some o has-min-tqme
(ctor o relation (owl-some o min-tqme-of class)))
(owl-only o has-min-tqme
(ctor o relation (owl-some o min-tqme-of class)))
(owl-some has-min-tqme
(ctor relation (owl-some min-tqme-of class)))
(owl-only has-min-tqme
(ctor relation (owl-some min-tqme-of class)))

)
)
)

(defn perm-gen-full
[ctor relation class]
(owl-and
(owl-some b/has_history
(owl-some b/has_occurrent_part
(owl-some has-phase
(ctor relation
(owl-some phase-of
(owl-some b/occurrent_part_of
(owl-some b/history_of class)
)
)
)
)
)
)
(owl-only b/has_history
(owl-only b/has_occurrent_part
(owl-only has-phase
(ctor relation
(owl-some phase-of
(owl-some b/occurrent_part_of
(owl-some b/history_of class)
)
)
)
)
)
)

)
)
Loading

0 comments on commit 09cf7f1

Please sign in to comment.