Use a more consistent representation for jsonld

Julien LepillerSat May 02 23:55:21+0200 2020

a568305

Use a more consistent representation for jsonld

activitystreams/ontology.scm

291291
  (or
292292
    (equal? property other)
293293
    (equal? (as-property-uri property) other)
294+
    (and (as-property? other)
295+
         (equal? (as-property-uri property) (as-property-uri other)))
294296
    (let loop ((superproperties (as-property-subproperty-of property)))
295297
      (match superproperties
296298
        (() #f)

320322
    (match kv
321323
      ((k . v)
322324
       (subproperty? k key))))
323-
  (let ((candidates (filter is-candidate document)))
325+
  (let ((candidates (filter is-candidate
326+
                            (if (as-document? document)
327+
                                (as-document-properties document)
328+
                                document))))
324329
    (map cdr candidates)))
325330
326331
(define (json->as-document ontology document)

368373
    ((json-array? document)
369374
     ;; XXX: this filter is not correct if one of the values is the litteral
370375
     ;; "false"
371-
     (list->array 1
372-
       (filter
373-
         (lambda (a) a)
374-
         (map (lambda (doc) (json->as-document ontology doc))
375-
              (array->list document)))))
376-
    ((json-has-key? document "@type")
377-
     (let* ((types (assoc-ref document "@type"))
376+
     (filter
377+
       (lambda (a) a)
378+
       (map (lambda (doc) (json->as-document ontology doc))
379+
            (array->list document))))
380+
    ((list? document)
381+
     (let* ((types (or (assoc-ref document "@type") #()))
378382
            (types (if (string? types) (list types) (array->list types)))
379383
            (types (filter (lambda (a) a) (map uri->datatype types))))
380-
       (if (null? types)
381-
           #f
382-
           (make-as-document
383-
             types
384-
             (filter
385-
               (lambda (a) a)
386-
               (map
387-
                 (match-lambda
388-
                   ((key . value)
389-
                    (let ((property (uri->property key))
390-
                          (value (json->as-document ontology value)))
391-
                      (if (and property (not (equal? key "@type")) value)
392-
                          (cons (uri->property key) value)
393-
                          #f))))
394-
                 document))))))
395-
    (else
396-
      (map
397-
        (match-lambda
398-
          ((key . value)
399-
           (cons key (json->as-document ontology value))))
400-
        document))))
384+
       (make-as-document
385+
         types
386+
         (filter
387+
           (lambda (a) a)
388+
           (map
389+
             (match-lambda
390+
               ((key . value)
391+
                (let ((property (uri->property key))
392+
                      (value (json->as-document ontology value)))
393+
                  (if (and property (not (equal? key "@type")) value)
394+
                      (cons (uri->property key) value)
395+
                      #f))))
396+
             document)))))))
401397
402398
(define (uri->as-document ontology uri)
403399
  (json->as-document ontology (expand uri)))

468464
                      (if (string? key) key (as-property-label key)))
469465
              (as-document->graphviz value #:label child-label)
470466
              (loop children (+ suffix 1))))))))
471-
    ((list? doc)
472-
     (format #t "  ~a [label=\"\"];~%" label)
473-
     (let loop ((children doc) (suffix 0))
474-
       (match children
475-
         (() (format #t "~%"))
476-
         (((key . value) children ...)
477-
          (let ((child-label (string-append label (number->string suffix))))
478-
            (format #t "  ~a -> ~a [label=\"~a\"];~%"
479-
                    label child-label
480-
                    (if (string? key) key (as-property-label key)))
481-
            (as-document->graphviz value #:label child-label)
482-
            (loop children (+ suffix 1)))))))
483467
    ((string? doc)
484468
     (format #t "  ~a [label=\"~a\"];~%" label doc))
485-
    ((array? doc)
486-
     (let loop ((children (array->list doc)) (suffix 0))
469+
    ((list? doc)
470+
     (let loop ((children doc) (suffix 0))
487471
       (match children
488472
         (() (format #t "~%"))
489473
         ((value children ...)