@tpluscode/rdf-string
TypeScript icon, indicating that this package has built-in type declarations

1.3.0 • Public • Published

@tpluscode/rdf-string Test codecov npm version

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. 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

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.

PREFIX schema: <http://schema.org/>

SELECT * WHERE {
  ?person a <http://example.com/Person> .
  ?person schema:name "John" .
}

turtle

TBD

n-triples

TBD

Readme

Keywords

Package Sidebar

Install

npm i @tpluscode/rdf-string

Weekly Downloads

4,123

Version

1.3.0

License

MIT

Unpacked Size

46 kB

Total Files

35

Last publish

Collaborators

  • tpluscode