-
Notifications
You must be signed in to change notification settings - Fork 4
/
examples.js
39 lines (30 loc) · 1.38 KB
/
examples.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* eslint-disable no-console,import/no-extraneous-dependencies */
import { vocabularies, prefixes, expand, shrink } from '@zazuko/vocabularies'
Promise.resolve().then(run)
async function run() {
console.warn('Count all available prefixes:')
console.warn('| Prefix | #Quads |')
console.warn('| ---- | ---- |')
await printQuadsCount()
const customSelection = ['rdfs', 'owl', 'skos']
console.warn('\nCount triples for a custom selection:', customSelection)
await printQuadsCount(customSelection)
console.warn('\nGet base URI for', customSelection)
customSelection.forEach((prefix) => {
const uri = prefixes[prefix]
console.log(`${prefix} => ${uri}`)
})
console.warn('\nGet a stream', await vocabularies({ only: customSelection, stream: true }))
const Class = expand('rdfs:Class')
const Property = expand('rdf:Property')
console.log(`\nexpanded rdfs:Class => ${Class}`)
const person = await expand('schema:Person', [Class, Property])
console.log(`expanded schema:Person => ${person} while checking it exists as either a rdfs:Class or rdf:Property`)
console.log(`\nshrink ${expand('xsd:Boolean')} to ${shrink(expand('xsd:Boolean'))}`)
}
async function printQuadsCount(prefixSelection) {
const result = await vocabularies({ only: prefixSelection })
Object.entries(result).forEach(([prefix, dataset]) => {
console.log(`| \`${prefix}\` | ${dataset.size} |`)
})
}