Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tpluscode/rdf-string
Simplifies creating of RDF strings
https://github.com/tpluscode/rdf-string
rdf rdf-strings sparql template-literals turtle
Last synced: about 2 months ago
JSON representation
Simplifies creating of RDF strings
- Host: GitHub
- URL: https://github.com/tpluscode/rdf-string
- Owner: tpluscode
- Created: 2020-02-07T17:10:58.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-05-06T10:03:32.000Z (8 months ago)
- Last Synced: 2024-05-07T11:04:30.919Z (8 months ago)
- Topics: rdf, rdf-strings, sparql, template-literals, turtle
- Language: TypeScript
- Homepage: https://tpluscode.github.io/rdf-string/
- Size: 1.72 MB
- Stars: 7
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
> # @tpluscode/rdf-string ![Test](https://github.com/tpluscode/rdf-string/workflows/Test/badge.svg) [![codecov](https://codecov.io/gh/tpluscode/rdf-string/branch/master/graph/badge.svg)](https://codecov.io/gh/tpluscode/rdf-string) [![npm version](https://badge.fury.io/js/%40tpluscode%2Frdf-string.svg)](https://badge.fury.io/js/%40tpluscode%2Frdf-string)
Simplifies the construction of RDF strings (turtle, n-triples, SPARQL, etc.)
by taking care of correctly serializing values to their string representation
and automatically prefixing URIs.## Usage
The heart of the library are [EcmaScript template string tag functions][template-literals].
All interpolated values are serialized according to the syntactic rules of the given RDF format.Formats which support prefixes will automatically abbreviate the URIs and
return the prefix declarations according to the specific syntax.### SPARQL
```js
import * as RDF from '@rdfjs/data-model'
import { prefixes } from '@zazuko/rdf-vocabularies'
import namespace from '@rdfjs/namespace'import { sparql } from '@zazuko/rdf-string'
const person = RDF.variable('person')
const PersonType = RDF.namedNode('http://example.com/Person')
const schema = namespace(prefixes.schema)
const name = "John"const query = sparql`SELECT * WHERE {
${person} a ${PersonType} .
${person} ${schema.name} ${name} .
}`query.toString()
```The last line will return a complete query.
```sparql
PREFIX schema:SELECT * WHERE {
?person a .
?person schema:name "John" .
}
```### turtle
TBD
### n-triples
TBD
[template-literals]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals