Write-side: emit URPX JSON-LD from coerced Clojure entities.
Symmetric to the existing parse + coerce path. Given a coerced urpx:RatePlan / urpx:RatePlanModifier / urpx:URPXDocument (or an EDN map shaped like one with namespaced-keyword keys + already-string values), emit a SHACL-valid JSON-LD string ready to write to disk or send to a consumer.
Pipeline (per call):
Round-trip success bar: logical/RDF-graph equivalence
(parse → coerce → write → re-parse → re-coerce yields a structurally
equal entity). Byte-for-byte equality with the input is NOT a goal —
key ordering, single-vs-vector property emission, and @context
recreation may differ from the source document. The vendored-fixture
round-trip suite in urpx.emit-test pins the =-equality contract over
every PG&E filing in test/resources/urpx-fixtures/ plus a URPXDocument-
wrapped E-ELEC test case from the URPX upstream.
@context emission: every write-* function accepts an optional opts map
with :context. Three states:
default-context
(URPX prefix declarations + typed-property declarations matching what
vendored fixtures carry).:context map → emit that map verbatim as @context.:context nil → emit no @context (used by round-trip tests
where the input doesn't carry one and =-equality would mismatch).An @context already on the input entity (:jsonld/context, e.g. from
a parsed document) is preserved untouched — the default never clobbers
a context the consumer already supplied.
Write-side: emit URPX JSON-LD from coerced Clojure entities.
Symmetric to the existing parse + coerce path. Given a coerced
urpx:RatePlan / urpx:RatePlanModifier / urpx:URPXDocument (or an EDN
map shaped like one with namespaced-keyword keys + already-string values),
emit a SHACL-valid JSON-LD string ready to write to disk or send to a
consumer.
Pipeline (per call):
1. urpx.coerce/encode runs the schema's :encode/urpx-jsonld transformer
— turns BigDecimal / LocalDate / LocalDateTime / LocalTime / Duration
/ int-month back into the JSON-LD string forms (xsd:decimal,
xsd:date, xsd:dateTime, xsd:time, xsd:duration, xsd:gMonth).
Already-string values pass through unchanged.
2. urpx.core/keys->jsonld walks the result, converting namespaced
keyword keys back to their CURIE / @-reserved JSON-LD forms.
3. clojure.data.json/write-str serializes to JSON.
Round-trip success bar: logical/RDF-graph equivalence
(parse → coerce → write → re-parse → re-coerce yields a structurally
equal entity). Byte-for-byte equality with the input is NOT a goal —
key ordering, single-vs-vector property emission, and @context
recreation may differ from the source document. The vendored-fixture
round-trip suite in urpx.emit-test pins the `=`-equality contract over
every PG&E filing in test/resources/urpx-fixtures/ plus a URPXDocument-
wrapped E-ELEC test case from the URPX upstream.
@context emission: every write-* function accepts an optional opts map
with `:context`. Three states:
- opts omits :context (or doesn't pass opts) → emit `default-context`
(URPX prefix declarations + typed-property declarations matching what
vendored fixtures carry).
- opts has `:context map` → emit that map verbatim as @context.
- opts has `:context nil` → emit no @context (used by round-trip tests
where the input doesn't carry one and `=`-equality would mismatch).
An @context already on the input entity (`:jsonld/context`, e.g. from
a parsed document) is preserved untouched — the default never clobbers
a context the consumer already supplied.Baseline @context emitted by the write-* functions when the caller doesn't supply one (and the input entity doesn't already carry a :jsonld/context). Covers:
Mirrors the shape that vendored fixtures (PG&E, CPAU, URPX upstream test cases) carry, so emitted JSON-LD parses cleanly with strict JSON-LD processors that rely on @context for type resolution.
Example-namespace prefixes (org, pge, ex, …) are intentionally omitted — those are corpus-specific. Callers who use such prefixes in @id strings should provide their own :context map via the write-* opts.
Baseline @context emitted by the write-* functions when the caller
doesn't supply one (and the input entity doesn't already carry a
:jsonld/context). Covers:
- the canonical URPX prefix declarations (urpx, schema, xsd)
- typed-property declarations for every URPX field whose schema has a
:decode/urpx-jsonld decoder
Mirrors the shape that vendored fixtures (PG&E, CPAU, URPX upstream
test cases) carry, so emitted JSON-LD parses cleanly with strict
JSON-LD processors that rely on @context for type resolution.
Example-namespace prefixes (org, pge, ex, …) are intentionally omitted
— those are corpus-specific. Callers who use such prefixes in @id
strings should provide their own :context map via the write-* opts.(write-rate-plan rate-plan)(write-rate-plan rate-plan opts)Serialize a coerced urpx:RatePlan to a JSON-LD string. Inverse of the urpx.core/load-rate-plan + urpx.coerce/coerce-rate-plan pipeline. Round-trip preserves logical/RDF-graph equivalence.
Optional opts keys:
:context — JSON-LD @context map (default: default-context); pass
nil to suppress @context emission entirely. An @context
already present on the input entity (e.g. from a parsed
document) is preserved untouched.
Serialize a coerced urpx:RatePlan to a JSON-LD string. Inverse of the
urpx.core/load-rate-plan + urpx.coerce/coerce-rate-plan pipeline.
Round-trip preserves logical/RDF-graph equivalence.
Optional `opts` keys:
:context — JSON-LD @context map (default: `default-context`); pass
`nil` to suppress @context emission entirely. An @context
already present on the input entity (e.g. from a parsed
document) is preserved untouched.(write-rate-plan-modifier modifier)(write-rate-plan-modifier modifier opts)Serialize a coerced urpx:RatePlanModifier to a JSON-LD string. Inverse of urpx.core/load-rate-plan-modifier + urpx.coerce/coerce-rate-plan-modifier.
See write-rate-plan for opts.
Serialize a coerced urpx:RatePlanModifier to a JSON-LD string. Inverse of urpx.core/load-rate-plan-modifier + urpx.coerce/coerce-rate-plan-modifier. See `write-rate-plan` for `opts`.
(write-urpx-document document)(write-urpx-document document opts)Serialize a coerced urpx:URPXDocument wrapper to a JSON-LD string. Inverse of urpx.coerce/coerce-urpx-document. The document's inner urpx:hasRatePlan / urpx:hasRatePlanModifier payloads are emitted as embedded entities.
See write-rate-plan for opts.
Serialize a coerced urpx:URPXDocument wrapper to a JSON-LD string. Inverse of urpx.coerce/coerce-urpx-document. The document's inner urpx:hasRatePlan / urpx:hasRatePlanModifier payloads are emitted as embedded entities. See `write-rate-plan` for `opts`.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |