Compare commits

...

6 commits

Author SHA1 Message Date
1d6c71f56a Abandon parser 2023-06-22 15:45:51 +02:00
4bf90ae278 Implement simple test 2023-06-22 15:45:38 +02:00
cc641bfe7f Implement simple specs and like map generation 2023-06-22 15:44:55 +02:00
6f8b77c17e Use orchestra 2023-06-22 15:44:25 +02:00
5727a8c834 Add basic like activity 2023-06-22 14:15:17 +02:00
b4ad068bab Add simple specs 2023-06-22 14:10:54 +02:00
5 changed files with 134 additions and 42 deletions

View file

@ -8,6 +8,7 @@
"src/main/clj"]
:resource-paths ["src/main/resources"]
:dependencies [[org.clojure/clojure "1.11.1"]
[orchestra "2021.01.01-1"]
;; Incoming HTTP
[ring/ring-core "1.9.6"]
[ring/ring-jetty-adapter "1.9.6"]

View file

@ -4,10 +4,13 @@
[quoll.raphael.core :refer [parse]]
[org.domaindrivenarchitecture.activity-pub-poc.common :as cm]
[clojure.spec.alpha :as s]
[orchestra.core :refer [defn-spec]]
[clojure.inspector :as ins]
[hato.client :as hato]
[clojure.string :as st]
[clojure.walk :as walk]))
[clojure.walk :as walk]
[clojure.string :as str]
[lambdaisland.uri :as uri]))
(def team-url "https://social.meissa-gmbh.de/users/team")
(def like-url "https://www.w3.org/ns/activitystreams#Like")
@ -20,9 +23,76 @@
(def team (ap/GET team-url))
(def parsed-rdf-syntax (parse (slurp cm/activitystreams-ttl)))
(defn type-string? [input]
(re-matches #"[A-Z]" (str (first input))))
(defn uri-string? [input]
(re-matches #"https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)" input))
(defn uri-vector? [input]
(and (every? #(uri? %) input)
(vector? input)))
(def context "@context")
(def type-string "type")
(def id-uri "id")
(def to-uri "to")
(def actor "actor")
(def object "object")
; Specs for a like
(s/def context uri-string?)
(s/def type-string type-string?)
(s/def id-uri uri-string?)
(s/def to-uri uri-vector?)
(s/def actor uri-string?)
(s/def object uri-string?)
(s/def ::to uri-string?)
(s/def ::target string?)
(s/def ::from uri-string?)
(def like? (s/keys :req-un [context
type-string
id-uri
to-uri
actor
object]))
(def like-data? (s/keys :req-un [::to ::target ::from]))
(def activity-streams-context "https://www.w3.org/ns/activitystreams")
(def like-data
{:to "https://chatty.bla/ben/"
:target "posts/234s23-2g34234-2hhj536"
:from "https://social.bla/alyssa/"})
(defn generate-id-from-object [from]
(str from "out" "/" "sdfsd44243g324g3455"))
(defn-spec generate-like-map like?
[input-map like-data?]
(assoc {}
"@context" activity-streams-context
"type" "Like"
"id" (generate-id-from-object (:from input-map))
"to" (:to input-map)
"actor" (:from input-map)
"object" (:target input-map)))
; ToDo
; Prädikat das langString parsen/validieren kann, evtl auch für xsd:string

View file

@ -0,0 +1,6 @@
{"@context": "https://www.w3.org/ns/activitystreams",
"type": "Like",
"id": "https://social.example/alyssa/posts/5312e10e-5110-42e5-a09b-934882b3ecec",
"to": ["https://chatty.example/ben/"],
"actor": "https://social.example/alyssa/",
"object": "https://chatty.example/ben/p/51086"}

View file

@ -1,6 +1,21 @@
(ns org.domaindrivenarchitecture.activity-pub-poc.core-test
(:require [clojure.test :refer :all]
[org.domaindrivenarchitecture.activity-pub-poc.core :as sut]))
(:require
[clojure.test :refer [deftest is are testing run-tests]]
[clojure.spec.test.alpha :as st]
[org.domaindrivenarchitecture.activity-pub-poc.core :as sut]))
(deftest get-property-type-from-ld-resource
(is (= 0 1)))
(st/instrument `sut/generate-like-map)
(def test-like-data
{:to "https://chatty.bla/ben/"
:target "posts/234s23-2g34234-2hhj536"
:from "https://social.bla/alyssa/"})
(deftest produces-valid-like
(is (= {"@context" "https://www.w3.org/ns/activitystreams",
"type" "Like",
"id" "https://social.bla/alyssa/out/sdfsd44243g324g3455",
"to" "https://chatty.bla/ben/",
"actor" "https://social.bla/alyssa/",
"object" "posts/234s23-2g34234-2hhj536"}
(sut/generate-like-map test-like-data))))

View file

@ -1,38 +1,38 @@
(ns org.domaindrivenarchitecture.activity-pub-poc.parser-test
(:require [clojure.test :refer :all]
[org.domaindrivenarchitecture.activity-pub-poc.parser :as sut]))
;(ns org.domaindrivenarchitecture.activity-pub-poc.parser-test
; (:require [clojure.test :refer :all]
; [org.domaindrivenarchitecture.activity-pub-poc.parser :as sut]))
(def processed (slurp "src/test/resources/deleted_comments_minimal.ttl"))
(def expected-definitions ["@prefix : <http://www.w3.org/ns/activitystreams#> "
"@prefix as: <http://www.w3.org/ns/activitystreams#> "
"@prefix owl: <http://www.w3.org/2002/07/owl#> "
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "
"@prefix xml: <http://www.w3.org/XML/1998/namespace> "
"@prefix xsd: <http://www.w3.org/2001/XMLSchema#> "
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> "
"@base <http://www.w3.org/ns/activitystreams> "
"<http://www.w3.org/ns/activitystreams#> a owl:Ontology ;\n rdfs:comment \"Extended Activity Streams 2.0 Vocabulary\"@en ;\n rdfs:label \"Activity Streams 2.0\"@en ;\n owl:imports <http://www.w3.org/ns/prov#> "
"rdf:langString a rdfs:Datatype "
"xsd:duration a rdfs:Datatype "
"as:actor a owl:ObjectProperty ;\n rdfs:label \"actor\"@en ;\n rdfs:domain as:Activity ;\n rdfs:comment \"Subproperty of as:attributedTo that identifies the primary actor\"@en ;\n rdfs:subPropertyOf as:attributedTo ;\n rdfs:range [\n a owl:Class ;\n owl:unionOf (as:Object as:Link)\n ] "
"as:attributedTo a owl:ObjectProperty ;\n rdfs:label \"attributedTo\"@en;\n rdfs:comment \"Identifies an entity to which an object is attributed\"@en;\n rdfs:range [\n a owl:Class ;\n owl:unionOf (as:Object as:Link)\n ] ;\n rdfs:domain [\n a owl:Class ;\n owl:unionOf (as:Object as:Link)\n ] ; "])
(deftest remove-comments-test
(is
(= processed
(sut/delete-comments-and-newlines "src/test/resources/minimal.ttl"))))
((deftest find-definitions-test
(testing "Finding definitons"
(is (= expected-definitions
(sut/find-definitions processed))))))
;ToDo
; spec für eine property: as:name
; test für (defn get-spec-from-ttl ttl-file element-name [spezified predicates]) -> (str spec)
; ToDo
; spec generator
; das gleiche für as:actor
;(def processed (slurp "src/test/resources/deleted_comments_minimal.ttl"))
;(def expected-definitions ["@prefix : <http://www.w3.org/ns/activitystreams#> "
; "@prefix as: <http://www.w3.org/ns/activitystreams#> "
; "@prefix owl: <http://www.w3.org/2002/07/owl#> "
; "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "
; "@prefix xml: <http://www.w3.org/XML/1998/namespace> "
; "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> "
; "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> "
; "@base <http://www.w3.org/ns/activitystreams> "
; "<http://www.w3.org/ns/activitystreams#> a owl:Ontology ;\n rdfs:comment \"Extended Activity Streams 2.0 Vocabulary\"@en ;\n rdfs:label \"Activity Streams 2.0\"@en ;\n owl:imports <http://www.w3.org/ns/prov#> "
; "rdf:langString a rdfs:Datatype "
; "xsd:duration a rdfs:Datatype "
; "as:actor a owl:ObjectProperty ;\n rdfs:label \"actor\"@en ;\n rdfs:domain as:Activity ;\n rdfs:comment \"Subproperty of as:attributedTo that identifies the primary actor\"@en ;\n rdfs:subPropertyOf as:attributedTo ;\n rdfs:range [\n a owl:Class ;\n owl:unionOf (as:Object as:Link)\n ] "
; "as:attributedTo a owl:ObjectProperty ;\n rdfs:label \"attributedTo\"@en;\n rdfs:comment \"Identifies an entity to which an object is attributed\"@en;\n rdfs:range [\n a owl:Class ;\n owl:unionOf (as:Object as:Link)\n ] ;\n rdfs:domain [\n a owl:Class ;\n owl:unionOf (as:Object as:Link)\n ] ; "])
;
;(deftest remove-comments-test
; (is
; (= processed
; (sut/delete-comments-and-newlines "src/test/resources/minimal.ttl"))))
;
;((deftest find-definitions-test
; (testing "Finding definitons"
; (is (= expected-definitions
; (sut/find-definitions processed))))))
;
;;ToDo
;; spec für eine property: as:name
;; test für (defn get-spec-from-ttl ttl-file element-name [spezified predicates]) -> (str spec)
;
;; ToDo
;; spec generator
;
;; das gleiche für as:actor