From 6de76f50c571f1e37db041638481c7e81d897d57 Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Sat, 22 Jul 2023 19:45:44 +0200 Subject: [PATCH 1/6] mvoe test to correct place & reflect renaming --- .../activitystreams2_legacy_test.clj} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/test/clj/org/domaindrivenarchitecture/{activitystreams2_test.clj => activity_pub_poc/activitystreams2_legacy_test.clj} (93%) diff --git a/src/test/clj/org/domaindrivenarchitecture/activitystreams2_test.clj b/src/test/clj/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2_legacy_test.clj similarity index 93% rename from src/test/clj/org/domaindrivenarchitecture/activitystreams2_test.clj rename to src/test/clj/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2_legacy_test.clj index cbedaec..5719928 100644 --- a/src/test/clj/org/domaindrivenarchitecture/activitystreams2_test.clj +++ b/src/test/clj/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2_legacy_test.clj @@ -1,9 +1,9 @@ -(ns org.domaindrivenarchitecture.activity-pub-poc.activitystreams2-test +(ns org.domaindrivenarchitecture.activity-pub-poc.activitystreams2-legacy-test (:require [clojure.test :refer [deftest is are testing run-tests]] [clojure.spec.test.alpha :as st] [clojure.spec.alpha :as s] - [org.domaindrivenarchitecture.activity-pub-poc.activitystreams2 :as sut])) + [org.domaindrivenarchitecture.activity-pub-poc.activitystreams2-legacy :as sut])) (deftest id-test (is (s/valid? ::sut/id "https://social.bla/alyssa/status/RANDOMHASH"))) From 8a028651927fc82278db8060a3f80cfae2c87596 Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Sat, 22 Jul 2023 19:46:09 +0200 Subject: [PATCH 2/6] mv test to correct place --- .../activity_pub_poc}/activitystreams2_test.clj | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) rename src/test/cljc/org/{ => domaindrivenarchitecture/activity_pub_poc}/activitystreams2_test.clj (64%) diff --git a/src/test/cljc/org/activitystreams2_test.clj b/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2_test.clj similarity index 64% rename from src/test/cljc/org/activitystreams2_test.clj rename to src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2_test.clj index 5944812..08f784d 100644 --- a/src/test/cljc/org/activitystreams2_test.clj +++ b/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2_test.clj @@ -5,5 +5,6 @@ [clojure.spec.alpha :as s] [org.domaindrivenarchitecture.activity-pub-poc.activitystreams2 :as sut])) -(deftest id-test - (is true)) \ No newline at end of file +(deftest shoult-test-spec-for-having-functional-property + (is (sut/is-functional-property? ::sut/id)) + (is (not (sut/is-functional-property? ::sut/Like)))) \ No newline at end of file From e70edd2f9c6ba94846255c82c734b4597992e857 Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Sat, 22 Jul 2023 19:46:55 +0200 Subject: [PATCH 3/6] did some cool spec work --- project.clj | 3 +- .../activity_pub_poc/activitystreams2.cljc | 44 ++++++++++++++++--- .../activity_pub_poc/owl.cljc | 20 ++++++++- .../activity_pub_poc/owl_test.cljc | 14 ++++++ 4 files changed, 71 insertions(+), 10 deletions(-) create mode 100644 src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/owl_test.cljc diff --git a/project.clj b/project.clj index 093ce80..4084f5e 100644 --- a/project.clj +++ b/project.clj @@ -25,6 +25,7 @@ [org.clojars.quoll/raphael "0.1.6"] [instaparse "1.4.12"]] :main ^:skip-aot org.domaindrivenarchitecture.activity-pub-poc.core - :profiles {:test {:test-paths ["src/test/clj"] + :profiles {:test {:test-paths ["src/test/cljc" + "src/test/clj"] :resource-paths ["src/test/resources"] :dependencies [[dda/data-test "0.1.1"]]}}) diff --git a/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2.cljc b/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2.cljc index 71b718a..a4bffa9 100644 --- a/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2.cljc +++ b/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2.cljc @@ -1,12 +1,42 @@ (ns org.domaindrivenarchitecture.activity-pub-poc.activitystreams2 (:require [clojure.spec.alpha :as s] + [orchestra.core :refer [defn-spec]] [org.domaindrivenarchitecture.activity-pub-poc.owl :as owl] - [org.domaindrivenarchitecture.activity-pub-poc.rdf :as rdf] - [org.domaindrivenarchitecture.activity-pub-poc.core :as core])) + [org.domaindrivenarchitecture.activity-pub-poc.xsd :as xsd])) + +(defn-spec + is-functional-property? boolean? + "Checks whether spec is a FunctionalProperty." + [spec keyword?] + (some #(clojure.string/includes? % "FunctionalProperty") (s/describe spec))) ;http://www.w3.org/ns/activitystreams#id -;TODO: how do we translate this? rdfs:domain [a owl:Class ; owl:unionOf (as:Link as:Object)] -(s/def ::id (s/and ::owl/FunctionalProperty - ::owl/DatatypeProperty - ::owl/DeprecatedProperty - core/uri-string?)) +(s/def + ::id (s/and ::owl/DatatypeProperty + ::owl/FunctionalProperty + ::owl/DeprecatedProperty + ::xsd/anyURI)) + +;http://www.w3.org/ns/activitystreams#attachment +;TODO: definition in progress +(s/def ::attachment + (s/and ::owl/ObjectProperty)) + +;http://www.w3.org/ns/activitystreams#result +;TODO: definition in progress +(s/def ::result + (s/and ::owl/ObjectProperty)) + +;http://www.w3.org/ns/activitystreams#Object +;TODO: definition in progress +(s/def ::Object (s/keys :opt-un [::attachment])) + +;http://www.w3.org/ns/activitystreams#Activity +;TODO: definition in progress +(s/def ::Activity + (s/and ::Object + (s/keys :opt-un [::result]))) + +;http://www.w3.org/ns/activitystreams#Like +(s/def ::Like ::Activity) + diff --git a/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/owl.cljc b/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/owl.cljc index 20cd38a..7afe811 100644 --- a/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/owl.cljc +++ b/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/owl.cljc @@ -1,7 +1,9 @@ (ns org.domaindrivenarchitecture.activity-pub-poc.owl "A swallow spec translation implementation of owl. Inheritance of FunctionalProperty is realized in deep implemented." - (:require [clojure.spec.alpha :as s])) + (:require + [clojure.spec.alpha :as s] + [orchestra.core :refer [defn-spec]])) ; Properties:https://www.w3.org/TR/owl-ref/#Property ; * Datatype properties link individuals to data values. @@ -15,8 +17,22 @@ ;http://www.w3.org/2002/07/owl#FunctionalProperty ;https://www.w3.org/TR/owl-ref/#FunctionalProperty-def -(s/def ::FunctionalProperty any?) +(defn-spec + functional? boolean? + [elem any?] + (and + (some? elem) + (or + (not (coll? elem)) + (and (vector? elem) (= 1 (count elem))) + (and (list? elem) (= 1 (count elem)))))) +(s/def ::FunctionalProperty functional?) ;http://www.w3.org/2002/07/owl#DeprecatedProperty ;https://www.w3.org/TR/owl-ref/#Deprecation (s/def ::DeprecatedProperty any?) + + +;http://www.w3.org/2002/07/owl#ObjectProperty +;https://www.w3.org/TR/owl-ref/#ObjectProperty +(s/def ::ObjectProperty any?) \ No newline at end of file diff --git a/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/owl_test.cljc b/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/owl_test.cljc new file mode 100644 index 0000000..427751f --- /dev/null +++ b/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/owl_test.cljc @@ -0,0 +1,14 @@ +(ns org.domaindrivenarchitecture.activity-pub-poc.owl-test + (:require + [clojure.test :refer [deftest is are testing run-tests]] + [clojure.spec.test.alpha :as st] + [clojure.spec.alpha :as s] + [org.domaindrivenarchitecture.activity-pub-poc.owl :as sut])) + +(deftest functional-predicate + (is (sut/functional? "str")) + (is (sut/functional? 2)) + (is (sut/functional? ["str"])) + (is (not (sut/functional? []))) + (is (not (sut/functional? nil))) + (is (not (sut/functional? [1 2])))) \ No newline at end of file From 44862216eb56d4b71625c60d63737a6b50093b9e Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Mon, 24 Jul 2023 09:05:50 +0200 Subject: [PATCH 4/6] finished ::id & ::attachment --- doc/Translate_ttl_to_spec.md | 74 ++++++++++++++++++- .../activity_pub_poc/activitystreams2.cljc | 34 +++++++-- .../activity_pub_poc/owl.cljc | 4 + .../activity_pub_poc/xsd.cljc | 3 +- 4 files changed, 104 insertions(+), 11 deletions(-) diff --git a/doc/Translate_ttl_to_spec.md b/doc/Translate_ttl_to_spec.md index 0e1c86b..4512cd1 100644 --- a/doc/Translate_ttl_to_spec.md +++ b/doc/Translate_ttl_to_spec.md @@ -1,6 +1,18 @@ +- [receipts to transform ttl to spec](#receipts-to-transform-ttl-to-spec) + - [**a**](#a) + - [**rdfs:range**](#rdfsrange) + - [**rdfs:domain**](#rdfsdomain) + - [owner is **a** type](#owner-is-a-type) + - [owner is a **owl:unionOf** types](#owner-is-a-owlunionof-types) +- [Further infos](#further-infos) + - [RDF/S](#rdfs) + - [range (https://www.w3.org/TR/rdf12-schema/#ch\_range)](#range-httpswwww3orgtrrdf12-schemach_range) + - [type (https://www.w3.org/TR/rdf12-schema/#ch\_type)](#type-httpswwww3orgtrrdf12-schemach_type) + + # receipts to transform ttl to spec -## *it* **a** *something* +## **a** *it* is **a** *something* @@ -28,6 +40,66 @@ Der token `a` in einer ttl Definition entspricht dem RDF-Prädikat `rdf:type`. S Das bedeutet für das Tripel: `(R, rdf:type, C) => C instanceof rdfs:Class & R instanceof C` + +## **rdfs:range** + +*its* value is defined in a **rdfs:range** *the range* + +If range links to an other definition we map range same as **a**. + +Example: +```ttl +as:id rdfs:range xsd:anyURI ; +``` + +Maps to +```clojure +(s/def ::anyURI p/uri-string?) + +(s/def ::id + (s/and + ... + ::anyURI)) +``` + +## **rdfs:domain** + +*it* belong to a **rdfs:domain** *owner* + +### owner is **a** type + +It is added to the owner. That's the way to model properties. If the owner is membe of an other namespace, we create a subclass with same name in the namespce in scope and enhance the subclass. + +Example in namespace activitypub2 +```ttl +as:id rdfs:domain [a owl:Class;] +``` + +Maps to +```clojure +(s/def + ::Class + (s/merge ::owl/Class + (s/keys :opt-un [::id]))) +``` + +### owner is a **owl:unionOf** types + +It is added to the owner. That's the way to model properties. If the owner is membe of an other namespace, we create a subclass with same name in the namespce in scope and enhance the subclass. + +Example in namespace activitypub2 +```ttl +as:id rdfs:domain [owl:unionOf (as:Link as:Object)] +``` + +Maps to +```clojure +(s/def ::Object (s/keys :opt-un [::id ...])) + + +(s/def ::Link (s/keys :opt-un [::id])) +``` + # Further infos ## RDF/S diff --git a/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2.cljc b/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2.cljc index a4bffa9..3540fc0 100644 --- a/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2.cljc +++ b/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2.cljc @@ -18,25 +18,43 @@ ::xsd/anyURI)) ;http://www.w3.org/ns/activitystreams#attachment -;TODO: definition in progress (s/def ::attachment - (s/and ::owl/ObjectProperty)) + (s/and + ::Class + ::Link + ::Object + ::owl/ObjectProperty)) ;http://www.w3.org/ns/activitystreams#result ;TODO: definition in progress +;How should we translate this? +;rdfs:range [ +; a owl:Class ; +; owl:unionOf ( as:Object as:Link ) +; ] (s/def ::result (s/and ::owl/ObjectProperty)) -;http://www.w3.org/ns/activitystreams#Object -;TODO: definition in progress -(s/def ::Object (s/keys :opt-un [::attachment])) - ;http://www.w3.org/ns/activitystreams#Activity ;TODO: definition in progress (s/def ::Activity (s/and ::Object (s/keys :opt-un [::result]))) -;http://www.w3.org/ns/activitystreams#Like -(s/def ::Like ::Activity) +;http://www.w3.org/ns/activitystreams#Object +;TODO: definition in progress +(s/def ::Object (s/keys :opt-un [::id ::attachment])) + +;http://www.w3.org/ns/activitystreams#Link +;TODO: definition in progress +(s/def ::Link (s/keys :opt-un [::id])) + +(s/def + ::Class + (s/merge ::owl/Class + (s/keys :opt-un [::id]))) + + +;http://www.w3.org/ns/activitystreams#Like +(s/def ::Like ::Activity) \ No newline at end of file diff --git a/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/owl.cljc b/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/owl.cljc index 7afe811..7e0ccf6 100644 --- a/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/owl.cljc +++ b/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/owl.cljc @@ -9,6 +9,10 @@ ; * Datatype properties link individuals to data values. ; * Object properties link individuals to individuals. +;http://www.w3.org/2002/07/owl#Class +;https://www.w3.org/TR/owl-ref/#Class-def +(s/def ::Class any?) + ;http://www.w3.org/2002/07/owl#DatatypeProperty (s/def ::DatatypeProperty any?) diff --git a/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/xsd.cljc b/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/xsd.cljc index 2fecabf..578afab 100644 --- a/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/xsd.cljc +++ b/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/xsd.cljc @@ -1,6 +1,5 @@ (ns org.domaindrivenarchitecture.activity-pub-poc.xsd - "A swallow spec translation implementation of xsd Inheritance of FunctionalProperty - is realized in deep implemented." + "A spec translation implementation of xsd. Predicates are implemented fully functional." (:require [clojure.spec.alpha :as s] [org.domaindrivenarchitecture.activity-pub-poc.predicates :as p])) From d13259c2b23725357ab81d4e05cebf61b2e59340 Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Mon, 24 Jul 2023 09:25:56 +0200 Subject: [PATCH 5/6] model result spec --- .../activity_pub_poc/activitystreams2.cljc | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2.cljc b/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2.cljc index 3540fc0..31674d0 100644 --- a/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2.cljc +++ b/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2.cljc @@ -20,20 +20,18 @@ ;http://www.w3.org/ns/activitystreams#attachment (s/def ::attachment (s/and + ::owl/ObjectProperty ::Class ::Link - ::Object - ::owl/ObjectProperty)) + ::Object)) ;http://www.w3.org/ns/activitystreams#result -;TODO: definition in progress -;How should we translate this? -;rdfs:range [ -; a owl:Class ; -; owl:unionOf ( as:Object as:Link ) -; ] (s/def ::result - (s/and ::owl/ObjectProperty)) + (s/and + ::owl/ObjectProperty + ::Class + ::Object + ::Link)) ;http://www.w3.org/ns/activitystreams#Activity ;TODO: definition in progress From 92770f4eb27a505858b0a12d42811c7a79b0d304 Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Mon, 24 Jul 2023 09:26:16 +0200 Subject: [PATCH 6/6] move test to more appropriate place --- .../activitystreams2_legacy_test.clj | 7 ------- .../activity_pub_poc/activitystreams2_test.clj | 9 ++++++++- src/test/resources/like.json | 12 +++++++++++- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/test/clj/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2_legacy_test.clj b/src/test/clj/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2_legacy_test.clj index 5719928..5bb2b87 100644 --- a/src/test/clj/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2_legacy_test.clj +++ b/src/test/clj/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2_legacy_test.clj @@ -5,13 +5,6 @@ [clojure.spec.alpha :as s] [org.domaindrivenarchitecture.activity-pub-poc.activitystreams2-legacy :as sut])) -(deftest id-test - (is (s/valid? ::sut/id "https://social.bla/alyssa/status/RANDOMHASH"))) - - - - - ;(deftest Note-test ; (is (s/valid? diff --git a/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2_test.clj b/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2_test.clj index 08f784d..1ef4f0b 100644 --- a/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2_test.clj +++ b/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2_test.clj @@ -7,4 +7,11 @@ (deftest shoult-test-spec-for-having-functional-property (is (sut/is-functional-property? ::sut/id)) - (is (not (sut/is-functional-property? ::sut/Like)))) \ No newline at end of file + (is (not (sut/is-functional-property? ::sut/Like)))) + +(deftest id-test + (is (s/valid? ::sut/id "https://social.bla/alyssa/status/RANDOMHASH")) + (is (not (s/valid? ::sut/id nil))) + (is (not (s/valid? ::sut/id 2))) + (is (not (s/valid? ::sut/id "no-uri"))) + ) \ No newline at end of file diff --git a/src/test/resources/like.json b/src/test/resources/like.json index 5566c6b..ffd8244 100644 --- a/src/test/resources/like.json +++ b/src/test/resources/like.json @@ -1 +1,11 @@ -{"@context":"https://www.w3.org/ns/activitystreams","id":"https://social.bla/alyssa#likes/RANDOMHASH","type":"Like","to":["https://chatty.bla/ben","https://chatty.bla/gen"],"actor":"https://social.bla/alyssa","object":"https://chatty.bla/ben/posts/234s23-2g34234-2hhj536"} \ No newline at end of file +{ + "@context": "https://www.w3.org/ns/activitystreams", + "id": "https://social.bla/alyssa#likes/RANDOMHASH", + "type": "Like", + "to": [ + "https://chatty.bla/ben", + "https://chatty.bla/gen" + ], + "actor": "https://social.bla/alyssa", + "object": "https://chatty.bla/ben/posts/234s23-2g34234-2hhj536" +} \ No newline at end of file