ldflex

WebJar for ldflex

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

ldflex
Last Version

Last Version

2.2.2
Release Date

Release Date

Type

Type

jar
Description

Description

ldflex
WebJar for ldflex
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/RubenVerborgh/LDflex

Download ldflex

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/ldflex/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>ldflex</artifactId>
    <version>2.2.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/ldflex/
implementation 'org.webjars.npm:ldflex:2.2.2'
// https://jarcasting.com/artifacts/org.webjars.npm/ldflex/
implementation ("org.webjars.npm:ldflex:2.2.2")
'org.webjars.npm:ldflex:jar:2.2.2'
<dependency org="org.webjars.npm" name="ldflex" rev="2.2.2">
  <artifact name="ldflex" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='ldflex', version='2.2.2')
)
libraryDependencies += "org.webjars.npm" % "ldflex" % "2.2.2"
[org.webjars.npm/ldflex "2.2.2"]

Dependencies

compile (3)

Group / Artifact Type Version
org.webjars.npm : babel__runtime jar [7.1.5,8)
org.webjars.npm : rdfjs__data-model jar [1.1.1,2)
org.webjars.npm » jsonld-context-parser jar [1.1.1,2)

Project Modules

There are no modules declared in this project.

LDflex makes Linked Data in JavaScript fun

LDflex is a domain-specific language for querying Linked Data on the Web as if you were browsing a local JavaScript graph.

npm version Build Status Coverage Status Dependency Status DOI

You can write things like person.friends.firstName to get a list of your friends. Thanks to the power of JSON-LD contexts and JavaScript's Proxy, these properties are not hard-coded in LDflex, but can be chosen at runtime. They feel as if you're traversing a local object, while you're actually querying the Web—without pulling in all data first.

Tim Berners-Lee came up with the idea for such a fluid JavaScript interface to Linked Data, in a discussion on how to make Linked Data easier for developers.

Articles and tutorials

Installation

npm install ldflex

In order to execute queries, you will also need a query engine:

npm install @ldflex/comunica

Usage

When you have obtained a starting subject, you can navigate through its properties using standard JavaScript dot property syntax.

In order to query for the result, use await if you want a single value, or for await to iterate over all values.

Initialization

const { PathFactory } = require('ldflex');
const { default: ComunicaEngine } = require('@ldflex/comunica');
const { namedNode } = require('@rdfjs/data-model');

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

Looking up data on the Web

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

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

  console.log(`${await person.givenName} is interested in:`);
  for await (const name of person.interest.label)
    console.log(`- ${name}`);

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

Inspecting the generated path expression

(async person => {
  console.log(await person.friends.givenName.pathExpression);
})(ruben);

Getting all subjects of a document

(async document => {
  for await (const subject of document.subjects)
    console.log(`${subject}`);
})(ruben);

Getting all properties of a subject

(async subject => {
  for await (const property of subject.properties)
    console.log(`${property}`);
})(ruben);

Converting an LDflex expression into a SPARQL query

(async person => {
  console.log(await person.friends.givenName.sparql);
})(ruben);

Sorting path results

(async person => {
  for await (const uri of person.interest.sort('label'))
    console.log(`- ${uri}`);
})(ruben);

The sort function takes multiple arguments, creating a path that sorts on the last argument. The path can also continue after the sort: person.friends.sort('country', 'label').givenName will sort the friends based on the label of their country, and then return their names.

License

©2018–present Ruben Verborgh, Ruben Taelman. MIT License.

Versions

Version
2.2.2