An open API service indexing awesome lists of open source software.

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.

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.