jsonld-context-infer
v0.3.1
Published
Infer a JSON-LD @context from a readable stream of tabular data.
Downloads
6
Maintainers
Readme
jsonld-context-infer
Infer a JSON-LD @context from a readable stream operating in object mode.
#Type infered
- String -> xsd:string
- Number: a number including floating point numbers -> xsd:double
- integer -> xsd:integer
- date (in ISO6801 format YYYY-MM-DD) -> xsd:date
- dateTime (in ISO8601 format of YYYY-MM-DDThh:mm:ssZ) -> xsd:dateTime
- Boolean: -> xsd:boolean
#Usage
From a readable stream in object mode emitting for instance:
{ a: 1, b: 2.3 }
{ a: 2, b: 3.6 }
The script
var jsonLdContextInfer = require('jsonld-context-infer');
jsonLdContextInfer(s, function(err, schema, scores){
console.log(schema, scores);
});
will outputs:
schema:
{
"@context": {
xsd: "http://www.w3.org/2001/XMLSchema#",
a: { "@id": "_:a", "@type": "xsd:integer" },
b: { "@id": "_:b", "@type": "xsd:double" }
}
}
scores:
{
a: { "xsd:string": 0, "xsd:double": 2, "xsd:integer": 2, "xsd:date": 0, "xsd:dateTime": 0, "xsd:boolean": 1 },
b: { "xsd:string": 0, "xsd:double": 2, "xsd:integer": 0, "xsd:date": 0, "xsd:dateTime": 0, "xsd:boolean": 0 }
}
#API
##jsonLdContextInfer(readableStream, [options], callback)
options :
nSample
: if specified only thenSample
first rows of the source will be used to infer the types otherwise all the rows will be used
#Tests
npm test
#License
MIT