Compare commits

...

26 commits

Author SHA1 Message Date
jem
ec1c45be63 Merge pull request 'object-or-refernce' (#1) from object-or-refernce into main
Reviewed-on: #1
2023-08-01 07:43:12 +00:00
4ee310596a add actor definition 2023-07-28 17:57:30 +02:00
c5376319c5 add Like-test 2023-07-28 17:45:54 +02:00
72a51b3f2c finished attachment 2023-07-28 17:42:07 +02:00
e04683d253 remove douplicate spec defs 2023-07-28 17:36:15 +02:00
d8874ba147 double-checked object 2023-07-28 17:33:42 +02:00
e4594d9391 double-checked result 2023-07-28 17:27:13 +02:00
5f94abcfdb fix as2.tl reference 2023-07-28 17:26:53 +02:00
d7549638cf make transormation receipt more lean 2023-07-28 17:12:44 +02:00
614db2aa91 adjust translate receipt 2023-07-28 17:09:24 +02:00
fc539a28d9 renamed 2023-07-28 17:09:06 +02:00
8aea2c5326 refactore out more spec-herlper fcts 2023-07-28 17:06:24 +02:00
21c5a0244e refactore out more spec-herlper fcts 2023-07-28 17:06:13 +02:00
077a50e733 remove unused as:Class 2023-07-28 16:58:10 +02:00
d572a8c05e catch up the idea of map-class-spec 2023-07-28 16:55:41 +02:00
Clemens
5588bcd5b8 adjustments 2023-07-28 16:08:32 +02:00
Clemens
ada2074726 fix merge conflicts 2023-07-28 14:33:47 +02:00
572d42f6ea fix the tests - transormation description in progress 2023-07-28 13:31:48 +02:00
3e84e78c15 undo not intended commit 2023-07-28 13:17:00 +02:00
97eb76b8d3 ignore domain .. a in mapping 2023-07-28 13:15:19 +02:00
0fadba5e53 Merge branch 'object-or-refernce' of ssh://repo.prod.meissa.de:2222/meissa/activity-pub-poc into object-or-refernce 2023-07-28 12:05:03 +02:00
26fac9b467 non working id test 2023-07-28 12:04:57 +02:00
19b050f517 non working id test 2023-07-28 12:04:10 +02:00
Clemens
56a4642800 Added ttl to rdf example 2023-07-28 12:02:47 +02:00
33404eb853 some rudimentary model of class 2023-07-28 11:13:47 +02:00
06a1864b2f more tests and investigation 2023-07-26 09:18:49 +02:00
12 changed files with 246 additions and 96 deletions

View file

@ -4,12 +4,12 @@
- [**rdfs:domain**](#rdfsdomain) - [**rdfs:domain**](#rdfsdomain)
- [owner is **a** type](#owner-is-a-type) - [owner is **a** type](#owner-is-a-type)
- [owner is a **owl:unionOf** types](#owner-is-a-owlunionof-types) - [owner is a **owl:unionOf** types](#owner-is-a-owlunionof-types)
- [**rdfs:subClassOf**](#rdfssubclassof)
- [Further infos](#further-infos) - [Further infos](#further-infos)
- [RDF/S](#rdfs) - [RDF/S](#rdfs)
- [range (https://www.w3.org/TR/rdf12-schema/#ch\_range)](#range-httpswwww3orgtrrdf12-schemach_range) - [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) - [type (https://www.w3.org/TR/rdf12-schema/#ch\_type)](#type-httpswwww3orgtrrdf12-schemach_type)
# receipts to transform ttl to spec # receipts to transform ttl to spec
## **a** ## **a**
@ -25,13 +25,10 @@ as:id a owl:DatatypeProperty ,
Maps to Maps to
```clojure ```clojure
(s/def ::DatatypeProperty any?)
(s/def ::FunctionalProperty any?)
(s/def ::id (s/def ::id
(s/and (s/and
::DeprecatedProperty ::owl/DeprecatedProperty
::FunctionalProperty)) ::owl/FunctionalProperty))
``` ```
Der token `a` in einer ttl Definition entspricht dem RDF-Prädikat `rdf:type`. Siehe: 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 Maps to
```clojure ```clojure
(s/def ::anyURI p/uri-string?)
(s/def ::id (s/def ::id
(s/and (s/and
... ...
::anyURI)) ::xsd/anyURI))
``` ```
## **rdfs:domain** ## **rdfs:domain**
@ -68,7 +63,7 @@ Maps to
### owner is **a** type ### 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 Example in namespace activitypub2
```ttl ```ttl
@ -77,10 +72,6 @@ as:id rdfs:domain [a owl:Class;]
Maps to Maps to
```clojure ```clojure
(s/def
::Class
(s/merge ::owl/Class
(s/keys :opt-un [::id])))
``` ```
### owner is a **owl:unionOf** types ### owner is a **owl:unionOf** types
@ -94,12 +85,35 @@ as:id rdfs:domain [owl:unionOf (as:Link as:Object)]
Maps to Maps to
```clojure ```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 # Further infos
## RDF/S ## RDF/S

32
doc/id_ttl_to_rdf.md Normal file
View file

@ -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
```

View file

@ -2,6 +2,6 @@
(def resource-path "src/main/resources/") (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-schema-ttl (str resource-path "rdf_schema_1.1.ttl"))
(def rdf-syntax-ttl (str resource-path "rdf_syntax_ns_22.ttl")) (def rdf-syntax-ttl (str resource-path "rdf_syntax_ns_22.ttl"))

View file

@ -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)

View file

@ -1,59 +1,91 @@
(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]))
(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 ;http://www.w3.org/ns/activitystreams#Object
::owl/DeprecatedProperty ;TODO: definition in progress
::xsd/anyURI)) (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 ;http://www.w3.org/ns/activitystreams#attachment
(s/def ::attachment (s/def ::attachment
(s/and (s/and
::owl/ObjectProperty ::owl/ObjectProperty
::Class ::owl/Class
::Link ::Object
::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 ;http://www.w3.org/ns/activitystreams#result
(s/def ::result (s/def ::result
(s/and (s/and
::owl/ObjectProperty ::owl/ObjectProperty
::Class
::Object ::Object
::Link)) ::Link))
;http://www.w3.org/ns/activitystreams#Activity ;http://www.w3.org/ns/activitystreams#object
;TODO: definition in progress (s/def ::object
(s/def ::Activity (s/and
(s/and ::Object ::owl/ObjectProperty
(s/keys :opt-un [::result]))) ::owl/Class
::Object
::Link))
;http://www.w3.org/ns/activitystreams#Object ;http://www.w3.org/ns/activitystreams#actor
;TODO: definition in progress (s/def ::actor
(s/def ::Object (s/keys :opt-un [::id ::attachment])) (s/and
::owl/ObjectProperty
::owl/Class
;http://www.w3.org/ns/activitystreams#Link ::Object
;TODO: definition in progress ::Link))
(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)

View file

@ -3,6 +3,7 @@
is realized in deep implemented." is realized in deep implemented."
(:require (:require
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
[org.domaindrivenarchitecture.activity-pub-poc.predicates :as p]
[orchestra.core :refer [defn-spec]])) [orchestra.core :refer [defn-spec]]))
; Properties:https://www.w3.org/TR/owl-ref/#Property ; Properties:https://www.w3.org/TR/owl-ref/#Property
@ -11,7 +12,11 @@
;http://www.w3.org/2002/07/owl#Class ;http://www.w3.org/2002/07/owl#Class
;https://www.w3.org/TR/owl-ref/#Class-def ;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 ;http://www.w3.org/2002/07/owl#DatatypeProperty
(s/def ::DatatypeProperty any?) (s/def ::DatatypeProperty any?)

View file

@ -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)))

View file

@ -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))
; )

View file

@ -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"})))

View file

@ -11,4 +11,15 @@
(is (sut/functional? ["str"])) (is (sut/functional? ["str"]))
(is (not (sut/functional? []))) (is (not (sut/functional? [])))
(is (not (sut/functional? nil))) (is (not (sut/functional? nil)))
(is (not (sut/functional? [1 2])))) (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 {})))

View file

@ -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))))