https://github.com/cristianvasquez/rdf-assets
A bunch of utilities to inspect RDF files, a wrapper.
https://github.com/cristianvasquez/rdf-assets
rdf sparql
Last synced: about 1 month ago
JSON representation
A bunch of utilities to inspect RDF files, a wrapper.
- Host: GitHub
- URL: https://github.com/cristianvasquez/rdf-assets
- Owner: cristianvasquez
- License: mit
- Created: 2024-05-10T13:34:07.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-07-26T13:45:13.000Z (9 months ago)
- Last Synced: 2025-03-10T19:40:13.125Z (about 2 months ago)
- Topics: rdf, sparql
- Language: JavaScript
- Homepage:
- Size: 124 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](https://en.wikipedia.org/wiki/Glob_(programming)).```js
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:
```js
import { createTriplestore, doSelect, getAssets } from '../index.js'const assets = await getAssets({ globPattern: './examples/**/*.{ttl,rdf}' })
const store = await createTriplestore({ assets })
const query = `
prefix foaf:SELECT ?s ?name
WHERE {
graph ?g {
?s foaf:name ?name .
}
}
`const rows = doSelect({ store, query })
console.log(rows)/**
* Outputs
[
{
s: NamedNode { value: 'http://example.org/Alice' },
name: Literal { value: 'Alice', language: '', datatype: [NamedNode] }
},
{
s: NamedNode { value: 'http://example.org/Bob' },
name: Literal { value: 'Bob', language: '', datatype: [NamedNode] }
}
]
*/```
### Do SPARQL CONSTRUCT
Or display the results of a CONSTRUCT serialized in turtle
```js
import {
createTriplestore,
doConstruct,
getAssets,
prettyPrintTurtle,
} from '../index.js'const assets = await getAssets({ globPattern: './examples/**/*' })
const store = await createTriplestore({ assets })
const query = `
prefix foaf: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)/**
* a ;
* ;
* "Alice" .
*
* a ;
* "Bob" ;
* .
*/```
See [examples](./examples) for details
This uses [RDF JavaScript Libraries](https://rdf.js.org/) and [oxygraph](https://github.com/oxigraph/oxigraph) as
in-memory triplestore.