1.0.0 • Published 4 years ago

@ldflex/rdflib v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

rdfib.js query support for LDflex

This library lets you use the built-in SPARQL query engine of the rdflib.js with the LDflex language.

npm version Build Status Coverage Status Dependency Status

Installation

npm install ldflex @ldflex/rdflib

Usage

import { PathFactory } from 'ldflex';
import RdflibQueryEngine from '@ldflex/rdflib';
import { namedNode } from 'rdflib';

// The JSON-LD context for resolving properties
const context = {
  "@context": {
    "@vocab": "http://xmlns.com/foaf/0.1/",
    "friends": "knows",
  }
};
// The query engine and its source
const queryEngine = new RdflibQueryEngine('https://ruben.verborgh.org/profile/');
// The object that can create new paths
const paths = new PathFactory({ context, queryEngine });

async function showPerson(person) {
  console.log(`This person is ${await person.name}`);

  console.log(`${await person.givenName} is friends with:`);
  for await (const name of person.friends.givenName)
    console.log(`- ${name}`);
}

const ruben = paths.create({
  subject: namedNode('https://ruben.verborgh.org/profile/#me'),
});
showPerson(ruben);

License

©2020–present Ruben Verborgh. MIT License.

1.0.0

4 years ago