@grafctory/blue - v0.17.0
    Preparing search index...

    Module dictionary

    Dictionary shape types and operations.

    Defines the shape describing localised text, stated once per language, together with its constraint types, and provides the dictionary factory stating them, mapping JSON-LD language maps to RDF 1.1 language-tagged strings. A property whose value varies by language takes one member rather than one per language.

    The text stated under each tag is described by an ordinary string shape, so the same content rules hold for a localised value and its plain counterpart: dictionary(text()) holds every entry to a single line of plain text, and dictionary(markdown()) keeps every entry verbatim as Markdown.

    Important

    Contradictory constraints are rejected as the shape is built, so a shape that exists admits at least one value. Requiring a language that languageIn rules out throws a TraceError, since no map could then satisfy both constraints at once and the shape would admit nothing.

    How many strings a tag carries is fixed by uniqueLang: a unique-tagged shape gives every tag a single string, and any other gives every tag an array. A member ranging over a dictionary carries the map whole, never in an array, whatever cardinality it states. A map carrying no text under any tag counts as no value, so a required localised member stating an empty map fails its cardinality.

    The tag-keyed map is the form a value is stored and submitted in. A localised member additionally coalesces under language negotiation when retrieved, at the same per-tag arity: the value may be retrieved as the negotiated content alone, and filtered by a plain string operand matched against it under ordinary textual semantics. Submission never coalesces: it accepts the tag-keyed form alone.

    Compatibility

    JSON JSON-LD RDF 1.1
    tag-keyed string map @language-container language map language-tagged string literals

    Defining language-tagged shapes

    Values are tag-keyed maps; the und tag carries content of undetermined language (a proper name, say), and the zxx tag content with no language at all (identifiers, codes, formulae):

    import { dictionary } from '@grafctory/blue/dictionary';
    import { markdown, string, text } from '@grafctory/blue/string';

    const label = dictionary(text(), { uniqueLang: true }); // a single line of plain text per tag
    const keywords = dictionary(string()); // an array of strings per tag
    const name = dictionary(text({ minLength: 1, maxLength: 200 })); // length-constrained
    const abstract = dictionary(markdown(), { languageIn: ["en", "it"] }); // language-restricted Markdown

    Using in resource shapes

    import { multiple, optional, required, resource } from '@grafctory/blue/resource';
    import { dictionary } from '@grafctory/blue/dictionary';
    import { markdown, text } from '@grafctory/blue/string';

    const Article = resource({
    title: required(dictionary(text({ minLength: 1 }), { uniqueLang: true })),
    abstract: optional(dictionary(markdown(), { uniqueLang: true })),
    keywords: multiple(dictionary(text(), { languageIn: ["en", "fr", "de"] }))
    });

    A member carries one map whatever cardinality it states, so keywords above reads as a single map of string arrays and never as an array of maps.

    DictionaryShape

    Describes a localised textual value.

    DictionaryConstraints

    Constraints accepted by the dictionary shape factory.

    dictionary

    Creates a dictionary shape.