1.12.3 • Published 3 years ago

rdfs v1.12.3

Weekly downloads
40
License
Apache-2.0
Repository
-
Last release
3 years ago

rdfs-js

Introduction

This is a RDF data model mapping library for javascript. It's primary feature is mapping from RDFS Class to javascript constructor function, and mapping from RDFS data types to javascript data types.

Requiring rdfs-js:

npm install --save rdfs
const RDFS = require('rdfs');

Quick Examples

Serialization Example

const RDFS = require('rdfs');
const should = require('should/as-function');
const JSONLD = require('jsonld');
const model = new RDFS.Model(
    'http://qfield.net/example/ns#',
    {
        'rdf': RDFS.IRI_RDF,
        'rdfs': RDFS.IRI_RDFS,
        'xsd': RDFS.IRI_XSD,
        'owl': 'http://www.w3.org/2002/07/owl#',
        'dc': 'http://purl.org/dc/elements/1.1/'
    }
);

const owlThing = model.rdfsClass('owl:Thing');
const thisProject = owlThing('rdfs-js');
thisProject.set('dc:creator', 'Qfield');

const jsonldDoc = thisProject.toJSON();

const nquads = await JSONLD.toRDF(jsonldDoc, {
    format: 'application/nquads'
});

const expectedStatements = [
    '<http://www.w3.org/2000/01/rdf-schema#Class> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .',
    '<http://www.w3.org/2002/07/owl#Thing> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .',
    '<http://qfield.net/example/ns#rdfs-js> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .',
    '<http://qfield.net/example/ns#rdfs-js> <http://purl.org/dc/elements/1.1/creator> "Qfield" .'
];
const statements = nquads.trim().split('\n');
should(statements).have.length(expectedStatements.length);
should(statements).containDeep(expectedStatements);
should(expectedStatements).containDeep(statements);

Deserialization Example

const RDFS = require('rdfs');
const should = require('should/as-function');
const JSONLD = require('jsonld');
const model = new RDFS.Model(
    'http://qfield.net/example/ns#',
    {
        'rdf': RDFS.IRI_RDF,
        'rdfs': RDFS.IRI_RDFS,
        'xsd': RDFS.IRI_XSD,
        'owl': 'http://www.w3.org/2002/07/owl#',
        'dc': 'http://purl.org/dc/elements/1.1/'
    }
);

const rdfDoc = '<http://qfield.net/example/ns#rdfs-js> <http://purl.org/dc/elements/1.1/creator> "Qfield" .\n'
    + '<http://qfield.net/example/ns#rdfs-js> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .\n'
    + '<http://www.w3.org/2002/07/owl#Thing> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .\n';

const jsonldDoc = await JSONLD.fromRDF(rdfDoc, {
    format: 'application/nquads'
});

const container = await model.load(jsonldDoc);

const thisProject = container.get(RDFS.IRI_RDFS_MEMBER).get('rdfs-js');
should(thisProject.get('dc:creator').valueOf()).equal('Qfield');
should(thisProject.get(RDFS.IRI_RDF_TYPE).has(model.rdfsResource('owl:Thing'))).be.true();

const owlThing = thisProject.get(RDFS.IRI_RDF_TYPE).get('owl:Thing');
should(owlThing.get(RDFS.IRI_RDF_TYPE).has(model.rdfsClass)).be.true();

More examples

License

Copyright © 2020 Qfield

Apache 2.0

1.12.3

3 years ago

1.12.2

3 years ago

1.12.1

3 years ago

1.12.0

3 years ago

1.11.0

3 years ago

1.10.0

3 years ago

1.9.1

3 years ago

1.9.0

4 years ago

1.8.1

4 years ago

1.8.0

4 years ago

1.7.1

7 years ago

1.7.0

7 years ago

1.6.2

7 years ago

1.6.1

7 years ago

1.6.0

7 years ago

1.5.2

7 years ago

1.5.1

7 years ago

1.5.0

7 years ago

1.4.0

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago