@graviola/json-schema-graph-extract
v0.1.1
Published
<h1 align="center"> SPARQL Query generator: @graviola/json-schema-graph-extract </h1> <p> <img alt="Version" src="https://img.shields.io/badge/version-0.1.1-blue.svg?cacheSeconds=2592000" /> <img src="https://img.shields.io/badge/node-%3E%3D10-blue.sv
Downloads
1
Readme
A library to get JSON documents using JSON-Schema out of a knowledge graph
🏠 Homepage
Prerequisites
- node >=10
Install
yarn add @graviola/json-schema-graph-extract
Usage
given the following json schema
{
"$defs": {
"Address": {
"type": "object",
"properties": {
"addressCountry": {
"type": "string"
},
"addressRegion": {
"type": "string"
},
"postalCode": {
"type": "string"
},
"streetAddress": {
"type": "string"
},
}
},
"Person": {
"title": "Person",
"description": "A human being",
"type": "object",
"properties": {
"familyName": {
"type": "string"
},
"givenName": {
"type": "string"
},
"address": {
"$ref": "#/$defs/Address"
}
}
}
},
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "https://example.com/person.schema.json",
}
and a knowledge graph that contains the following triples:
@prefix : <https://example.com/person.schema.json#> .
@prefix ex: <http://example.com/entities#> .
ex:me a :Person ;
:familyName "Meneman" ;
:givenName "Max" ;
:address ex:address .
:addressCountry "Germany" ;
:addressRegion "Berlin" ;
:postalCode "10967" ;
:streetAddress "Humboldforum 7821" .
call the extractDocumentFromDataset
function with on any dataset:
const baseIRI = 'http://example.com',
entityIRI = 'http://example.com/entities#me'
const data = extractDocumentFromDataset(
baseIRI,
entityIRI,
dataset,
schema,
{
omitEmptyArrays: true,
omitEmptyObjects: true,
maxRecursionEachRef: 1,
maxRecursion: 5
})
the result data serialized to json will look like this:
{
"@id": "http://example.com/entities#me",
"@type": "Person",
"familyName": "Meneman",
"givenName": "Max",
"address": {
"addressCountry": "Germany",
"addressRegion": "Berlin",
"postalCode": "10967",
"streetAddress": "Humboldforum 7821"
}
}
if the entry exists within the dataset and the document is valid according to the schema.
In the example the maxRecursionEachRef
and maxRecursion
options are used to limit the depth of the recursion.
It is possible to have a schema that references itself, which would lead to an infinite recursion.
In future versions a more fine grained control over the recursion will be possible.
The omitEmptyArrays
and omitEmptyObjects
options are used to omit empty arrays and objects from the result.
Author
👤 Sebastian Tilsch
- Github: @bastiion
Show your support
Give a ⭐️ if this project helped you!