rdf-assets
A bunch of utilities to inspect RDF files, a wrapper.
Examples
Say you have a bunch of RDF files in various formats scattered throughout a directory tree.
Bundle in TRIG
Then you can gather and bundle these files into TRIG format by utilizing
a glob pattern.
import { getAssets, toFile, TRIG } from '../index.js'
const prefixes = { 'ex': 'http://example.org/' }
const assets = await getAssets({ globPattern: './examples/data/**/*' })
await toFile(assets, 'bundle.trig', { format: TRIG, prefixes })
Do SPARQL SELECT
Or you can use SPARQL to query these files:
import { createTriplestore, doSelect, getAssets } from '../index.js'
const assets = await getAssets({ globPattern: './examples/**/*.{ttl,rdf}' })
const store = await createTriplestore({ assets })
const query = `
prefix foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?s ?name
WHERE {
graph ?g {
?s foaf:name ?name .
}
}
`
const rows = doSelect({ store, query })
console.log(rows)
Do SPARQL CONSTRUCT
Or display the results of a CONSTRUCT serialized in turtle
import {
createTriplestore,
doConstruct,
getAssets,
prettyPrintTurtle,
} from '../index.js'
const assets = await getAssets({ globPattern: './examples/**/*' })
const store = await createTriplestore({ assets })
const query = `
prefix foaf: <http://xmlns.com/foaf/0.1/>
CONSTRUCT {
?s ?p ?o
}
WHERE {
graph ?g {
?s a foaf:Person .
?s ?p ?o .
}
}
`
const dataset = doConstruct({ store, query })
const str = await prettyPrintTurtle({ dataset })
console.log(str)
See examples for details
This uses RDF JavaScript Libraries and oxygraph as
in-memory triplestore.