expand the context
This commit is contained in:
parent
0f940aaaef
commit
50ff2f4617
3 changed files with 45 additions and 9 deletions
|
@ -1,11 +1,14 @@
|
|||
(ns activity-pub-poc.json-ld
|
||||
(ns dda.activity-pub-poc.json-ld
|
||||
(:require
|
||||
[hato.client :as http]
|
||||
[clojure.string :as str]
|
||||
[clojure.inspector :as ins]
|
||||
))
|
||||
|
||||
(def team-url "https://social.meissa-gmbh.de/users/team")
|
||||
|
||||
(def context-cache (atom {}))
|
||||
|
||||
(defn json-get [url]
|
||||
(:body
|
||||
(http/get url
|
||||
|
@ -13,4 +16,38 @@
|
|||
:http-client {:redirect-policy :normal}
|
||||
:as :json-string-keys})))
|
||||
|
||||
(ins/inspect-tree (json-get team-url))
|
||||
(defn fetch-context [url]
|
||||
(if-let [ctx (get @context-cache url)]
|
||||
ctx
|
||||
(get
|
||||
(swap! context-cache
|
||||
(fn [cache]
|
||||
(assoc cache url (get (json-get url) "@context"))))
|
||||
url)))
|
||||
|
||||
(defn expand-context
|
||||
([new-context]
|
||||
(expand-context {} new-context))
|
||||
([current-context new-context]
|
||||
(cond
|
||||
(string? new-context)
|
||||
(expand-context current-context (fetch-context new-context))
|
||||
|
||||
(sequential? new-context)
|
||||
(reduce expand-context current-context new-context)
|
||||
|
||||
(map? new-context)
|
||||
(into current-context
|
||||
(map
|
||||
(fn [[k v]]
|
||||
(let [id (if (map? v) (get v "@id" v) v)
|
||||
[prefix suffix] (str/split id #":")]
|
||||
(if-let [base (get (merge current-context new-context) prefix)]
|
||||
[k (assoc (if (map? v) v {})
|
||||
"@id" (str (if (map? base) (get base "@id") base)
|
||||
suffix))]
|
||||
[k (if (map? v) v {"@id" v})]))))
|
||||
new-context))))
|
||||
|
||||
|
||||
(expand-context (get (json-get team-url) "@context"))
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
(ns activity-pub-poc.core-test
|
||||
(:require [clojure.test :refer :all]
|
||||
[activity-pub-poc.core :refer :all]))
|
||||
|
||||
(deftest a-test
|
||||
(testing "FIXME, I fail."
|
||||
(is (= 0 1))))
|
6
src/test/clj/dda/activity_pub_poc/json_ld_test.clj
Normal file
6
src/test/clj/dda/activity_pub_poc/json_ld_test.clj
Normal file
|
@ -0,0 +1,6 @@
|
|||
(ns dda.activity-pub-poc.json-ld-test
|
||||
(:require [clojure.test :refer :all]
|
||||
[dda.activity-pub-poc.json-ld :as sut]))
|
||||
|
||||
(deftest get-property-type-from-ld-resource
|
||||
(is (= 0 1)))
|
Loading…
Reference in a new issue