diff --git a/doc/Translate_ttl_to_spec.md b/doc/Translate_ttl_to_spec.md index 4512cd1..dc8dc54 100644 --- a/doc/Translate_ttl_to_spec.md +++ b/doc/Translate_ttl_to_spec.md @@ -4,12 +4,12 @@ - [**rdfs:domain**](#rdfsdomain) - [owner is **a** type](#owner-is-a-type) - [owner is a **owl:unionOf** types](#owner-is-a-owlunionof-types) + - [**rdfs:subClassOf**](#rdfssubclassof) - [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 ## **a** @@ -25,13 +25,10 @@ as:id a owl:DatatypeProperty , Maps to ```clojure -(s/def ::DatatypeProperty any?) -(s/def ::FunctionalProperty any?) - (s/def ::id (s/and - ::DeprecatedProperty - ::FunctionalProperty)) + ::owl/DeprecatedProperty + ::owl/FunctionalProperty)) ``` Der token `a` in einer ttl Definition entspricht dem RDF-Prädikat `rdf:type`. Siehe: @@ -54,12 +51,10 @@ as:id rdfs:range xsd:anyURI ; Maps to ```clojure -(s/def ::anyURI p/uri-string?) - (s/def ::id (s/and ... - ::anyURI)) + ::xsd/anyURI)) ``` ## **rdfs:domain** @@ -68,7 +63,7 @@ Maps to ### 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. +We ignore this. Example in namespace activitypub2 ```ttl @@ -77,10 +72,6 @@ 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 @@ -94,12 +85,35 @@ as:id rdfs:domain [owl:unionOf (as:Link as:Object)] Maps to ```clojure -(s/def ::Object (s/keys :opt-un [::id ...])) +(s/def ::Object (sh/map-spec (s/keys :opt-un [::id ...]))) -(s/def ::Link (s/keys :opt-un [::id])) +(s/def ::Link (sh/map-spec (s/keys :opt-un [::id]))) ``` +## **rdfs:subClassOf** + +*its* value a **rdfs:subClassOf** *the class* + +If subClassOf links to an other definition we map range same as **a**. + +Example: +```ttl +as:Activity rdfs:subClassOf as:Object ; +``` + +Maps to +```clojure +(s/def ::Object ...) + +(s/def ::Activity + (s/and + ... + ::Object + ...)) +``` + + # Further infos ## RDF/S diff --git a/doc/id_ttl_to_rdf.md b/doc/id_ttl_to_rdf.md new file mode 100644 index 0000000..d771931 --- /dev/null +++ b/doc/id_ttl_to_rdf.md @@ -0,0 +1,32 @@ +```ttl +as:id a owl:DatatypeProperty , + owl:FunctionalProperty, + owl:DeprecatedProperty ; + rdfs:label "id"@en ; + rdfs:range xsd:anyURI ; + rdfs:domain [ + a owl:Class ; + owl:unionOf (as:Link as:Object) + ] . +``` + +This ttl def can be written as rdf N-Triples: + +``` +as:id rdf:type owl:DatatypeProperty . +as:id rdf:type owl:FunctionalProperty . +as:id rdf:type owl:DeprecatedProperty . + +as:id rdfs:label "id"@en . + +as:id rdfs:range xsd:anyURI . + +as:id rdfs:domain _:do . +_:do rdf:type owl:Class . +_:do owl:unionOf (as:Link as:Object) . + +--- + +_:Object as:id "http://an.uri" +_:Object as:type _:do +``` \ No newline at end of file diff --git a/src/main/clj/org/domaindrivenarchitecture/activity_pub_poc/common.clj b/src/main/clj/org/domaindrivenarchitecture/activity_pub_poc/common.clj index baa9523..f0260c6 100644 --- a/src/main/clj/org/domaindrivenarchitecture/activity_pub_poc/common.clj +++ b/src/main/clj/org/domaindrivenarchitecture/activity_pub_poc/common.clj @@ -2,6 +2,6 @@ (def resource-path "src/main/resources/") -(def activitystreams-ttl (str resource-path "activitystreams_2.0_owl.ttl")) +(def activitystreams-ttl (str resource-path "activitystreams_2.0.ttl")) (def rdf-schema-ttl (str resource-path "rdf_schema_1.1.ttl")) (def rdf-syntax-ttl (str resource-path "rdf_syntax_ns_22.ttl")) \ No newline at end of file diff --git a/src/main/clj/org/domaindrivenarchitecture/activity_pub_poc/xsd.clj b/src/main/clj/org/domaindrivenarchitecture/activity_pub_poc/xsd.clj deleted file mode 100644 index abbad0e..0000000 --- a/src/main/clj/org/domaindrivenarchitecture/activity_pub_poc/xsd.clj +++ /dev/null @@ -1,7 +0,0 @@ -(ns org.domaindrivenarchitecture.activity-pub-poc.xsd - (:require [clojure.spec.alpha :as s])) - -; http://www.datypic.com/sc/xsd/t-xsd_anyURI.html -; TODO: Find out correct definition! -(defn anyUri? [input] - false) \ No newline at end of file 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 093e800..0be62e1 100644 --- a/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2.cljc +++ b/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2.cljc @@ -1,59 +1,91 @@ (ns org.domaindrivenarchitecture.activity-pub-poc.activitystreams2 (:require [clojure.spec.alpha :as s] [orchestra.core :refer [defn-spec]] + [org.domaindrivenarchitecture.activity-pub-poc.spec-helper :as sh] [org.domaindrivenarchitecture.activity-pub-poc.owl :as owl] [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 -(s/def - ::id (s/and ::owl/DatatypeProperty - ::owl/FunctionalProperty - ::owl/DeprecatedProperty - ::xsd/anyURI)) + +;======================= + +;http://www.w3.org/ns/activitystreams#Object +;TODO: definition in progress +(s/def ::Object + (s/and + ::owl/Class + (sh/map-spec (s/keys :opt-un [::id ::type ::attachment])))) + +;http://www.w3.org/ns/activitystreams#Link +;TODO: definition in progress +(s/def ::Link + (s/and + ::owl/Class + (sh/map-spec (s/keys :opt-un [::id ::type])))) + +;http://www.w3.org/ns/activitystreams#Activity +;TODO: Define more properties necessary for Like +(s/def ::Activity + (s/and + ::owl/Class + ::Object + (sh/map-spec (s/keys :opt-un [::result ::object ::actor])))) + +;http://www.w3.org/ns/activitystreams#Relationship +;We only have this class, since the property "object" is in the domain "Activity" and "Relationship" +; TODO: What means: "as:Relationship a rdf:Statement". Relevant for spec? +(s/def ::Relationship + (s/and + ::owl/Class + ::Object + (sh/map-spec (s/keys :opt-un [::object])))) + +;http://www.w3.org/ns/activitystreams#Like +(s/def ::Like + (s/and + ::owl/Class + ::Activity)) ;http://www.w3.org/ns/activitystreams#attachment -(s/def ::attachment +(s/def ::attachment (s/and ::owl/ObjectProperty - ::Class - ::Link - ::Object)) + ::owl/Class + ::Object + ::Link)) + +;http://www.w3.org/ns/activitystreams#id +(s/def ::id + (s/and ::owl/DatatypeProperty + ::owl/FunctionalProperty + ::owl/DeprecatedProperty + ::xsd/anyURI)) + +;https://www.w3.org/TR/activitystreams-vocabulary/#dfn-type +;TODO: this can not be found in the ttl / namespace. Where is this exactly defined? +(s/def ::type + any?;::xsd/anyURI + ) ;http://www.w3.org/ns/activitystreams#result (s/def ::result (s/and ::owl/ObjectProperty - ::Class ::Object ::Link)) -;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#object +(s/def ::object + (s/and + ::owl/ObjectProperty + ::owl/Class + ::Object + ::Link)) -;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])) - -;TODO: There is no as:Class! Why do we need this? -(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 +;http://www.w3.org/ns/activitystreams#actor +(s/def ::actor + (s/and + ::owl/ObjectProperty + ::owl/Class + ::Object + ::Link)) 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 7e0ccf6..86fce47 100644 --- a/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/owl.cljc +++ b/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/owl.cljc @@ -3,6 +3,7 @@ is realized in deep implemented." (:require [clojure.spec.alpha :as s] + [org.domaindrivenarchitecture.activity-pub-poc.predicates :as p] [orchestra.core :refer [defn-spec]])) ; Properties:https://www.w3.org/TR/owl-ref/#Property @@ -11,7 +12,11 @@ ;http://www.w3.org/2002/07/owl#Class ;https://www.w3.org/TR/owl-ref/#Class-def -(s/def ::Class any?) +(defn-spec owl-class? boolean? + [elem any?] + (or (p/uri-string? elem) + (coll? elem))) +(s/def ::Class owl-class?) ;http://www.w3.org/2002/07/owl#DatatypeProperty (s/def ::DatatypeProperty any?) diff --git a/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/spec_helper.cljc b/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/spec_helper.cljc new file mode 100644 index 0000000..cada86f --- /dev/null +++ b/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/spec_helper.cljc @@ -0,0 +1,20 @@ +(ns org.domaindrivenarchitecture.activity-pub-poc.spec-helper + "A swallow spec translation implementation of owl. Inheritance of FunctionalProperty + is realized in deep implemented." + (:require + [clojure.spec.alpha :as s] + [orchestra.core :refer [defn-spec]])) + +(defn-spec map-spec s/spec? + "Spec that applies only for map values." + [spec s/spec?] + (s/and + (s/or + :no-map #(not (map? %)) + :map spec))) + +(defn-spec + is-functional-property? boolean? + "Checks whether spec is a FunctionalProperty." + [spec s/spec?] + (some #(clojure.string/includes? % "FunctionalProperty") (s/describe spec))) \ No newline at end of file diff --git a/src/main/resources/activitystreams_2.0_owl.ttl b/src/main/resources/activitystreams_2.0.ttl similarity index 100% rename from src/main/resources/activitystreams_2.0_owl.ttl rename to src/main/resources/activitystreams_2.0.ttl 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 deleted file mode 100644 index c9109ac..0000000 --- a/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2_test.clj +++ /dev/null @@ -1,31 +0,0 @@ -(ns org.domaindrivenarchitecture.activity-pub-poc.activitystreams2-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])) - -(deftest shoult-test-spec-for-having-functional-property - (is (sut/is-functional-property? ::sut/id)) - (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"))) - (is (not (s/valid? ::sut/id ["https://social.bla/alyssa/status/RANDOMHASH", "https://social.bla/alyssa/status/RANDOMHASH2"]))) - ) - -(deftest result-test - (is (s/valid? ::sut/result "https://social.bla/alyssa/result/RANDOMHASH")) - (is (s/valid? ::sut/result {:type "http://www.types.example/flightstatus", :name "On Time"})) - (is (s/valid? ::sut/result {:type "Link" :href "http://www.target.de"})) - (is (not (s/valid? ::sut/result nil))) - (is (not (s/valid? ::sut/result 47))) -) - - -;(deftest attachment-test -; (is (s/valid? ::sut/attachment)) -; ) \ No newline at end of file diff --git a/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2_test.cljc b/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2_test.cljc new file mode 100644 index 0000000..9735f68 --- /dev/null +++ b/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2_test.cljc @@ -0,0 +1,63 @@ +(ns org.domaindrivenarchitecture.activity-pub-poc.activitystreams2-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])) + +(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"))) + (is (not (s/valid? ::sut/id ["https://social.bla/alyssa/status/RANDOMHASH", "https://social.bla/alyssa/status/RANDOMHASH2"])))) + +(deftest object-test + (is (s/valid? ::sut/object "http://example.org/posts/1")) + (is (s/valid? ::sut/object {:type "Note", + :content "A simple note"})) + (is (s/valid? ::sut/object ["http://example.org/posts/1", + {:type "Note", + :summary "A simple note", + :content "That is a tree."}]))) + +(deftest result-test + (is (s/valid? ::sut/result "https://social.bla/alyssa/result/RANDOMHASH")) + (is (s/valid? ::sut/result {:type "http://www.types.example/flightstatus", :name "On Time"})) + (is (s/valid? ::sut/result {:type "Link" :href "http://www.target.de"})) + (is (not (s/valid? ::sut/result nil))) + (is (not (s/valid? ::sut/result 47)))) + + +(deftest attachment-test + (is (s/valid? ::sut/attachment + [{:type "Image", + :content "This is what he looks like.", + :url "http://example.org/cat.jpeg"}]))) + +(deftest actor-test + (is (s/valid? ::sut/actor "http://sally.example.org")) + (is (s/valid? ::sut/actor {:type "Person", + :id "http://sally.example.org", + :summary "Sally"})) + (is (s/valid? ::sut/actor ["http://joe.example.org", + {:type "Person", + :id "http://sally.example.org", + :name "Sally"}]))) + +(deftest Activity-test + (is (s/valid? ::sut/Activity + {:type "Activity", + :summary "Sally did something to a note", + :actor {:type "Person", + :name "Sally"}, + :object {:type "Note", + :name "A Note"}}))) + +(deftest Like-test + (is (s/valid? ::sut/Like + {:summary "Sally liked a note", + :type "Like", + :actor {:type "Person", + :name "Sally"}, + :object "http://example.org/notes/1"}))) 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 index 427751f..4bc968f 100644 --- a/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/owl_test.cljc +++ b/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/owl_test.cljc @@ -11,4 +11,15 @@ (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 + (is (not (sut/functional? [1 2])))) + +(deftest owl-class-predicate + (is (sut/owl-class? "http://some.uri")) + (is (sut/owl-class? {:as "class-definition"})) + (is (sut/owl-class? [])) + (is (not (sut/owl-class? "str"))) + (is (not (sut/owl-class? nil)))) + +(deftest class-test + (is (s/valid? ::sut/Class "https://social.bla/alyssa/status/RANDOMHASH")) + (is (s/valid? ::sut/Class {}))) diff --git a/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/spec_helper_test.cljc b/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/spec_helper_test.cljc new file mode 100644 index 0000000..cb7f08a --- /dev/null +++ b/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/spec_helper_test.cljc @@ -0,0 +1,11 @@ +(ns org.domaindrivenarchitecture.activity-pub-poc.spec-helper-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 as2] + [org.domaindrivenarchitecture.activity-pub-poc.spec-helper :as sut])) + +(deftest shoult-test-spec-for-having-functional-property + (is (sut/is-functional-property? ::as2/id)) + (is (not (sut/is-functional-property? ::as2/Like)))) \ No newline at end of file