zazuko / xrm

A friendly language for mappings to RDF
MIT License
1 stars 0 forks source link

Include JSONPath and XPath usage in the documentation #129

Closed mchlrch closed 4 months ago

mchlrch commented 8 months ago

The documentation doesn't touch on the JSONPath or XPath topics yet.

Aliasing path expressions: The documentation currently only mentions the aliasing mechanism in general but not the combination with path expression for referenceables inside logical-source.

For example declaring recordId and descriptorId:

logical-source personen_desc {
  type json
  source "stdin"
  iterator "$..[?(@.thesaurus == 'Personenbegriffe')]"

  referenceables
    identifier
    title
    description
    recordId "records[*].id"
    descriptorId "related_descriptor_set[*].to_descriptor.identifier"
}

The following sample is from a customer ticket https://gitlab.zazuko.tools/stabs/staatsarchiv-ld-pipeline/-/issues/14#note_128

Input JSON (reduced):

[
    {
        "identifier": "51725",
        "thesaurus": "Personenbegriffe",
        "title": "Ciba AG",
        "description": "",
        "records": [
            {
                "id": 727741,
                "title": "Anschluss der chemischen Grossindustrie an das st\u00e4dtische Verkehrsnetz: Ciba, Durand & Huguenin, Geigy, Roche, Sandoz"
            }
        ],
        "related_descriptor_set": [
            {
                "identifier": "376261-378711-siehe auch",
                "to_descriptor": {
                    "identifier": "54187",
                    "title": "Ciba-Geigy AG"
                },
                "role": "siehe auch",
                "reverse_role": "siehe auch"
            },
            {
                "identifier": "376261-378712-benutzt f\u00fcr",
                "to_descriptor": {
                    "identifier": "54188",
                    "title": "Ciba"
                },
                "role": "benutzt f\u00fcr",
                "reverse_role": "siehe unter"
            }
        ]
    }
]

Output data triples:

<https://ld.bs.ch/ais/Descriptor/54187> <http://schema.example.org/hasName> "Ciba-Geigy AG" .
<https://ld.bs.ch/ais/Descriptor/54187> <http://schema.example.org/hasIdentifier> "54187" .
<https://ld.bs.ch/ais/Descriptor/54188> <http://schema.example.org/hasName> "Ciba" .
<https://ld.bs.ch/ais/Descriptor/54188> <http://schema.example.org/hasIdentifier> "54188" .
<https://ld.bs.ch/ais/Agent/51725> <http://schema.example.org/hasRelatedRecord> <https://ld.bs.ch/ais/Record/727741> .
<https://ld.bs.ch/ais/Agent/51725> <http://schema.example.org/hasRelatedDescriptor> <https://ld.bs.ch/ais/Descriptor/54188> .
<https://ld.bs.ch/ais/Agent/51725> <http://schema.example.org/hasRelatedDescriptor> <https://ld.bs.ch/ais/Descriptor/54187> .
<https://ld.bs.ch/ais/Agent/51725> <http://schema.example.org/hasName> "Ciba AG" .
<https://ld.bs.ch/ais/Agent/51725> <http://schema.example.org/hasIdentifier> "51725" .

Mapping:

output carml

map agent from personen_desc {
  subject template "https://ld.bs.ch/ais/Agent/{0}" with identifier;

  properties
    ex.hasIdentifier from identifier;
    ex.hasName from title;
    ex.hasRelatedRecord template "https://ld.bs.ch/ais/Record/{0}" with recordId;
    ex.hasRelatedDescriptor template "https://ld.bs.ch/ais/Descriptor/{0}" with descriptorId;
}

map descriptor from descriptor_desc {
  subject template "https://ld.bs.ch/ais/Descriptor/{0}" with identifier;

  properties
    ex.hasIdentifier from identifier;
    ex.hasName from title;
}

logical-source personen_desc {
  type json
  source "stdin"
  iterator "$..[?(@.thesaurus == 'Personenbegriffe')]"

  referenceables
    identifier
    title
    description
    recordId "records[*].id"
    descriptorId "related_descriptor_set[*].to_descriptor.identifier"
}

logical-source descriptor_desc {
  type json
  source "stdin"
  iterator "$..[?(@.thesaurus == 'Personenbegriffe')].related_descriptor_set[*]"

  referenceables
    title "to_descriptor.title"
    identifier "to_descriptor.identifier"
}

vocabulary ex {
    prefix "ex" "http://schema.example.org/"

    classes

    properties
        hasIdentifier
        hasName
        hasRelatedRecord
        hasRelatedDescriptor
}
mchlrch commented 4 months ago

https://github.com/zazuko/expressive-rdf-mapper/blob/main/documentation/mapping-language.md#xpath-and-jsonpath-usage