jsonld-context-infer

0.3.1 • Public • Published

jsonld-context-infer

Infer a JSON-LD @context from a readable stream operating in object mode.

NPM

Type infered

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 the nSample first rows of the source will be used to infer the types otherwise all the rows will be used

Tests

npm test

License

MIT

Package Sidebar

Install

npm i jsonld-context-infer

Weekly Downloads

1

Version

0.3.1

License

MIT

Last publish

Collaborators

  • sballesteros