Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
# solid-namespace
# Solid Namespace
[![](https://img.shields.io/badge/project-Solid-7C4DFF.svg?style=flat)](https://github.com/solid/solid)
[![NPM Version](https://img.shields.io/npm/v/solid-namespace.svg?style=flat)](https://npm.im/solid-namespace)

A collection of common RDF namespaces used in the Solid project.

solid-namespace can be used with any RDF/JS-compatible library (e.g. [rdflib.js](/linkeddata/rdflib.js)).


## Usage

You can use this library in two ways.

1. With a RDF JS library to get NamedNodes
2. Without a library to get url strings

### With a rdf library

If a rdf library is provided then the map of namespaces given will be the result of calling `rdflib.Namespace` on the namespace urls.

```js
const $rdf = require('rdflib');
const ns = require('solid-namespace')($rdf);
const store = $rdf.graph();

let me = ...;
let name = store.any(me, ns.vcard('fn')) || store.any(me, ns.foaf('name'));

console.log(ns.foaf('name')); // -> NamedNode(<http://xmlns.com/foaf/0.1/name>)
```

### Without a rdf library

```js
var rdf = require('rdflib') // optional
var vocab = require('solid-namespace')(rdf) // or require('solid-namespace')()
console.log(vocab.foaf('name'))
// -> NamedNode(<http://xmlns.com/foaf/0.1/name>)
const ns = require('solid-namespace')();
console.log(ns.foaf('name')); // -> "http://xmlns.com/foaf/0.1/name"
```
87 changes: 58 additions & 29 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,70 @@
'use strict'
/**
* Provides a hashmap of relevant vocabs / namespaces.
* Provides a way to access commonly used namespaces
*
* Usage:
*
* ```
* var rdf = require('rdflib') // optional
* var vocab = require('solid-vocab')(rdf) // or require('solid-vocab')()
* console.log(vocab.foaf('name')) // -> <http://xmlns.com/foaf/0.1/name>
* const $rdf = require('rdflib'); //or any other RDF/JS-compatible library
* const ns = require('solid-namespace')($rdf);
* const store = $rdf.graph();
*
* let me = ...;
* let name = store.any(me, ns.vcard(‘fn’)) || store.any(me, ns.foaf(‘name’));
* ```
* @module vocab
*/
const aliases = {
acl: 'http://www.w3.org/ns/auth/acl#',
arg: 'http://www.w3.org/ns/pim/arg#',
cal: 'http://www.w3.org/2002/12/cal/ical#',
contact: 'http://www.w3.org/2000/10/swap/pim/contact#',
dc: 'http://purl.org/dc/elements/1.1/',
dct: 'http://purl.org/dc/terms/',
doap: 'http://usefulinc.com/ns/doap#',
foaf: 'http://xmlns.com/foaf/0.1/',
http: 'http://www.w3.org/2007/ont/http#',
httph: 'http://www.w3.org/2007/ont/httph#',
icalTZ: 'http://www.w3.org/2002/12/cal/icaltzd#', // Beware: not cal:
ldp: 'http://www.w3.org/ns/ldp#',
link: 'http://www.w3.org/2007/ont/link#',
log: 'http://www.w3.org/2000/10/swap/log#',
meeting: 'http://www.w3.org/ns/pim/meeting#',
mo: 'http://purl.org/ontology/mo/',
owl: 'http://www.w3.org/2002/07/owl#',
pad: 'http://www.w3.org/ns/pim/pad#',
patch: 'http://www.w3.org/ns/pim/patch#',
qu: 'http://www.w3.org/2000/10/swap/pim/qif#',
trip: 'http://www.w3.org/ns/pim/trip#',
rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
rdfs: 'http://www.w3.org/2000/01/rdf-schema#',
rss: 'http://purl.org/rss/1.0/',
sched: 'http://www.w3.org/ns/pim/schedule#',
schema: 'http:/schema.org/', // @@ beware confusion with documents no 303
sioc: 'http://rdfs.org/sioc/ns#',
solid: 'http://www.w3.org/ns/solid/terms#',
space: 'http://www.w3.org/ns/pim/space#',
stat: 'http://www.w3.org/ns/posix/stat#',
tab: 'http://www.w3.org/2007/ont/link#',
tabont: 'http://www.w3.org/2007/ont/link#',
ui: 'http://www.w3.org/ns/ui#',
vcard: 'http://www.w3.org/2006/vcard/ns#',
wf: 'http://www.w3.org/2005/01/wf/flow#',
xsd: 'http://www.w3.org/2001/XMLSchema#'
}

/**
* @param [rdf] {RDF} Optional RDF Library (such as rdflib.js or rdf-ext) to
* inject
* @param [rdflib] {RDF} Optional RDF Library (such as rdflib.js or rdf-ext) to inject
*/
function vocab (rdf) {
var ns = require('rdf-ns')(rdf)
var vocabMap = {
'acl': ns.base('http://www.w3.org/ns/auth/acl#'),
'app': ns.base('http://www.w3.org/ns/solid/app#'),
'cert': ns.base('http://www.w3.org/ns/auth/cert#'),
'dct': ns.base('http://purl.org/dc/terms/'),
'foaf': ns.base('http://xmlns.com/foaf/0.1/'),
'ldp': ns.base('http://www.w3.org/ns/ldp#'),
'owl': ns.base('http://www.w3.org/2002/07/owl#'),
'pim': ns.base('http://www.w3.org/ns/pim/space#'),
'rdf': ns.base('http://www.w3.org/1999/02/22-rdf-syntax-ns#'),
'rdfs': ns.base('http://www.w3.org/2000/01/rdf-schema#'),
'schema': ns.base('http://schema.org/'),
'sioc': ns.base('http://rdfs.org/sioc/ns#'),
'solid': ns.base('http://www.w3.org/ns/solid/terms#'),
'stat': ns.base('http://www.w3.org/ns/posix/stat#'),
'vcard': ns.base('http://www.w3.org/2006/vcard/ns#'),
'xsd': ns.base('http://www.w3.org/2001/XMLSchema#')
}
return vocabMap
}
function vocab (rdf = { namedNode: u => u }) {
const namespaces = {}
for (const alias in aliases) {
const expansion = aliases[alias]
namespaces[alias] = function (localName = '') {
return rdf.namedNode(expansion + localName)
}
};

return namespaces
};

module.exports = vocab
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "solid-namespace",
"version": "0.1.0",
"version": "0.2.0",
"description": "A collection of common RDF namespaces used in the Solid project",
"main": "./index.js",
"scripts": {
"standard": "standard src/*"
"standard": "standard index.js",
"test": "node ./test.js"
},
"repository": {
"type": "git",
Expand All @@ -22,15 +23,16 @@
"rest"
],
"author": "Dmitri Zagidulin <dzagidulin@gmail.com>",
"contributors": [
"Dmitri Zagidulin <dzagidulin@gmail.com>",
"Jordan Shurmer <jordan@shurmerfamily.com>"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/solid/solid-namespace/issues"
},
"homepage": "https://github.com/solid/solid-namespace",
"dependencies": {
"rdf-ns": "^0.1.0"
},
"devDependencies": {},
"dependencies": {},
"standard": {
"globals": []
}
Expand Down
13 changes: 13 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const assert = require('assert');

//Test the non-rdflib functionality
const ns = require('./index.js')();
assert.equal(ns.schema('Recipe'), 'http:/schema.org/Recipe');


//Test the rdflib functionality
const rdflib = {
namedNode: val => 'RDF::'+val
};
const rdfns = require('./index.js')(rdflib);
assert.equal(rdfns.schema('Recipe'), 'RDF::http:/schema.org/Recipe');