Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

rdfs

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rdfs

RDF data model mapping library for javascript.

latest
npmnpm
Version
1.12.3
Version published
Weekly downloads
61
454.55%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

linked data

FAQs

Package last updated on 18 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts