Giter VIP home page Giter VIP logo

rdf-string's Introduction

@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

rdf-string's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar github-actions[bot] avatar retog avatar tpluscode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rdf-string's Issues

Type resolution with `node16` and `nodeNext`

I get errors when trying to use the library in typescript module with moduleResolution node16 or nodeNext.

e.g.

Could not find a declaration file for module '@tpluscode/rdf-string'. '/workspaces/my-project/node_modules/@tpluscode/rdf-string/index.mjs' implicitly has an 'any' type.
  There are types at '/workspaces/my-project/node_modules/@tpluscode/rdf-string/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@tpluscode/rdf-string' library may need to update its package.json or typings.

Ordering dataset output

import { turtle } from '@tpluscode/rdf-string'

turtle`${dataset}`.toString({
  ordered: true,
})

The example is turtle, but should apply also to other formats ordering by graph (where applicable), subject, predicate, object

namespace is not a function

I double checked that my project has no older dependency than the ones in rdf-string but I'm still getting the following error:

    C:\Users\me\Documents\retog\rdfjs-dataset-sparql\node_modules\@tpluscode\rdf-ns-builders\vocabularies\as.js:1
    TypeError: namespace is not a function

      at Object.<anonymous> (node_modules/@tpluscode/rdf-ns-builders/vocabularies/as.js:2:19)
          at Object.<anonymous> (C:\Users\me\Documents\retog\rdfjs-dataset-sparql\node_modules\@tpluscode\rdf-ns-builders\index.js:1)

Any idea what could be causing this?

Inlining additional prefixes

import { turtle } from '@tpluscode/rdf-string'

turtle`${dataset}`.toString({
  prefixes: {
    dbr: 'http://dbpedia.org/resource/',
  }
})

NamedNode is not generic

I'm getting the following error because type declarations use NamedNode with a type parameter.

node_modules/@tpluscode/rdf-string/lib/nquads.d.ts:18:132 - error TS2315: Type 'NamedNode' is not generic.

18 export declare const nquads: (strings: TemplateStringsArray, ...values: Value<TemplateResult<NQuadsOptions>, BlankNode | Literal | 
NamedNode<string>>[]) => TemplateResult<NQuadsOptions>;

The .d.ts files get generated like that despite the fact that the ts code contains no such argument. It seems to be a bug in typescript that is solved by updating typescript.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.