0.0.15 • Published 1 year ago

@brechtvdv/rdfs2ngsi-ld.js v0.0.15

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

rdfs2ngsild.js

JS library to convert RDFS objects (in JSON-LD format) to NGSI-LD compliant JSON-LD objects

What is the difference between an RDFS object and NGSI-LD object?

An example of an RDFS object:

{
  "@context": "https://brechtvdv.github.io/demo-data/OSLO-airAndWater-Core-ap.jsonld",
  "@id": "https://lodi.ilabt.imec.be/odala/data/observations/16584343831",
  "@type": "Observation",
  "Observation.observedProperty": "http://www.wikidata.org/entity/Q48035511",
  "Observation.hasSimpleResult": "8.10 ug/m3"
}

Should be transformed to an NGSI-LD compliant object:

{
  "@context": [
    "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld",
    "https://brechtvdv.github.io/demo-data/OSLO-airAndWater-Core-ap.jsonld"
  ],
  "@id": "https://lodi.ilabt.imec.be/odala/data/observations/16584343831",
  "@type": "Observation",
  "Observation.observedProperty": {
    "@type": "Relationship",
    "object": "http://www.wikidata.org/entity/Q48035511"
  },
  "Observation.hasSimpleResult": {
    "@type": "Property",
    "value": "8.10 ug/m3"
  }
}

Use it

npm install @brechtvdv/rdfs2ngsi-ld.js

We expect an JSON-LD object at the input.

import { Ngsildify } from 'rdfs2ngsi-ld.js';
const ngsildify = new Ngsildify();

const input = {
    "@context": "https://brechtvdv.github.io/demo-data/OSLO-airAndWater-Core-ap.jsonld",
    "@id": "https://lodi.ilabt.imec.be/odala/data/observations/16584343831",
    "@type": "Observation",
    "Observation.observedProperty": "http://www.wikidata.org/entity/Q48035511",
    "Observation.hasSimpleResult": "8.10 ug/m3"
};

console.log(ngsildify.transform(input));

// Output will be an array of NGSI-LD compliant entities
[{
"@context": [
  "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld",
  "https://brechtvdv.github.io/demo-data/OSLO-airAndWater-Core-ap.jsonld"
],
        "@id": "https://lodi.ilabt.imec.be/odala/data/observations/16584343831",
        "@type": "Observation",
        "Observation.observedProperty": {
  "@type": "Relationship",
          "object": "http://www.wikidata.org/entity/Q48035511"
},
"Observation.hasSimpleResult": {
  "@type": "Property",
          "value": "8.10 ug/m3"
}
}]

What it does

  • Loop over the input object when it's an array
  • Copy the JSON-LD context and add it with NGSI-LD's context
  • loop over all the properties of the JSON object
  • Based on the value of the property:
    • if the value is a string and starts with http or has a @value key, add as NGSI-LD Property
    • else add as NGSI-LD relationship
      • create an identifier if not provided, based on the subject id, relation and index
0.0.14

1 year ago

0.0.15

1 year ago

0.0.10

2 years ago

0.0.11

2 years ago

0.0.12

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.1

2 years ago