|
1 | | -'use strict' |
2 | 1 | /** |
3 | | - * Provides a hashmap of relevant vocabs / namespaces. |
| 2 | + * Provides a way to access commonly used namespaces |
| 3 | + * |
4 | 4 | * Usage: |
5 | 5 | * |
6 | 6 | * ``` |
7 | | - * var rdf = require('rdflib') // optional |
8 | | - * var vocab = require('solid-vocab')(rdf) // or require('solid-vocab')() |
9 | | - * console.log(vocab.foaf('name')) // -> <http://xmlns.com/foaf/0.1/name> |
| 7 | + * const $rdf = require('rdflib'); //or any other RDF/JS-compatible library |
| 8 | + * const ns = require('solid-namespace')($rdf); |
| 9 | + * const store = $rdf.graph(); |
| 10 | + * |
| 11 | + * let me = ...; |
| 12 | + * let name = store.any(me, ns.vcard(‘fn’)) || store.any(me, ns.foaf(‘name’)); |
10 | 13 | * ``` |
11 | 14 | * @module vocab |
12 | 15 | */ |
| 16 | +const aliases = { |
| 17 | + acl: 'http://www.w3.org/ns/auth/acl#', |
| 18 | + arg: 'http://www.w3.org/ns/pim/arg#', |
| 19 | + cal: 'http://www.w3.org/2002/12/cal/ical#', |
| 20 | + contact: 'http://www.w3.org/2000/10/swap/pim/contact#', |
| 21 | + dc: 'http://purl.org/dc/elements/1.1/', |
| 22 | + dct: 'http://purl.org/dc/terms/', |
| 23 | + doap: 'http://usefulinc.com/ns/doap#', |
| 24 | + foaf: 'http://xmlns.com/foaf/0.1/', |
| 25 | + http: 'http://www.w3.org/2007/ont/http#', |
| 26 | + httph: 'http://www.w3.org/2007/ont/httph#', |
| 27 | + icalTZ: 'http://www.w3.org/2002/12/cal/icaltzd#', // Beware: not cal: |
| 28 | + ldp: 'http://www.w3.org/ns/ldp#', |
| 29 | + link: 'http://www.w3.org/2007/ont/link#', |
| 30 | + log: 'http://www.w3.org/2000/10/swap/log#', |
| 31 | + meeting: 'http://www.w3.org/ns/pim/meeting#', |
| 32 | + mo: 'http://purl.org/ontology/mo/', |
| 33 | + owl: 'http://www.w3.org/2002/07/owl#', |
| 34 | + pad: 'http://www.w3.org/ns/pim/pad#', |
| 35 | + patch: 'http://www.w3.org/ns/pim/patch#', |
| 36 | + qu: 'http://www.w3.org/2000/10/swap/pim/qif#', |
| 37 | + trip: 'http://www.w3.org/ns/pim/trip#', |
| 38 | + rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', |
| 39 | + rdfs: 'http://www.w3.org/2000/01/rdf-schema#', |
| 40 | + rss: 'http://purl.org/rss/1.0/', |
| 41 | + sched: 'http://www.w3.org/ns/pim/schedule#', |
| 42 | + schema: 'http:/schema.org/', // @@ beware confusion with documents no 303 |
| 43 | + sioc: 'http://rdfs.org/sioc/ns#', |
| 44 | + solid: 'http://www.w3.org/ns/solid/terms#', |
| 45 | + space: 'http://www.w3.org/ns/pim/space#', |
| 46 | + stat: 'http://www.w3.org/ns/posix/stat#', |
| 47 | + tab: 'http://www.w3.org/2007/ont/link#', |
| 48 | + tabont: 'http://www.w3.org/2007/ont/link#', |
| 49 | + ui: 'http://www.w3.org/ns/ui#', |
| 50 | + vcard: 'http://www.w3.org/2006/vcard/ns#', |
| 51 | + wf: 'http://www.w3.org/2005/01/wf/flow#', |
| 52 | + xsd: 'http://www.w3.org/2001/XMLSchema#' |
| 53 | +} |
13 | 54 |
|
14 | 55 | /** |
15 | | - * @param [rdf] {RDF} Optional RDF Library (such as rdflib.js or rdf-ext) to |
16 | | - * inject |
| 56 | + * @param [rdflib] {RDF} Optional RDF Library (such as rdflib.js or rdf-ext) to inject |
17 | 57 | */ |
18 | | -function vocab (rdf) { |
19 | | - var ns = require('rdf-ns')(rdf) |
20 | | - var vocabMap = { |
21 | | - 'acl': ns.base('http://www.w3.org/ns/auth/acl#'), |
22 | | - 'app': ns.base('http://www.w3.org/ns/solid/app#'), |
23 | | - 'cert': ns.base('http://www.w3.org/ns/auth/cert#'), |
24 | | - 'dct': ns.base('http://purl.org/dc/terms/'), |
25 | | - 'foaf': ns.base('http://xmlns.com/foaf/0.1/'), |
26 | | - 'ldp': ns.base('http://www.w3.org/ns/ldp#'), |
27 | | - 'owl': ns.base('http://www.w3.org/2002/07/owl#'), |
28 | | - 'pim': ns.base('http://www.w3.org/ns/pim/space#'), |
29 | | - 'rdf': ns.base('http://www.w3.org/1999/02/22-rdf-syntax-ns#'), |
30 | | - 'rdfs': ns.base('http://www.w3.org/2000/01/rdf-schema#'), |
31 | | - 'schema': ns.base('http://schema.org/'), |
32 | | - 'sioc': ns.base('http://rdfs.org/sioc/ns#'), |
33 | | - 'solid': ns.base('http://www.w3.org/ns/solid/terms#'), |
34 | | - 'stat': ns.base('http://www.w3.org/ns/posix/stat#'), |
35 | | - 'vcard': ns.base('http://www.w3.org/2006/vcard/ns#'), |
36 | | - 'xsd': ns.base('http://www.w3.org/2001/XMLSchema#') |
37 | | - } |
38 | | - return vocabMap |
39 | | -} |
| 58 | +function vocab (rdf = { namedNode: u => u }) { |
| 59 | + const namespaces = {} |
| 60 | + for (const alias in aliases) { |
| 61 | + const expansion = aliases[alias] |
| 62 | + namespaces[alias] = function (localName = '') { |
| 63 | + return rdf.namedNode(expansion + localName) |
| 64 | + } |
| 65 | + }; |
| 66 | + |
| 67 | + return namespaces |
| 68 | +}; |
40 | 69 |
|
41 | 70 | module.exports = vocab |
0 commit comments