Update compaction algorithm. This fixes two new test failures.
jsonld.scm
| 25 | 25 | #:use-module (jsonld expansion) | |
| 26 | 26 | #:use-module (jsonld flattening) | |
| 27 | 27 | #:use-module (jsonld generate-blank-node-identifier) | |
| 28 | - | #:use-module (jsonld inverse-context-creation) | |
| 29 | 28 | #:use-module (jsonld iri-compaction) | |
| 30 | 29 | #:use-module (jsonld json) | |
| 31 | 30 | #:use-module (jsonld node-map-generation) | |
… | |||
| 61 | 60 | #:base base-iri) | |
| 62 | 61 | context context-base | |
| 63 | 62 | #:options options)) | |
| 64 | - | (inverse-context (inverse-context-creation active-context)) | |
| 65 | 63 | (compacted-output | |
| 66 | - | (compaction active-context inverse-context | |
| 64 | + | (compaction active-context | |
| 67 | 65 | json-null ;; active-property | |
| 68 | 66 | expanded-input ;; element | |
| 69 | 67 | #:compact-arrays? (jsonld-options-compact-arrays? options) | |
… | |||
| 74 | 72 | (set! compacted-output '()) | |
| 75 | 73 | (when (json-array? compacted-output) | |
| 76 | 74 | (set! compacted-output `((,(iri-compaction active-context | |
| 77 | - | inverse-context | |
| 78 | 75 | "@graph" | |
| 79 | 76 | #:vocab? #t | |
| 80 | 77 | #:reverse? #f) . | |
… | |||
| 141 | 138 | (jsonld-options-base options)) | |
| 142 | 139 | (jsonld-options-base options)) | |
| 143 | 140 | #:options options))) | |
| 141 | + | ||
| 144 | 142 | (when (and | |
| 145 | 143 | (json-object? expanded-output) | |
| 146 | 144 | (json-has-key? expanded-output "@graph") | |
jsonld/compaction.scm
| 18 | 18 | (define-module (jsonld compaction) | |
| 19 | 19 | #:use-module (jsonld context) | |
| 20 | 20 | #:use-module (jsonld context-processing) | |
| 21 | - | #:use-module (jsonld inverse-context-creation) | |
| 22 | 21 | #:use-module (jsonld iri-compaction) | |
| 23 | 22 | #:use-module (jsonld iri-expansion) | |
| 24 | 23 | #:use-module (jsonld json) | |
… | |||
| 50 | 49 | (list->array 1 new-value)))) | |
| 51 | 50 | (alist-set object key new-value))) | |
| 52 | 51 | ||
| 53 | - | (define* (compaction active-context inverse-context active-property element | |
| 52 | + | (define* (compaction active-context active-property element | |
| 54 | 53 | #:key (compact-arrays? #f) (ordered? #f) processing-mode) | |
| 55 | - | (pk 'compaction element) | |
| 56 | 54 | ;; 1 | |
| 57 | 55 | (let ((type-scoped-context active-context) | |
| 58 | 56 | (def (term-definition-ref active-context active-property))) | |
… | |||
| 68 | 66 | (for-each | |
| 69 | 67 | (lambda (item) | |
| 70 | 68 | ;; 3.2.1 | |
| 71 | - | (let ((compacted-item (compaction active-context inverse-context | |
| 69 | + | (let ((compacted-item (compaction active-context | |
| 72 | 70 | active-property item | |
| 73 | 71 | #:compact-arrays? compact-arrays? | |
| 74 | 72 | #:ordered? ordered? | |
… | |||
| 98 | 96 | (and (json-has-key? element "@id") | |
| 99 | 97 | (null? (filter (lambda (kp) (not (equal? (car kp) "@id"))) | |
| 100 | 98 | element)))) | |
| 101 | - | (set! active-context (active-context-previous active-context)) | |
| 102 | - | (set! inverse-context (inverse-context-creation active-context)))) | |
| 99 | + | (set! active-context (active-context-previous active-context)))) | |
| 103 | 100 | ;; 6 | |
| 104 | 101 | (when (and (term-definition? def) | |
| 105 | 102 | (not-null-or-false (term-definition-context def))) | |
| 106 | - | ;; 6.1 | |
| 107 | 103 | (set! active-context | |
| 108 | 104 | (context-processing active-context (term-definition-context def) | |
| 109 | 105 | (term-definition-base-url def) | |
| 110 | - | #:override-protected? #t)) | |
| 111 | - | ;; 6.2 | |
| 112 | - | (set! inverse-context (inverse-context-creation active-context))) | |
| 106 | + | #:override-protected? #t))) | |
| 113 | 107 | ;; 7 | |
| 114 | 108 | (cond | |
| 115 | 109 | ((and (or (json-has-key? element "@value") | |
| 116 | 110 | (json-has-key? element "@id")) | |
| 117 | 111 | (let ((compact | |
| 118 | - | (value-compaction active-context inverse-context | |
| 119 | - | active-property element processing-mode))) | |
| 112 | + | (value-compaction active-context active-property element | |
| 113 | + | processing-mode))) | |
| 120 | 114 | (or (scalar? compact) | |
| 121 | 115 | (and (term-definition? def) | |
| 122 | 116 | (equal? (term-definition-type def) "@json"))))) | |
| 123 | - | (value-compaction active-context inverse-context active-property | |
| 124 | - | element processing-mode)) | |
| 117 | + | (value-compaction active-context active-property element | |
| 118 | + | processing-mode)) | |
| 125 | 119 | ;; 8 | |
| 126 | 120 | ((and (json-has-key? element "@list") | |
| 127 | 121 | (member "@list" (container-mapping active-context active-property))) | |
| 128 | - | (compaction active-context inverse-context active-property | |
| 122 | + | (compaction active-context active-property | |
| 129 | 123 | (assoc-ref element "@list") | |
| 130 | 124 | #:compact-arrays? compact-arrays? | |
| 131 | 125 | #:ordered? ordered?)) | |
… | |||
| 142 | 136 | (compacted-types | |
| 143 | 137 | (map | |
| 144 | 138 | (lambda (type) | |
| 145 | - | (iri-compaction active-context inverse-context type | |
| 146 | - | #:vocab? #t #:processing-mode processing-mode)) | |
| 139 | + | (iri-compaction active-context type | |
| 140 | + | #:vocab? #t | |
| 141 | + | #:processing-mode processing-mode)) | |
| 147 | 142 | types))) | |
| 148 | - | (pk 'compacted-types compacted-types) | |
| 149 | 143 | (for-each | |
| 150 | 144 | (lambda (term) | |
| 151 | - | ;; 11.1 | |
| 152 | 145 | (when (and | |
| 153 | 146 | (term-definition? (term-definition-ref type-scoped-context term)) | |
| 154 | 147 | (term-definition-context | |
| 155 | 148 | (term-definition-ref type-scoped-context term))) | |
| 156 | - | ;; 11.1.1 | |
| 157 | 149 | (set! active-context | |
| 158 | 150 | (context-processing | |
| 159 | 151 | active-context | |
… | |||
| 161 | 153 | (term-definition-ref type-scoped-context term)) | |
| 162 | 154 | (term-definition-base-url | |
| 163 | 155 | (term-definition-ref type-scoped-context term)) | |
| 164 | - | #:propagate? #f)) | |
| 165 | - | ;; 11.1.2 | |
| 166 | - | (set! inverse-context | |
| 167 | - | (inverse-context-creation active-context)))) | |
| 156 | + | #:propagate? #f)))) | |
| 168 | 157 | (sort compacted-types string<=?)))) | |
| 169 | 158 | ;; 12 | |
| 170 | 159 | (for-each-pair | |
| 171 | 160 | (lambda (expanded-property expanded-value) | |
| 172 | 161 | (set! result | |
| 173 | - | (step-12 active-context inverse-context expanded-property | |
| 162 | + | (step-12 active-context expanded-property | |
| 174 | 163 | expanded-value result compact-arrays? ordered? | |
| 175 | 164 | inside-reverse? type-scoped-context active-property | |
| 176 | 165 | processing-mode))) | |
… | |||
| 180 | 169 | ;; 13 | |
| 181 | 170 | result))))))) | |
| 182 | 171 | ||
| 183 | - | (define (step-12 active-context inverse-context expanded-property expanded-value | |
| 172 | + | (define (step-12 active-context expanded-property expanded-value | |
| 184 | 173 | result compact-arrays? ordered? inside-reverse? type-scoped-context | |
| 185 | 174 | active-property processing-mode) | |
| 186 | 175 | (cond | |
| 187 | 176 | ;; 12.1 | |
| 188 | 177 | ((equal? expanded-property "@id") | |
| 189 | - | (pk 'expanded-value expanded-value) | |
| 190 | 178 | ;; XXX: not clear what to do if expanded-value is not a | |
| 191 | 179 | ;; string, make sure there is a test | |
| 192 | 180 | (let ((compacted-value | |
| 193 | 181 | (if (string? expanded-value) | |
| 194 | - | (iri-compaction active-context inverse-context expanded-value | |
| 182 | + | (iri-compaction active-context expanded-value | |
| 195 | 183 | #:vocab? #f #:processing-mode processing-mode) | |
| 196 | 184 | expanded-value)) | |
| 197 | - | (alias (iri-compaction active-context inverse-context expanded-property | |
| 185 | + | (alias (iri-compaction active-context expanded-property | |
| 198 | 186 | #:vocab? #t #:processing-mode processing-mode))) | |
| 199 | - | (pk 'compacted-value compacted-value) | |
| 200 | - | (pk 'alias alias) | |
| 201 | 187 | (set! result | |
| 202 | 188 | (alist-set result alias compacted-value)))) | |
| 203 | 189 | ;; 12.2 | |
| 204 | 190 | ((equal? expanded-property "@type") | |
| 205 | 191 | (let* ((compacted-value #f) | |
| 206 | - | (alias (iri-compaction active-context inverse-context expanded-property | |
| 192 | + | ;; 12.2.3 | |
| 193 | + | (alias (iri-compaction active-context expanded-property | |
| 207 | 194 | #:vocab? #t #:processing-mode processing-mode)) | |
| 195 | + | ;; 12.2.4 | |
| 208 | 196 | (as-array? | |
| 209 | 197 | (or | |
| 210 | 198 | (and | |
| 211 | - | (not (processing-mode-1.0? processing-mode)) | |
| 199 | + | (processing-mode-1.1? processing-mode) | |
| 212 | 200 | (member "@set" (container-mapping active-context alias))) | |
| 213 | - | (not compact-arrays?))) | |
| 214 | - | (type-scoped-inverse-context | |
| 215 | - | (inverse-context-creation type-scoped-context))) | |
| 216 | - | (pk 'alias alias) | |
| 201 | + | (not compact-arrays?)))) | |
| 217 | 202 | (if (string? expanded-value) | |
| 203 | + | ;; 12.1 | |
| 218 | 204 | (set! compacted-value | |
| 219 | - | (iri-compaction type-scoped-context type-scoped-inverse-context | |
| 205 | + | (iri-compaction type-scoped-context | |
| 220 | 206 | expanded-value | |
| 221 | 207 | #:vocab? #t #:processing-mode processing-mode)) | |
| 208 | + | ;; 12.2 | |
| 222 | 209 | (begin | |
| 223 | 210 | (set! expanded-value (array->list expanded-value)) | |
| 224 | 211 | (set! compacted-value | |
| 225 | 212 | (list->array 1 | |
| 226 | 213 | (map | |
| 227 | - | (lambda (v) | |
| 228 | - | (pk 'v (iri-compaction type-scoped-context type-scoped-inverse-context | |
| 229 | - | v | |
| 230 | - | #:vocab? #t #:processing-mode processing-mode))) | |
| 214 | + | (lambda (expanded-type) | |
| 215 | + | (iri-compaction type-scoped-context expanded-type | |
| 216 | + | #:vocab? #t | |
| 217 | + | #:processing-mode processing-mode)) | |
| 231 | 218 | expanded-value))))) | |
| 232 | - | (pk 'compacted-value compacted-value) | |
| 219 | + | ;; XXX: not in spec | |
| 233 | 220 | (when (and (json-array? compacted-value) (= (array-length compacted-value) 1)) | |
| 234 | 221 | (set! compacted-value (car (array->list compacted-value)))) | |
| 235 | 222 | (set! result | |
| 236 | 223 | (add-value result alias compacted-value as-array?)))) | |
| 237 | 224 | ;; 12.3 | |
| 238 | 225 | ((equal? expanded-property "@reverse") | |
| 226 | + | ;; 12.3.1 | |
| 239 | 227 | (let ((compacted-value | |
| 240 | - | (compaction active-context inverse-context "@reverse" expanded-value | |
| 228 | + | (compaction active-context "@reverse" expanded-value | |
| 241 | 229 | #:compact-arrays? compact-arrays? #:ordered? ordered?))) | |
| 242 | 230 | ;; 12.3.2 | |
| 243 | 231 | (for-each-pair | |
| 244 | 232 | (lambda (property value) | |
| 245 | 233 | (let ((def (term-definition-ref active-context property))) | |
| 246 | 234 | (when (and (term-definition? def) (term-definition-reverse? def)) | |
| 235 | + | ;; 12.3.2.1.1 | |
| 247 | 236 | (let ((as-array? (or | |
| 248 | 237 | (member "@set" | |
| 249 | 238 | (container-mapping active-context property)) | |
| 250 | 239 | (not compact-arrays?)))) | |
| 240 | + | ;; 12.3.2.1.2 | |
| 251 | 241 | (set! result | |
| 252 | 242 | (add-value result property value as-array?))) | |
| 243 | + | ;; 12.3.2.1.3 | |
| 253 | 244 | (set! compacted-value | |
| 254 | 245 | (alist-remove compacted-value property))))) | |
| 255 | 246 | compacted-value) | |
| 256 | 247 | ;; 12.3.3 | |
| 257 | 248 | (unless (null? compacted-value) | |
| 258 | - | (let ((alias (iri-compaction active-context inverse-context "@reverse" | |
| 249 | + | (let ((alias (iri-compaction active-context "@reverse" | |
| 259 | 250 | #:vocab? #t #:processing-mode processing-mode))) | |
| 260 | - | (pk 'alias alias) | |
| 261 | 251 | (set! result (alist-set result alias compacted-value)))))) | |
| 262 | 252 | ;; 12.4 | |
| 263 | 253 | ((equal? expanded-property "@preserve") | |
| 264 | 254 | (let ((compacted-value | |
| 265 | - | (compaction active-context inverse-context active-property | |
| 266 | - | expanded-value #:compact-arrays? compact-arrays? | |
| 255 | + | (compaction active-context active-property expanded-value | |
| 256 | + | #:compact-arrays? compact-arrays? | |
| 267 | 257 | #:ordered? ordered?))) | |
| 268 | 258 | (unless (equal? expanded-value #()) | |
| 269 | 259 | (set! result (alist-set result "@preserve" compacted-value))))) | |
… | |||
| 277 | 267 | (equal? expanded-property "@index") | |
| 278 | 268 | (equal? expanded-property "@language") | |
| 279 | 269 | (equal? expanded-property "@value")) | |
| 280 | - | (let ((alias (iri-compaction active-context inverse-context expanded-property | |
| 270 | + | (let ((alias (iri-compaction active-context expanded-property | |
| 281 | 271 | #:vocab? #t #:processing-mode processing-mode))) | |
| 282 | - | (pk 'alias alias) | |
| 283 | 272 | (set! result | |
| 284 | 273 | (alist-set result alias expanded-value)))) | |
| 285 | 274 | (else | |
| 286 | 275 | ;; 12.7 | |
| 287 | 276 | (when (equal? expanded-value #()) | |
| 288 | 277 | (let* ((item-active-property | |
| 289 | - | (iri-compaction active-context inverse-context expanded-property | |
| 278 | + | (iri-compaction active-context expanded-property | |
| 290 | 279 | #:value expanded-value | |
| 291 | 280 | #:vocab? #t | |
| 292 | 281 | #:reverse? inside-reverse? | |
… | |||
| 296 | 285 | (nest-term (if (term-definition? def) (term-definition-nest def) #f)) | |
| 297 | 286 | ;; 12.7.4 | |
| 298 | 287 | (nest-result result)) | |
| 299 | - | (pk 'item-active-property item-active-property) | |
| 300 | 288 | ;; 12.7.2 | |
| 301 | 289 | (when nest-term | |
| 302 | 290 | (unless (or (equal? nest-term "@nest") | |
… | |||
| 316 | 304 | (lambda (expanded-item) | |
| 317 | 305 | (let* ((item-active-property | |
| 318 | 306 | (iri-compaction | |
| 319 | - | active-context inverse-context expanded-property | |
| 307 | + | active-context expanded-property | |
| 320 | 308 | #:value expanded-item | |
| 321 | 309 | #:vocab? #t | |
| 322 | 310 | #:reverse? inside-reverse? | |
… | |||
| 334 | 322 | (not compact-arrays?))) | |
| 335 | 323 | ;; 12.8.6 | |
| 336 | 324 | (compacted-item | |
| 337 | - | (compaction active-context inverse-context item-active-property | |
| 325 | + | (compaction active-context item-active-property | |
| 338 | 326 | (if (json-has-key? expanded-item "@list") | |
| 339 | 327 | (assoc-ref expanded-item "@list") | |
| 340 | 328 | (if (graph-object? expanded-item) | |
… | |||
| 342 | 330 | expanded-item)) | |
| 343 | 331 | #:compact-arrays? compact-arrays? | |
| 344 | 332 | #:ordered? ordered?))) | |
| 345 | - | (pk 'item-active-property item-active-property) | |
| 346 | 333 | ;; 12.8.2 | |
| 347 | 334 | (when (not-null-or-false nest-term) | |
| 348 | 335 | (unless (or (equal? nest-term "@nest") | |
… | |||
| 365 | 352 | ;; 12.8.7.2 | |
| 366 | 353 | (begin | |
| 367 | 354 | (set! compacted-item | |
| 368 | - | `((,(iri-compaction active-context inverse-context | |
| 369 | - | "@list" #:vocab? #t | |
| 355 | + | `((,(iri-compaction active-context "@list" #:vocab? #t | |
| 370 | 356 | #:processing-mode processing-mode) . | |
| 371 | 357 | ,compacted-item))) | |
| 372 | 358 | (when (json-has-key? expanded-item "@index") | |
| 373 | 359 | (set! compacted-item | |
| 374 | 360 | (alist-set | |
| 375 | 361 | compacted-item | |
| 376 | - | (iri-compaction active-context inverse-context | |
| 377 | - | "@index" #:vocab? #t | |
| 362 | + | (iri-compaction active-context "@index" #:vocab? #t | |
| 378 | 363 | #:processing-mode processing-mode) | |
| 379 | 364 | (assoc-ref expanded-item "@index")))) | |
| 380 | 365 | (set! nest-result | |
… | |||
| 395 | 380 | "@none")) | |
| 396 | 381 | (map-key | |
| 397 | 382 | (iri-compaction | |
| 398 | - | active-context inverse-context map-key | |
| 383 | + | active-context map-key | |
| 399 | 384 | #:vocab? (not (json-has-key? expanded-item "@id")) | |
| 400 | 385 | #:processing-mode processing-mode))) | |
| 401 | 386 | ;; 12.8.8.1.3 | |
… | |||
| 426 | 411 | (when (and (json-array? compacted-item) | |
| 427 | 412 | (> (array-length compacted-item) 1)) | |
| 428 | 413 | (set! compacted-item | |
| 429 | - | `((,(iri-compaction active-context inverse-context "@included" | |
| 430 | - | #:vocab? #t #:processing-mode processing-mode) . | |
| 414 | + | `((,(iri-compaction active-context "@included" | |
| 415 | + | #:vocab? #t | |
| 416 | + | #:processing-mode processing-mode) . | |
| 431 | 417 | ,compacted-item)))) | |
| 432 | 418 | (set! nest-result | |
| 433 | 419 | (add-value nest-result item-active-property compacted-item | |
… | |||
| 437 | 423 | (else | |
| 438 | 424 | ;; 12.8.8.4.1 | |
| 439 | 425 | (set! compacted-item | |
| 440 | - | `((,(iri-compaction active-context inverse-context "@graph" | |
| 441 | - | #:vocab? #t #:processing-mode processing-mode) . | |
| 426 | + | `((,(iri-compaction active-context "@graph" | |
| 427 | + | #:vocab? #t | |
| 428 | + | #:processing-mode processing-mode) . | |
| 442 | 429 | ,compacted-item))) | |
| 443 | 430 | ;; 12.8.8.4.2 | |
| 444 | 431 | (when (json-has-key? expanded-item "@id") | |
| 445 | 432 | (set! compacted-item | |
| 446 | 433 | (alist-set | |
| 447 | 434 | compacted-item | |
| 448 | - | (iri-compaction active-context inverse-context "@id" | |
| 435 | + | (iri-compaction active-context "@id" | |
| 449 | 436 | #:vocab? #t | |
| 450 | 437 | #:processing-mode processing-mode) | |
| 451 | - | (iri-compaction active-context inverse-context | |
| 438 | + | (iri-compaction active-context | |
| 452 | 439 | (assoc-ref expanded-item "@id") | |
| 453 | 440 | #:vocab? #f | |
| 454 | 441 | #:processing-mode processing-mode)))) | |
… | |||
| 457 | 444 | (set! compacted-item | |
| 458 | 445 | (alist-set | |
| 459 | 446 | compacted-item | |
| 460 | - | (iri-compaction active-context inverse-context "@index" | |
| 447 | + | (iri-compaction active-context "@index" | |
| 461 | 448 | #:vocab? #t | |
| 462 | 449 | #:processing-mode processing-mode) | |
| 463 | 450 | (assoc-ref expanded-item "@index")))) | |
… | |||
| 476 | 463 | (let* ((map-object (or (assoc-ref nest-result item-active-property) | |
| 477 | 464 | '())) | |
| 478 | 465 | ;; 12.8.9.2 | |
| 479 | - | (container-key (iri-compaction active-context inverse-context | |
| 466 | + | (container-key (iri-compaction active-context | |
| 480 | 467 | (cond | |
| 481 | 468 | ((member "@language" container) "@language") | |
| 482 | 469 | ((member "@index" container) "@index") | |
… | |||
| 505 | 492 | ((member "@index" container) | |
| 506 | 493 | ;; 12.8.9.6.1 | |
| 507 | 494 | (set! container-key | |
| 508 | - | (iri-compaction active-context inverse-context index-key | |
| 495 | + | (iri-compaction active-context | |
| 496 | + | (assoc-ref | |
| 497 | + | (iri-expansion active-context index-key | |
| 498 | + | #:vocab? #t) | |
| 499 | + | "iri") | |
| 509 | 500 | #:vocab? #t)) | |
| 510 | 501 | ;; 12.8.9.6.2 | |
| 511 | 502 | (let* ((keys (assoc-ref compacted-item container-key)) | |
… | |||
| 561 | 552 | "@id")) | |
| 562 | 553 | (set! compacted-item | |
| 563 | 554 | (compaction | |
| 564 | - | active-context inverse-context item-active-property | |
| 555 | + | active-context item-active-property | |
| 565 | 556 | `(("@id" . ,(assoc-ref expanded-item "@id"))))))))) | |
| 566 | 557 | ;; 12.8.9.9 | |
| 567 | 558 | (when (json-null? map-key) | |
| 568 | - | (set! map-key (iri-compaction active-context inverse-context | |
| 569 | - | "@none" #:vocab? #t))) | |
| 559 | + | (set! map-key (iri-compaction active-context "@none" | |
| 560 | + | #:vocab? #t))) | |
| 570 | 561 | ;; 12.8.9.10 | |
| 571 | 562 | (set! map-object | |
| 572 | 563 | (add-value map-object map-key compacted-item as-array?)) | |
jsonld/context-processing.scm
| 38 | 38 | "Process a context. This is an implementation of the context processing | |
| 39 | 39 | algorithm defined in the JsonLD API specification. | |
| 40 | 40 | ||
| 41 | - | See @url{https://www.w3.org/TR/2014/REC-json-ld-api-20140116}." | |
| 41 | + | See @url{https://w3c.github.io/json-ld-api/#context-processing-algorithm}." | |
| 42 | 42 | ;; 1 | |
| 43 | - | (define result active-context) | |
| 43 | + | (define result (update-active-context active-context #:inverse-context json-null)) | |
| 44 | 44 | ;; 2 | |
| 45 | 45 | (when (json-has-key? local-context "@propagate") | |
| 46 | 46 | (set! propagate? (assoc-ref local-context "@propagate"))) |
jsonld/context.scm
| 24 | 24 | active-context-definitions | |
| 25 | 25 | active-context-base | |
| 26 | 26 | active-context-original-base | |
| 27 | + | active-context-inverse-context | |
| 27 | 28 | active-context-vocab | |
| 28 | 29 | active-context-language | |
| 29 | 30 | active-context-direction | |
… | |||
| 53 | 54 | ;;; Section 4.1: definitions of an Active Context and a Term Definition | |
| 54 | 55 | ||
| 55 | 56 | (define-record-type active-context | |
| 56 | - | (make-active-context definitions base original-base vocab language direction | |
| 57 | - | previous) | |
| 57 | + | (make-active-context definitions base original-base inverse-context vocab | |
| 58 | + | language direction previous) | |
| 58 | 59 | active-context? | |
| 59 | - | (definitions active-context-definitions) | |
| 60 | - | (base active-context-base) | |
| 61 | - | (original-base active-context-original-base) | |
| 62 | - | (vocab active-context-vocab) | |
| 63 | - | (language active-context-language) | |
| 64 | - | (direction active-context-direction) | |
| 65 | - | (previous active-context-previous)) | |
| 60 | + | (definitions active-context-definitions) | |
| 61 | + | (base active-context-base) | |
| 62 | + | (original-base active-context-original-base) | |
| 63 | + | (inverse-context active-context-inverse-context) | |
| 64 | + | (vocab active-context-vocab) | |
| 65 | + | (language active-context-language) | |
| 66 | + | (direction active-context-direction) | |
| 67 | + | (previous active-context-previous)) | |
| 66 | 68 | ||
| 67 | 69 | (define* (update-active-context | |
| 68 | 70 | active-context | |
| 69 | - | #:key (definitions (active-context-definitions active-context)) | |
| 70 | - | (base (active-context-base active-context)) | |
| 71 | - | (original-base (active-context-original-base active-context)) | |
| 72 | - | (vocab (active-context-vocab active-context)) | |
| 73 | - | (language (active-context-language active-context)) | |
| 74 | - | (direction (active-context-direction active-context)) | |
| 75 | - | (previous (active-context-previous active-context))) | |
| 76 | - | (make-active-context definitions base original-base vocab language direction | |
| 77 | - | previous)) | |
| 71 | + | #:key (definitions (active-context-definitions active-context)) | |
| 72 | + | (base (active-context-base active-context)) | |
| 73 | + | (original-base (active-context-original-base active-context)) | |
| 74 | + | (inverse-context (active-context-inverse-context active-context)) | |
| 75 | + | (vocab (active-context-vocab active-context)) | |
| 76 | + | (language (active-context-language active-context)) | |
| 77 | + | (direction (active-context-direction active-context)) | |
| 78 | + | (previous (active-context-previous active-context))) | |
| 79 | + | (make-active-context definitions base original-base inverse-context vocab | |
| 80 | + | language direction previous)) | |
| 78 | 81 | ||
| 79 | 82 | (define* (new-active-context | |
| 80 | - | #:key (definitions '()) | |
| 81 | - | (base #f) | |
| 82 | - | (original-base #f) | |
| 83 | - | (vocab #f) | |
| 84 | - | (language #f) | |
| 85 | - | (direction #f) | |
| 86 | - | (previous json-null)) | |
| 87 | - | (make-active-context definitions base original-base vocab language direction | |
| 88 | - | previous)) | |
| 83 | + | #:key (definitions '()) | |
| 84 | + | (base #f) | |
| 85 | + | (original-base #f) | |
| 86 | + | (inverse-context json-null) | |
| 87 | + | (vocab #f) | |
| 88 | + | (language #f) | |
| 89 | + | (direction #f) | |
| 90 | + | (previous json-null)) | |
| 91 | + | (make-active-context definitions base original-base inverse-context vocab | |
| 92 | + | language direction previous)) | |
| 89 | 93 | ||
| 90 | 94 | (define-record-type term-definition | |
| 91 | 95 | (make-term-definition iri prefix? protected? reverse? base-url context container | |
jsonld/deserialize-jsonld.scm
| 54 | 54 | (define* (deserialize-jsonld generate-blank-node node-map dataset | |
| 55 | 55 | #:key produce-generalized-rdf? rdf-direction) | |
| 56 | 56 | ;; 1 | |
| 57 | - | (pk 'node-map node-map) | |
| 58 | 57 | (for-each-pair | |
| 59 | 58 | (lambda (graph-name graph) | |
| 60 | 59 | ;; 1.1 |
jsonld/iri-compaction.scm
| 18 | 18 | (define-module (jsonld iri-compaction) | |
| 19 | 19 | #:use-module (iri iri) | |
| 20 | 20 | #:use-module (jsonld context) | |
| 21 | + | #:use-module (jsonld inverse-context-creation) | |
| 21 | 22 | #:use-module (jsonld json) | |
| 22 | 23 | #:use-module (jsonld term-selection) | |
| 23 | 24 | #:export (iri-compaction)) | |
… | |||
| 28 | 29 | (unless var | |
| 29 | 30 | (set! var val))))) | |
| 30 | 31 | ||
| 31 | - | (define* (iri-compaction active-context inverse-context var | |
| 32 | + | (define* (iri-compaction active-context var | |
| 32 | 33 | #:key value vocab? reverse? processing-mode) | |
| 33 | 34 | ;; not specified, but sometimes the spec leads to var being an array, so | |
| 34 | 35 | ;; in that case we iri-compact each part of it and return an array. | |
| 35 | 36 | (cond | |
| 36 | - | ;; 2 | |
| 37 | + | ;; 1 | |
| 37 | 38 | ((json-null? var) json-null) | |
| 39 | + | ;; XXX: addition to spec | |
| 38 | 40 | ((json-array? var) | |
| 39 | 41 | (list->array 1 | |
| 40 | 42 | (map | |
| 41 | 43 | (lambda (val) | |
| 42 | - | (iri-compaction active-context inverse-context val | |
| 44 | + | (iri-compaction active-context val | |
| 43 | 45 | #:value value | |
| 44 | 46 | #:vocab? vocab? | |
| 45 | 47 | #:reverse? reverse? | |
… | |||
| 47 | 49 | (array->list var)))) | |
| 48 | 50 | (else | |
| 49 | 51 | (begin | |
| 50 | - | (let ((result #f)) | |
| 51 | - | (pk 'inverse (assoc-ref inverse-context var)) | |
| 52 | - | ;; 2 | |
| 52 | + | ;; 2 | |
| 53 | + | (when (json-null? (active-context-inverse-context active-context)) | |
| 54 | + | (set! active-context | |
| 55 | + | (update-active-context active-context | |
| 56 | + | #:inverse-context | |
| 57 | + | (inverse-context-creation active-context)))) | |
| 58 | + | ;; 3 | |
| 59 | + | (let* ((inverse-context (active-context-inverse-context active-context)) | |
| 60 | + | (result #f)) | |
| 61 | + | ;; 4 | |
| 53 | 62 | (when (and vocab? (json-has-key? inverse-context var)) | |
| 54 | 63 | (let ((default-language | |
| 55 | - | ;; 2.1 | |
| 56 | - | (if (or (not-null-or-false (active-context-direction active-context)) | |
| 57 | - | (not-null-or-false (active-context-language active-context))) | |
| 64 | + | ;; 4.1 | |
| 65 | + | (if (not-null-or-false (active-context-direction active-context)) | |
| 58 | 66 | (string-append | |
| 59 | - | (or (not-null-or-false (active-context-language active-context)) | |
| 60 | - | "") | |
| 67 | + | (string-downcase | |
| 68 | + | (or (not-null-or-false (active-context-language active-context)) | |
| 69 | + | "")) | |
| 61 | 70 | "_" | |
| 62 | - | (or (not-null-or-false (active-context-direction active-context)) | |
| 63 | - | "")) | |
| 64 | - | "@none")) | |
| 65 | - | ;; 2.3 | |
| 71 | + | (active-context-direction active-context)) | |
| 72 | + | (string-downcase | |
| 73 | + | (or (not-null-or-false (active-context-language active-context)) | |
| 74 | + | "@none")))) | |
| 75 | + | ;; 4.3 | |
| 66 | 76 | (containers '()) | |
| 67 | - | ;; 2.4 | |
| 77 | + | ;; 4.4 | |
| 68 | 78 | (type/language "@language") | |
| 69 | 79 | (type/language-value "@null") | |
| 70 | - | ;; 2.14 | |
| 80 | + | ;; 4.14 | |
| 71 | 81 | (preferred-values '())) | |
| 72 | - | ;; 2.2 | |
| 82 | + | ;; 4.2 | |
| 73 | 83 | (when (json-has-key? value "@preserve") | |
| 74 | - | (set! value (assoc-ref value "@preserve"))) | |
| 75 | - | ;; 2.5 | |
| 84 | + | (let ((preserve (assoc-ref value "@preserve"))) | |
| 85 | + | (set! value | |
| 86 | + | (if (json-array? preserve) | |
| 87 | + | (car (array->list preserve)) | |
| 88 | + | preserve)))) | |
| 89 | + | ;; 4.5 | |
| 76 | 90 | (when (and (json-has-key? value "@index") | |
| 77 | 91 | (not (graph-object? value))) | |
| 78 | 92 | (set! containers | |
| 79 | 93 | (append containers '("@index" "@index@set")))) | |
| 80 | 94 | (cond | |
| 81 | - | ;; 2.6 | |
| 95 | + | ;; 4.6 | |
| 82 | 96 | (reverse? | |
| 83 | 97 | (set! type/language "@type") | |
| 84 | 98 | (set! type/language-value "@reverse") | |
| 85 | 99 | (set! containers (append containers '("@set")))) | |
| 86 | - | ;; 2.7 | |
| 100 | + | ;; 4.7 | |
| 87 | 101 | ((list-object? value) | |
| 88 | - | ;; 2.7.1 | |
| 102 | + | ;; 4.7.1 | |
| 89 | 103 | (unless (json-has-key? value "@index") | |
| 90 | 104 | (set! containers (append containers '("@list")))) | |
| 91 | - | ;; 2.7.2 | |
| 105 | + | ;; 4.7.2 | |
| 92 | 106 | (let ((lst (array->list (assoc-ref value "@list"))) | |
| 93 | - | ;; 2.7.3 | |
| 107 | + | ;; 4.7.3 | |
| 94 | 108 | (common-type json-null) | |
| 95 | 109 | (common-language json-null)) | |
| 96 | 110 | (when (null? lst) | |
| 97 | 111 | (set! common-language default-language)) | |
| 98 | - | ;; 2.7.4 | |
| 112 | + | ;; 4.7.4 | |
| 99 | 113 | (for-each | |
| 100 | 114 | (lambda (item) | |
| 101 | - | ;; 2.7.4.1 | |
| 115 | + | ;; 4.7.4.1 | |
| 102 | 116 | (let ((item-language "@none") | |
| 103 | 117 | (item-type "@none")) | |
| 104 | 118 | (if (json-has-key? item "@value") | |
| 105 | - | ;; 2.7.4.2 | |
| 119 | + | ;; 4.7.4.2 | |
| 106 | 120 | (cond | |
| 107 | 121 | ((json-has-key? item "@direction") | |
| 108 | 122 | (set! item-language | |
… | |||
| 116 | 130 | (set! item-type (assoc-ref item "@type"))) | |
| 117 | 131 | (else | |
| 118 | 132 | (set! item-language "@null"))) | |
| 119 | - | ;; 2.7.4.3 | |
| 133 | + | ;; 4.7.4.3 | |
| 120 | 134 | (set! item-type "@id")) | |
| 121 | - | ;; 2.7.4.4 | |
| 135 | + | ;; 4.7.4.4 | |
| 122 | 136 | (if (json-null? common-language) | |
| 123 | 137 | (set! common-language item-language) | |
| 124 | 138 | (unless (or (equal? common-language item-language) | |
| 125 | 139 | (not (json-has-key? item "@value"))) | |
| 126 | 140 | (set! common-language "@none"))) | |
| 127 | - | ;; 2.7.4.6 | |
| 141 | + | ;; 4.7.4.6 | |
| 128 | 142 | (if (json-null? common-type) | |
| 129 | 143 | (set! common-type item-type) | |
| 130 | 144 | (unless (equal? common-type item-type) | |
| 131 | 145 | (set! common-type "@none"))))) | |
| 132 | 146 | lst) | |
| 133 | - | ;; 2.7.5 | |
| 147 | + | ;; 4.7.5 | |
| 134 | 148 | (when (json-null? common-language) | |
| 135 | 149 | (set! common-language "@none")) | |
| 136 | 150 | (when (json-null? common-type) | |
… | |||
| 140 | 154 | (set! type/language "@type") | |
| 141 | 155 | (set! type/language-value common-type)) | |
| 142 | 156 | (set! type/language-value common-language)))) | |
| 143 | - | ;; 2.8 | |
| 157 | + | ;; 4.8 | |
| 144 | 158 | ((graph-object? value) | |
| 145 | - | ;; 2.8.1 | |
| 159 | + | ;; 4.8.1 | |
| 146 | 160 | (when (json-has-key? value "@index") | |
| 147 | 161 | (set! containers | |
| 148 | 162 | (append containers '("@graph@index" "@graph@index@set")))) | |
| 149 | - | ;; 2.8.2 | |
| 163 | + | ;; 4.8.2 | |
| 150 | 164 | (when (json-has-key? value "@id") | |
| 151 | 165 | (set! containers | |
| 152 | 166 | (append containers '("@graph@id" "@graph@id@set")))) | |
| 153 | - | ;; 2.8.3 | |
| 167 | + | ;; 4.8.3 | |
| 154 | 168 | (set! containers | |
| 155 | 169 | (append containers '("@graph" "@graph@set" "@set"))) | |
| 156 | - | ;; 2.8.4 | |
| 170 | + | ;; 4.8.4 | |
| 157 | 171 | (unless (json-has-key? value "@index") | |
| 158 | 172 | (set! containers | |
| 159 | 173 | (append containers '("@graph@index" "@graph@index@set")))) | |
| 160 | - | ;; 2.8.5 | |
| 174 | + | ;; 4.8.5 | |
| 161 | 175 | (unless (json-has-key? value "@id") | |
| 162 | 176 | (set! containers | |
| 163 | 177 | (append containers '("@graph@id" "@graph@id@set")))) | |
| 164 | - | ;; 2.8.6 | |
| 178 | + | ;; 4.8.6 | |
| 165 | 179 | (set! containers | |
| 166 | 180 | (append containers '("@index" "@index@set"))) | |
| 167 | - | ;; 2.8.7 | |
| 181 | + | ;; 4.8.7 | |
| 168 | 182 | (set! type/language "@type") | |
| 169 | 183 | (set! type/language-value "@id")) | |
| 170 | - | ;; 2.9.1 and 2.9.3 | |
| 184 | + | ;; 4.9.1 and 4.9.3 | |
| 171 | 185 | ((json-has-key? value "@value") | |
| 172 | 186 | (cond | |
| 173 | 187 | ((and (json-has-key? value "@direction") | |
… | |||
| 188 | 202 | (set! type/language-value (assoc-ref value "@type")) | |
| 189 | 203 | (set! type/language "@type"))) | |
| 190 | 204 | (set! containers (append containers '("@set")))) | |
| 191 | - | ;; 2.9.2 and 2.9.3 | |
| 205 | + | ;; 4.9.2 and 4.9.3 | |
| 192 | 206 | (else | |
| 193 | 207 | (set! type/language "@type") | |
| 194 | 208 | (set! type/language-value "@id") | |
| 195 | 209 | (set! containers | |
| 196 | 210 | (append containers '("@id" "@id@set" "@type" "@set@type" "@set"))))) | |
| 197 | - | ;;2.10 | |
| 211 | + | ;; 4.10 | |
| 198 | 212 | (set! containers (append containers '("@none"))) | |
| 199 | - | ;; 2.11 | |
| 213 | + | ;; 4.11 | |
| 200 | 214 | (unless (processing-mode-1.0? processing-mode) | |
| 201 | 215 | (unless (json-has-key? value "@index") | |
| 202 | 216 | (set! containers (append containers '("@index" "@index@set")))) | |
| 203 | - | ;; 2.12 | |
| 217 | + | ;; 4.12 | |
| 204 | 218 | (when (and (json-has-key? value "@value") | |
| 205 | 219 | (null? (filter (lambda (kp) (not (equal? (car kp) "@value"))) | |
| 206 | 220 | value))) | |
| 207 | 221 | (set! containers (append containers '("@language" "@language@set"))))) | |
| 208 | - | ;; 2.13 | |
| 222 | + | ;; 4.13 | |
| 209 | 223 | (when (equal? type/language-value json-null) | |
| 210 | 224 | (set! type/language-value "@null")) | |
| 211 | - | ;; 2.15 | |
| 225 | + | ;; 4.15 | |
| 212 | 226 | (when (equal? type/language-value "@reverse") | |
| 213 | 227 | (set! preferred-values (append preferred-values '("@reverse")))) | |
| 214 | - | ;; 2.16 | |
| 228 | + | ;; 4.16 | |
| 215 | 229 | (if (and (or (equal? type/language-value "@reverse") | |
| 216 | 230 | (equal? type/language-value "@id")) | |
| 217 | 231 | (json-has-key? value "@id")) | |
| 218 | - | (let* ((compacted-iri (iri-compaction active-context inverse-context | |
| 232 | + | (let* ((compacted-iri (iri-compaction active-context | |
| 219 | 233 | (assoc-ref value "@id") | |
| 220 | 234 | #:vocab? #t | |
| 221 | 235 | #:processing-mode processing-mode)) | |
… | |||
| 228 | 242 | (append preferred-values '("@vocab" "@id" "@none"))) | |
| 229 | 243 | (set! preferred-values | |
| 230 | 244 | (append preferred-values '("@id" "@vocab" "@none"))))) | |
| 231 | - | ;; 2.17 | |
| 245 | + | ;; 4.17 | |
| 232 | 246 | (begin | |
| 233 | 247 | (when (equal? (assoc-ref value "@list") #()) | |
| 234 | 248 | (set! type/language "@any")) | |
| 235 | 249 | (set! preferred-values | |
| 236 | 250 | (append preferred-values (list type/language-value "@none"))))) | |
| 237 | - | ;; 2.18 | |
| 251 | + | ;; 4.18 | |
| 238 | 252 | (set! preferred-values (append preferred-values '("@any"))) | |
| 239 | - | ;; 2.19 | |
| 253 | + | ;; 4.19 | |
| 240 | 254 | (let* ((underscore-vals (filter | |
| 241 | 255 | (lambda (s) | |
| 242 | 256 | (string-index s #\_)) | |
… | |||
| 249 | 263 | (list | |
| 250 | 264 | (string-join | |
| 251 | 265 | (cons "" (cdr (string-split underscore #\_))) "_")))))) | |
| 252 | - | ;; 2.20 | |
| 253 | - | (let ((term (term-selection inverse-context var containers type/language preferred-values))) | |
| 266 | + | ;; 4.20 | |
| 267 | + | (let ((term (term-selection active-context var containers | |
| 268 | + | type/language preferred-values))) | |
| 254 | 269 | (when (not-null-or-false term) | |
| 255 | 270 | (set-cond! result term))))) | |
| 256 | - | ;; 3 | |
| 271 | + | ;; 5 | |
| 257 | 272 | (when (and vocab? (not-null-or-false (active-context-vocab active-context))) | |
| 258 | 273 | (let ((vocab (active-context-vocab active-context))) | |
| 259 | - | (pk 'vocab vocab var) | |
| 260 | 274 | (when (and (>= (string-length var) (string-length vocab)) | |
| 261 | 275 | (equal? (substring var 0 (string-length vocab)) vocab)) | |
| 262 | 276 | (let ((suffix (substring var (string-length vocab)))) | |
| 263 | 277 | (when (not (not-null-or-false (term-definition-ref active-context suffix))) | |
| 264 | 278 | (set-cond! result suffix)))))) | |
| 265 | - | ;; 4 | |
| 279 | + | ;; 6 | |
| 266 | 280 | (let ((compact-iri json-null)) | |
| 267 | - | ;; 5 | |
| 281 | + | ;; 7 | |
| 268 | 282 | (for-each-pair | |
| 269 | 283 | (lambda (term def) | |
| 270 | - | ;; 5.1 | |
| 284 | + | ;; 7.1 | |
| 271 | 285 | (unless (or (json-null? (term-definition-iri def)) | |
| 272 | 286 | (equal? (term-definition-iri def) var) | |
| 273 | 287 | (not (string? var)) | |
… | |||
| 278 | 292 | (string-length (term-definition-iri def))) | |
| 279 | 293 | (term-definition-iri def))) | |
| 280 | 294 | (not (term-definition-prefix? def))) | |
| 281 | - | ;; 5.2 | |
| 295 | + | ;; 7.2 | |
| 282 | 296 | (let ((candidate (string-append term ":" | |
| 283 | 297 | (substring | |
| 284 | 298 | var | |
| 285 | 299 | (string-length | |
| 286 | 300 | (term-definition-iri def)))))) | |
| 287 | - | ;; 5.3 | |
| 301 | + | ;; 7.3 | |
| 288 | 302 | (when (or (json-null? compact-iri) | |
| 289 | 303 | (< (string-length candidate) (string-length compact-iri)) | |
| 290 | 304 | (and (= (string-length candidate) | |
… | |||
| 296 | 310 | (equal? (term-definition-iri def) var))) | |
| 297 | 311 | (set! compact-iri candidate))))))) | |
| 298 | 312 | (active-context-definitions active-context)) | |
| 299 | - | ;; 6 | |
| 313 | + | ;; 8 | |
| 300 | 314 | (when (not-null-or-false compact-iri) | |
| 301 | 315 | (set-cond! result compact-iri))) | |
| 302 | - | ;; 7 | |
| 316 | + | ;; 9 | |
| 303 | 317 | (unless result | |
| 304 | 318 | (let* ((components (string-split var #\:)) | |
| 305 | 319 | (prefix (car components)) | |
… | |||
| 313 | 327 | (unless (and (> (string-length suffix) 2) | |
| 314 | 328 | (equal? (substring suffix 0 2) "//")) | |
| 315 | 329 | (throw 'iri-confused-with-prefix))))) | |
| 316 | - | ;; 8 | |
| 330 | + | ;; 10 | |
| 317 | 331 | (unless vocab? | |
| 318 | 332 | (when (and (not-null-or-false (active-context-base active-context)) | |
| 319 | 333 | (absolute-iri? var)) | |
| 320 | - | (set-cond! result | |
| 321 | - | (make-relative-iri var (active-context-base active-context))))) | |
| 322 | - | ;; 9 | |
| 334 | + | (let ((iri (make-relative-iri var (active-context-base active-context)))) | |
| 335 | + | (if (keyword-form? iri) | |
| 336 | + | (set-cond! result (string-append "./" iri)) | |
| 337 | + | (set-cond! result iri))))) | |
| 338 | + | ;; 11 | |
| 323 | 339 | (set-cond! result var) | |
| 324 | 340 | result))))) | |
jsonld/json.scm
| 50 | 50 | node-object? | |
| 51 | 51 | not-null-or-false | |
| 52 | 52 | processing-mode-1.0? | |
| 53 | + | processing-mode-1.1? | |
| 53 | 54 | relative-iri? | |
| 54 | 55 | same-json? | |
| 55 | 56 | identical-json? | |
… | |||
| 213 | 214 | (define (processing-mode-1.0? mode) | |
| 214 | 215 | (member mode '("jsonld-1.0" "json-ld-1.0"))) | |
| 215 | 216 | ||
| 217 | + | (define (processing-mode-1.1? mode) | |
| 218 | + | (member mode '("jsonld-1.1" "json-ld-1.1"))) | |
| 219 | + | ||
| 216 | 220 | (define (node-object? o) | |
| 217 | 221 | (and (json-object? o) | |
| 218 | 222 | (not (json-has-key? o "@value")) | |
jsonld/options.scm
| 73 | 73 | (extract-all-scripts? #f) | |
| 74 | 74 | (frame-expansion? #f) | |
| 75 | 75 | (ordered? #f) | |
| 76 | - | (processing-mode "jsonld-1.1") | |
| 76 | + | (processing-mode "json-ld-1.1") | |
| 77 | 77 | (produce-generalized-rdf? #t) | |
| 78 | 78 | (rdf-direction #f) | |
| 79 | 79 | (use-native-types? #f) |
jsonld/term-selection.scm
| 16 | 16 | ;;;; | |
| 17 | 17 | ||
| 18 | 18 | (define-module (jsonld term-selection) | |
| 19 | + | #:use-module (jsonld context) | |
| 20 | + | #:use-module (jsonld inverse-context-creation) | |
| 19 | 21 | #:use-module (jsonld json) | |
| 20 | 22 | #:export (term-selection)) | |
| 21 | 23 | ||
| 22 | - | (define* (term-selection inverse-context var containers type/language | |
| 24 | + | (define* (term-selection active-context var containers type/language | |
| 23 | 25 | preferred-values) | |
| 24 | - | (let ((container-map (assoc-ref inverse-context var)) | |
| 26 | + | ;; 1 | |
| 27 | + | (when (json-null? (active-context-inverse-context active-context)) | |
| 28 | + | (set! active-context | |
| 29 | + | (update-active-context active-context | |
| 30 | + | #:inverse-context | |
| 31 | + | (inverse-context-creation active-context)))) | |
| 32 | + | (let ((container-map (assoc-ref (active-context-inverse-context active-context) var)) | |
| 25 | 33 | (result json-null)) | |
| 26 | - | ;; 2 | |
| 34 | + | ;; 4 | |
| 27 | 35 | (for-each | |
| 28 | 36 | (lambda (container) | |
| 29 | - | ;; 2.1 | |
| 37 | + | ;; 4.1 | |
| 30 | 38 | (when (json-has-key? container-map container) | |
| 31 | - | ;; 2.2 | |
| 39 | + | ;; 4.2 | |
| 32 | 40 | (let* ((type/language-map (assoc-ref container-map container)) | |
| 33 | - | ;; 2.3 | |
| 41 | + | ;; 4.3 | |
| 34 | 42 | (value-map (assoc-ref type/language-map type/language))) | |
| 35 | 43 | (for-each | |
| 36 | 44 | (lambda (item) | |
… | |||
| 39 | 47 | (set! result (assoc-ref value-map item))))) | |
| 40 | 48 | preferred-values)))) | |
| 41 | 49 | containers) | |
| 42 | - | ;; 3 | |
| 50 | + | ;; 5 | |
| 43 | 51 | result)) | |
jsonld/value-compaction.scm
| 32 | 32 | (array->list container-mapping) | |
| 33 | 33 | (list container-mapping)))) | |
| 34 | 34 | ||
| 35 | - | (define (value-compaction active-context inverse-context active-property value | |
| 36 | - | processing-mode) | |
| 35 | + | (define (value-compaction active-context active-property value processing-mode) | |
| 37 | 36 | (let* ((result value) | |
| 38 | 37 | (active-def (term-definition-ref active-context active-property)) | |
| 39 | 38 | ;; 2 | |
… | |||
| 58 | 57 | (cond | |
| 59 | 58 | ((and (term-definition? active-def) | |
| 60 | 59 | (equal? (term-definition-type active-def) "@id")) | |
| 61 | - | (set! result (iri-compaction active-context inverse-context | |
| 60 | + | (set! result (iri-compaction active-context | |
| 62 | 61 | (assoc-ref value "@id") #:vocab? #f | |
| 63 | 62 | #:processing-mode processing-mode))) | |
| 64 | 63 | ((and (term-definition? active-def) | |
| 65 | 64 | (equal? (term-definition-type active-def) "@vocab")) | |
| 66 | - | (set! result (iri-compaction active-context inverse-context | |
| 65 | + | (set! result (iri-compaction active-context | |
| 67 | 66 | (assoc-ref value "@id") #:vocab? #t | |
| 68 | 67 | #:processing-mode processing-mode))))) | |
| 69 | 68 | ;; 5 | |
… | |||
| 77 | 76 | (equal? (term-definition-type active-def) "@none")) | |
| 78 | 77 | (json-has-key? value "@type")) | |
| 79 | 78 | (when (json-has-key? result "@type") | |
| 80 | - | (let ((type (iri-compaction active-context inverse-context | |
| 79 | + | (let ((type (iri-compaction active-context | |
| 81 | 80 | (assoc-ref result "@type") | |
| 82 | 81 | #:vocab? #t | |
| 83 | 82 | #:processing-mode | |
… | |||
| 121 | 120 | (map | |
| 122 | 121 | (lambda (kv) | |
| 123 | 122 | (cons | |
| 124 | - | (iri-compaction active-context inverse-context (car kv) | |
| 125 | - | #:vocab? #t) | |
| 123 | + | (iri-compaction active-context (car kv) #:vocab? #t) | |
| 126 | 124 | (cdr kv))) | |
| 127 | 125 | result))) | |
| 128 | 126 | ;; 10 | |
tests/tordf.scm unknown status 2
| 1 | - | #!/data/tyreunom/projects/guile-jsonld/pre-inst-env guile | |
| 2 | - | !# | |
| 3 | - | ;;;; Copyright (C) 2020 Julien Lepiller <julien@lepiller.eu> | |
| 4 | - | ;;;; | |
| 5 | - | ;;;; This library is free software; you can redistribute it and/or | |
| 6 | - | ;;;; modify it under the terms of the GNU Lesser General Public | |
| 7 | - | ;;;; License as published by the Free Software Foundation; either | |
| 8 | - | ;;;; version 3 of the License, or (at your option) any later version. | |
| 9 | - | ;;;; | |
| 10 | - | ;;;; This library is distributed in the hope that it will be useful, | |
| 11 | - | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | - | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 | - | ;;;; Lesser General Public License for more details. | |
| 14 | - | ;;;; | |
| 15 | - | ;;;; You should have received a copy of the GNU Lesser General Public | |
| 16 | - | ;;;; License along with this library; if not, write to the Free Software | |
| 17 | - | ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 18 | - | ;;;; | |
| 19 | - | ||
| 20 | - | (use-modules (test-modules online)) | |
| 21 | - | (use-modules (test-modules result)) | |
| 22 | - | (use-modules (test-modules testsuite)) | |
| 23 | - | ||
| 24 | - | (run-test-suite tordf-test-url expected-failures tap-driver) |