Skip to content

Mapping and Normalization #11

@simontaurus

Description

@simontaurus

Alias notation see #12
ToDo: Class / Instance alias notation

Normalization can be realized by chaining JSON-LD algorithms:

  • Expand
  • Flatten

Mapping-Context could also be constructed from https://github.com/mapping-commons/sssom, see also mapping-commons/rda-fair-mappings#85

As an example a dataset could consist of persons and organisations that report their relations in a inoperable way:

Input Expand Context Flatten Context Result
"skos:label": "test" "skos_label": "skos:prefLabel" "skos_label": {"@id": "skos:prefLabel", "@language": "en", "@container": "@set"} "skos:label": [{"@value": "test", "@lang": "en"}]
"rdfs:label": "test" "rdfs_label": "rdfs:prefLabel" "rdfs_label": skos:label "skos:label": "test"
"@id": "ex:P", "schema:worksFor": "ex:C" "schema_worksFor": "schema:worksFor" "schema_worksFor": {"@reverse": "schema:employes"} "@id": "ex:C", "schema:employes": "ex:P"

Example input:

"@graph":
- id: demo:person1
  type: schema:Person
  name: Person1
  works_for: demo:organizationA # forward relation
  works_for*: demo:organizationB # forward relation but different property
- id: demo:organizationA
  type: schema:Organization
- id: demo:organizationB
  type: schema:Organization
- id: demo:organizationC
  type: schema:Organization
  employes: demo:person1 # backwards relation

Example output:

"@graph":
- employes:
  - demo:person1
  - demo:person2
  - demo:person3
  id: demo:organizationA
  label:
  - lang: en
    text: organizationA
  type: schema:Organization
- id: demo:person1
  name: Person1
  type: schema:Person
- id: demo:person2
  name: Person2
  type: schema:Person
- id: demo:person3
  name: Person3
  type: schema:Person
{
  "@context": {
    "schema": "http://schema.org/",
    "demo": "https://oo-ld.github.io/demo/",
    "works_for": {"@id": "schema:worksFor", "@type": "@id"},
    "works_for*": {"@id": "demo:worksFor", "@type": "@id"},
    "works_for**": {"@reverse": "schema:employes", "@type": "@id"},
    "employes":{"@id": "schema:employes", "@type": "@id"},
    "type": "@type",
    "id": "@id"

  },
  "@graph": [
    {
      "id": "demo:person1",
      "type": "schema:Person",
      "name": "Person1",
      "works_for": "demo:organizationA",
      "works_for*": "demo:organizationB"
    },
    {
      "id": "demo:organizationA",
      "type": "schema:Organization"
    },
    {
      "id": "demo:organizationB",
      "type": "schema:Organization"
    },
    {
      "id": "demo:organizationC",
      "type": "schema:Organization",
      "employes": "demo:person1"
    }
  ]
}

flattened

{
  "@graph": [
    {
      "@id": "https://oo-ld.github.io/demo/organizationA",
      "@type": "http://schema.org/Organization"
    },
    {
      "@id": "https://oo-ld.github.io/demo/organizationB",
      "@type": "http://schema.org/Organization"
    },
    {
      "@id": "https://oo-ld.github.io/demo/organizationC",
      "@type": "http://schema.org/Organization",
      "https://oo-ld.github.io/demo/employes": {
        "@id": "https://oo-ld.github.io/demo/person1"
      }
    },
    {
      "@id": "https://oo-ld.github.io/demo/person1",
      "@type": "http://schema.org/Person",
      "http://schema.org/worksFor": {
        "@id": "https://oo-ld.github.io/demo/organizationA"
      },
      "https://oo-ld.github.io/demo/worksFor": {
        "@id": "https://oo-ld.github.io/demo/organizationB"
      }
    }
  ]
}

playground

Notebook: https://oo-ld.github.io/jupyterlite/lab/index.html?path=data_normalization.ipynb

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions