Add as-document manipulation routines

Julien LepillerMon Oct 05 03:19:52+0200 2020

f8bb8b6

Add as-document manipulation routines

activitystreams/ontology.scm

6666
            subproperty?
6767
            subtype?
6868
            as-ref
69+
            as-document-set
70+
            as-document-delete
71+
            as-document-delete*
72+
6973
            json->as-document
7074
            uri->as-document
7175
            as-document->json

144148
         (cons (cons key value) lst)
145149
         (cons (cons k v) (alist-set lst key value))))))
146150
151+
(define (as-alist-set lst key value)
152+
  (match lst
153+
    (() `((,key . ,value)))
154+
    (((k . v) lst ...)
155+
     (if (equal? (as-property-uri k) (as-property-uri key))
156+
         (cons (cons key value) lst)
157+
         (cons (cons k v) (as-alist-set lst key value))))))
158+
159+
(define (as-alist-delete lst key)
160+
  (match lst
161+
    (() '())
162+
    (((k . v) lst ...)
163+
     (if (equal? (as-property-uri k) (as-property-uri key))
164+
         lst
165+
         (cons (cons k v) (as-alist-delete lst key))))))
166+
167+
(define (as-alist-delete* lst key)
168+
  (match lst
169+
    (() '())
170+
    (((k . v) lst ...)
171+
     (if (subproperty? k key)
172+
         (as-alist-delete* lst key)
173+
         (cons (cons k v) (as-alist-delete lst key))))))
174+
147175
(define (merge-domains d1 d2)
148176
  (uniq
149177
    (if (list? d1)

328356
                                document))))
329357
    (map cdr candidates)))
330358
359+
(define (as-document-set document key value)
360+
  (make-as-document
361+
    (as-document-types document)
362+
    (as-alist-set (as-document-properties document) key value)))
363+
364+
(define (as-document-delete document key)
365+
  (make-as-document
366+
    (as-document-types document)
367+
    (as-alist-delete (as-document-properties document) key)))
368+
369+
(define (as-document-delete* document key)
370+
  (make-as-document
371+
    (as-document-types document)
372+
    (as-alist-delete* (as-document-properties document) key)))
373+
331374
(define (json->as-document ontology document)
332375
  (define (uri->datatype type)
333376
    (let ((candidates (filter (lambda (t) (equal? (as-type-uri t) type))