Compare commits
2 commits
5588bcd5b8
...
077a50e733
Author | SHA1 | Date | |
---|---|---|---|
077a50e733 | |||
d572a8c05e |
5 changed files with 44 additions and 58 deletions
|
@ -1,6 +1,7 @@
|
||||||
(ns org.domaindrivenarchitecture.activity-pub-poc.activitystreams2
|
(ns org.domaindrivenarchitecture.activity-pub-poc.activitystreams2
|
||||||
(:require [clojure.spec.alpha :as s]
|
(:require [clojure.spec.alpha :as s]
|
||||||
[orchestra.core :refer [defn-spec]]
|
[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.owl :as owl]
|
||||||
[org.domaindrivenarchitecture.activity-pub-poc.xsd :as xsd]))
|
[org.domaindrivenarchitecture.activity-pub-poc.xsd :as xsd]))
|
||||||
|
|
||||||
|
@ -10,70 +11,51 @@
|
||||||
[spec keyword?]
|
[spec keyword?]
|
||||||
(some #(clojure.string/includes? % "FunctionalProperty") (s/describe spec)))
|
(some #(clojure.string/includes? % "FunctionalProperty") (s/describe spec)))
|
||||||
|
|
||||||
(defn-spec map-class-spec s/spec?
|
|
||||||
"Spec which checks whether a value is a ::Class
|
|
||||||
and if it is a map, if it validates the given map-spec."
|
|
||||||
[map-spec s/spec?]
|
|
||||||
(s/and
|
|
||||||
::Class
|
|
||||||
(s/or
|
|
||||||
:no-map #(not (map? %))
|
|
||||||
:map map-spec)))
|
|
||||||
|
|
||||||
;=======================
|
|
||||||
|
|
||||||
;TODO: There is no as:Class! Why do we need this?
|
|
||||||
;Answer jem: I do not want to enhance owl/Class inline from here.
|
|
||||||
(s/def
|
|
||||||
::Class
|
|
||||||
(s/and ::owl/Class))
|
|
||||||
|
|
||||||
;=======================
|
;=======================
|
||||||
|
|
||||||
;http://www.w3.org/ns/activitystreams#object
|
;http://www.w3.org/ns/activitystreams#object
|
||||||
(s/def ::Object
|
(s/def ::Object
|
||||||
(s/and
|
(s/and
|
||||||
::Class
|
::owl/Class
|
||||||
(s/keys :opt-un [::id ::type ::attachment])))
|
(sh/map-spec (s/keys :opt-un [::id ::type ::attachment]))))
|
||||||
|
|
||||||
;http://www.w3.org/ns/activitystreams#Link
|
;http://www.w3.org/ns/activitystreams#Link
|
||||||
(s/def ::Link
|
(s/def ::Link
|
||||||
(s/and
|
(s/and
|
||||||
::Class
|
::owl/Class
|
||||||
(s/keys :opt-un [::id ::type])))
|
(sh/map-spec (s/keys :opt-un [::id ::type]))))
|
||||||
|
|
||||||
;http://www.w3.org/ns/activitystreams#Activity
|
;http://www.w3.org/ns/activitystreams#Activity
|
||||||
;TODO: Define more properties necessary for Like
|
;TODO: Define more properties necessary for Like
|
||||||
(s/def ::Activity
|
(s/def ::Activity
|
||||||
(s/and
|
(s/and
|
||||||
::Class
|
::owl/Class
|
||||||
::Object
|
::Object
|
||||||
(s/keys :opt-un [::result ::object])))
|
(sh/map-spec (s/keys :opt-un [::result ::object]))))
|
||||||
|
|
||||||
;http://www.w3.org/ns/activitystreams#Relationship
|
;http://www.w3.org/ns/activitystreams#Relationship
|
||||||
;We only have this class, since the property "object" is in the domain "Activity" and "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?
|
; TODO: What means: "as:Relationship a rdf:Statement". Relevant for spec?
|
||||||
(s/def ::Relationship
|
(s/def ::Relationship
|
||||||
(s/and
|
(s/and
|
||||||
::Class
|
::owl/Class
|
||||||
::Object
|
::Object
|
||||||
(s/keys :opt-un [::object])))
|
(sh/map-spec (s/keys :opt-un [::object]))))
|
||||||
|
|
||||||
;http://www.w3.org/ns/activitystreams#Like
|
;http://www.w3.org/ns/activitystreams#Like
|
||||||
(s/def ::Like
|
(s/def ::Like
|
||||||
(s/and
|
(s/and
|
||||||
::Class
|
::owl/Class
|
||||||
::Activity))
|
::Activity))
|
||||||
|
|
||||||
;http://www.w3.org/ns/activitystreams#attachment
|
;http://www.w3.org/ns/activitystreams#attachment
|
||||||
; TODO: Why do we need to model this? Is this necessary for a Like-Activity?
|
; TODO: Why do we need to model this? Is this necessary for a Like-Activity?
|
||||||
(s/def ::attachment
|
(s/def ::attachment
|
||||||
(s/and
|
(s/and
|
||||||
|
::owl/Class
|
||||||
::owl/ObjectProperty
|
::owl/ObjectProperty
|
||||||
(map-class-spec
|
::Object
|
||||||
(s/or
|
::Link))
|
||||||
:object ::Object
|
|
||||||
:link ::Link))))
|
|
||||||
|
|
||||||
;http://www.w3.org/ns/activitystreams#id
|
;http://www.w3.org/ns/activitystreams#id
|
||||||
(s/def ::id
|
(s/def ::id
|
||||||
|
@ -92,38 +74,29 @@
|
||||||
;http://www.w3.org/ns/activitystreams#result
|
;http://www.w3.org/ns/activitystreams#result
|
||||||
(s/def ::result
|
(s/def ::result
|
||||||
(s/and
|
(s/and
|
||||||
|
::owl/Class
|
||||||
::owl/ObjectProperty
|
::owl/ObjectProperty
|
||||||
(map-class-spec
|
::Object
|
||||||
(s/or :object ::Object
|
::Link))
|
||||||
:link ::Link))))
|
|
||||||
|
|
||||||
;http://www.w3.org/ns/activitystreams#object
|
;http://www.w3.org/ns/activitystreams#object
|
||||||
(s/def ::object
|
(s/def ::object
|
||||||
(s/and
|
(s/and
|
||||||
|
::owl/Class
|
||||||
::owl/ObjectProperty
|
::owl/ObjectProperty
|
||||||
(map-class-spec
|
::Object
|
||||||
(s/or
|
::Link))
|
||||||
:object ::Object
|
|
||||||
:link ::Link))))
|
|
||||||
|
|
||||||
;http://www.w3.org/ns/activitystreams#object
|
;http://www.w3.org/ns/activitystreams#object
|
||||||
(defmulti object-type map?)
|
(s/def ::Object
|
||||||
(defmethod object-type true [_]
|
(s/and ::owl/Class
|
||||||
(s/and ::Class
|
(sh/map-spec (s/keys :opt-un [::id]))))
|
||||||
(s/keys :opt-un [::id])))
|
|
||||||
(defmethod object-type false [_]
|
|
||||||
(s/and ::Class))
|
|
||||||
(s/def ::Object object-type)
|
|
||||||
|
|
||||||
;http://www.w3.org/ns/activitystreams#Link
|
;http://www.w3.org/ns/activitystreams#Link
|
||||||
;TODO: definition in progress
|
;TODO: definition in progress
|
||||||
(defmulti link-type map?)
|
(s/def ::Link
|
||||||
(defmethod link-type true [_]
|
(s/and ::owl/Class
|
||||||
(s/and ::Class
|
(sh/map-spec (s/keys :opt-un [::id]))))
|
||||||
(s/keys :opt-un [::id])))
|
|
||||||
(defmethod link-type false [_]
|
|
||||||
(s/and ::Class))
|
|
||||||
(s/def ::Link link-type)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,7 @@
|
||||||
(defn-spec owl-class? boolean?
|
(defn-spec owl-class? boolean?
|
||||||
[elem any?]
|
[elem any?]
|
||||||
(or (p/uri-string? elem)
|
(or (p/uri-string? elem)
|
||||||
(map? elem)
|
(coll? elem)))
|
||||||
(vector? elem)))
|
|
||||||
(s/def ::Class owl-class?)
|
(s/def ::Class owl-class?)
|
||||||
|
|
||||||
;http://www.w3.org/2002/07/owl#DatatypeProperty
|
;http://www.w3.org/2002/07/owl#DatatypeProperty
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
(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)))
|
|
@ -16,7 +16,6 @@
|
||||||
(is (not (s/valid? ::sut/id "no-uri")))
|
(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"]))))
|
(is (not (s/valid? ::sut/id ["https://social.bla/alyssa/status/RANDOMHASH", "https://social.bla/alyssa/status/RANDOMHASH2"]))))
|
||||||
|
|
||||||
;TODO: where does the ability for a link reference come from ?
|
|
||||||
(deftest object-test
|
(deftest object-test
|
||||||
(is (s/valid? ::sut/object "http://example.org/posts/1"))
|
(is (s/valid? ::sut/object "http://example.org/posts/1"))
|
||||||
(is (s/valid? ::sut/object {:type "Note",
|
(is (s/valid? ::sut/object {:type "Note",
|
||||||
|
@ -26,9 +25,6 @@
|
||||||
:summary "A simple note",
|
:summary "A simple note",
|
||||||
:content "That is a tree."}])))
|
:content "That is a tree."}])))
|
||||||
|
|
||||||
(deftest class-test
|
|
||||||
(is (s/valid? ::sut/Class "https://social.bla/alyssa/status/RANDOMHASH")))
|
|
||||||
|
|
||||||
(deftest result-test
|
(deftest result-test
|
||||||
(is (s/valid? ::sut/result "https://social.bla/alyssa/result/RANDOMHASH"))
|
(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 "http://www.types.example/flightstatus", :name "On Time"}))
|
||||||
|
|
|
@ -19,3 +19,7 @@
|
||||||
(is (sut/owl-class? []))
|
(is (sut/owl-class? []))
|
||||||
(is (not (sut/owl-class? "str")))
|
(is (not (sut/owl-class? "str")))
|
||||||
(is (not (sut/owl-class? nil))))
|
(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 {})))
|
||||||
|
|
Loading…
Reference in a new issue