Tutorial

This tutorial will show you how to use RDF-Ext.

Example Workspace

All examples of this tutorial are available as Gitpodopen in new window workspace:

Open in Gitpod

Basics

Let's start with some basics.

Example Dataset

We will use the housemdopen in new window example dataset in this tutorial. The following lines show how to load it:

import housemd from 'housemd'
import rdf from 'rdf-ext'

// import the housemd RDF/JS Quads and use RDF-Ext as factory
const quads = housemd({ factory: rdf })

// load the quads into a RDF/JS dataset
const dataset = rdf.dataset(quads)

// dump the content of the dataset to the console
console.log(dataset.toCanonical())
 
 
 
 
 
 
 
 



1
2
3
4
5
6
7
8
9
10
11

N-Triples

Converting Term, Quads, or Dataset to N-Triples string can be helpful for debugging. The example shows how to do it:

import housemd from 'housemd'
import rdf from 'rdf-ext'

// import the housemd RDF/JS Quads and use RDF-Ext as factory
const quads = housemd({ factory: rdf })

// load the quads into a RDF/JS dataset
const dataset = rdf.dataset(quads)

// dump the content of the dataset to the console
console.log(dataset.toCanonical())









 
 
1
2
3
4
5
6
7
8
9
10
11

Browser

A module bundler is required to build a Web application with RDF-Ext. webpackopen in new window is a very popular one, which we will use in this tutorial.

Dependencies

First, you need to install webpack and the webpack cli. The following command will install both and add them as a developer dependency:

npm install --save-dev webpack webpack-cli
1

Bundle

Now you can run the bundler:

npx webpack ./examples/browser/fetch-resource.js --output-filename=fetch-resource.js
1

Server

The repository contains a small Web server that hosts the examples. You can use the launch configuration in VSCode/Gitpod to start it. Or with the following command:

node server.js 
1

Gitpod will automatically open a browser window. On a local environment, open this link: http://localhost:8080/open in new window