Rename JSON-LD slots & accessors

The slot .ETC is renamed to @ETC; accessors are
renamed from JSON-LD-CONTEXT (for example) to
simply the slot-name, @CONTEXT.
This commit is contained in:
Jaidyn Ann 2024-09-05 12:01:57 -05:00
parent a0f4d6ba36
commit 4978dfb7ee

View File

@ -27,10 +27,8 @@
#:*default-json-type* #:*default-json-type*
;; Objects ;; Objects
#:json-ld-object #:json-ld-object
;; Accessors ;; Slots/Accessors
#:json-ld-context #:json-ld-etc #:json-ld-id #:json-ld-type :@context :@id :@type :@etc))
;; Slots
:@context :@id :@type :.etc))
(in-package #:activity-servist/json-ld) (in-package #:activity-servist/json-ld)
@ -67,20 +65,20 @@ Maps URLs to text-content, so we dont have to download the same context again
:initform nil :initform nil
:documentation :documentation
"Used as an override for a classes @context during encoding. "Used as an override for a classes @context during encoding.
The method JSON-LD-CONTEXT is how the contents of encoded @context is The method @CONTEXT is how the contents of encoded @context is
determined; to change a classes default/calculated @context, override that determined; to change a classes default/calculated @context, override that
method. This slot is for changing a specific objects @context.") method. This slot is for changing a specific objects @context.")
(@id (@id
:accessor json-ld-id :accessor @id
:documentation :documentation
"Provides the globally unique identifier for an object.") "Provides the globally unique identifier for an object.")
(@type (@type
:accessor json-ld-type :accessor @type
:documentation :documentation
"Identifies the type of an object. Used to determine the corresponding CLOS-object.") "Identifies the type of an object. Used to determine the corresponding CLOS-object.")
(.etc (@etc
:initform nil :initform nil
:accessor json-ld-etc :accessor @etc
:documentation :documentation
"Components of the JSON object which, during parsing, did not match any specific "Components of the JSON object which, during parsing, did not match any specific
slot. This is often filled up in the case of undefined node-types or non-adherent slot. This is often filled up in the case of undefined node-types or non-adherent
@ -92,7 +90,7 @@ object definitions.")))
("@id" @id . "@id") ("@id" @id . "@id")
("@type" @type . "@type"))) ("@type" @type . "@type")))
(defgeneric json-ld-context (obj) (defgeneric @context (obj)
(:documentation (:documentation
"Returns a JSON-LD CLOS objects @context, for use in JSON-encoding of the "Returns a JSON-LD CLOS objects @context, for use in JSON-encoding of the
object. object.
@ -101,7 +99,7 @@ URL.
If you would like to change @context on a class-level, override this method. If you would like to change @context on a class-level, override this method.
If you would like to change it on an object-level, set the @CONTEXT slot.")) If you would like to change it on an object-level, set the @CONTEXT slot."))
(defmethod json-ld-context ((obj json-ld-object)) (defmethod @context ((obj json-ld-object))
(let ((slot-@context (slot-value obj '@context))) (let ((slot-@context (slot-value obj '@context)))
(unless (eq slot-@context 'no-@context) (unless (eq slot-@context 'no-@context)
(or slot-@context (or slot-@context
@ -119,9 +117,9 @@ If you would like to change it on an object-level, set the @CONTEXT slot."))
(no-context-p (aliased-prop-p "@context" type-def)) (no-context-p (aliased-prop-p "@context" type-def))
(no-id-p (aliased-prop-p "@id" type-def)) (no-id-p (aliased-prop-p "@id" type-def))
(no-type-p (aliased-prop-p "@type" type-def)) (no-type-p (aliased-prop-p "@type" type-def))
(context (json-ld-context obj)) (context (@context obj))
(id (and (slot-boundp obj '@id) (json-ld-id obj))) (id (and (slot-boundp obj '@id) (@id obj)))
(type (and (slot-boundp obj '@type) (json-ld-type obj)))) (type (and (slot-boundp obj '@type) (@type obj))))
(when (and context (not no-context-p)) (when (and context (not no-context-p))
(yason:encode-object-element "@context" context)) (yason:encode-object-element "@context" context))
(when (and id (not no-id-p)) (when (and id (not no-id-p))
@ -131,7 +129,7 @@ If you would like to change it on an object-level, set the @CONTEXT slot."))
(mapcar (lambda (alist-cell) (mapcar (lambda (alist-cell)
(yason:encode-object-element (car alist-cell) (yason:encode-object-element (car alist-cell)
(cdr alist-cell))) (cdr alist-cell)))
(json-ld-etc obj))) (@etc obj)))
(defmethod yason:encode ((obj json-ld-object) &optional (stream *standard-output)) (defmethod yason:encode ((obj json-ld-object) &optional (stream *standard-output))
(yason:with-output (stream) (yason:with-output (stream)
@ -375,10 +373,10 @@ CTX is the according parsed-context."
(lambda (property value) (lambda (property value)
(let* ((property-def (assoc property type-def :test #'equal)) (let* ((property-def (assoc property type-def :test #'equal))
(slot-name (second property-def)) (slot-name (second property-def))
(etc-value (slot-value obj '.etc))) (etc-value (slot-value obj '@etc)))
(if property-def (if property-def
(setf (slot-value obj slot-name) value) (setf (slot-value obj slot-name) value)
(setf (slot-value obj '.etc) (setf (slot-value obj '@etc)
(append etc-value (append etc-value
(list (cons property value))))))) (list (cons property value)))))))
table) table)
@ -501,8 +499,8 @@ during JSON-encoding with YASON:ENCODE."
(loop for subobj in (cdr (contained-json-objects obj)) (loop for subobj in (cdr (contained-json-objects obj))
do do
(progn (progn
(let ((old-context (json-ld-context obj)) (let ((old-context (@context obj))
(old-subcontext (json-ld-context subobj))) (old-subcontext (@context subobj)))
(when (and old-subcontext (when (and old-subcontext
(not (equal old-context old-subcontext))) (not (equal old-context old-subcontext)))
(setf (slot-value obj '@context) (setf (slot-value obj '@context)
@ -528,7 +526,7 @@ Unregistered slots that dont get encoded/decoded are ignored."
slot-defs) slot-defs)
(mapcar (lambda (etc-cons) (mapcar (lambda (etc-cons)
(cdr etc-cons)) (cdr etc-cons))
(slot-value obj '.etc)))))) (slot-value obj '@etc))))))
(defun contained-json-objects (item) (defun contained-json-objects (item)
"Given ITEM of arbitrary type, return all JSON-LD-OBJECTs contained within, "Given ITEM of arbitrary type, return all JSON-LD-OBJECTs contained within,