In this part of the tutorial, we will build on the quickstart version of the Obelisk vocabulary to develop a simple JavaScript application that answers the question: “Is this person an obelisk sculptor ?”

The artifact generator

The last thing we want developers to do is memorize and type IRIs all over their code. That’s why some libraries (such as rdf-namespaces) define constants giving easy access to the terms from common vocabularies:

import { rdf } from 'rdf-namespaces';

// The value of iri will be http://www.w3.org/1999/02/22-rdf-syntax-ns#type.
const iri = rdf.type;

However, an issue with these libraries is that, by their nature, they are limited to just the common, well-known vocabularies. What about your specific vocabulary, designed for your app? How can you make the terms described in that vocabulary easily reusable in your code (and easily reusable in the code of others who may wish to reuse the terms you’ve defined in your cool vocabulary)?

The ArtifactGenerator is a tool (currently available as Alpha) that takes any RDF vocabulary as input and can generate multiple source-code bundles (e.g., Java JAR, JavaScript NPM module, etc.) that you can then use in your application. Let’s see how it works.

Generate the artifact

To generate a JavaScript artifact with the default options, you can use the following command: npx @inrupt/artifact-generator generate https://solidproject.org/SPS/assets/misc/tutorials/quickstart-obelisk.ttl --noprompt.

You can specify a local vocabulary file rather than an IRI if your vocabulary is not yet available online.

Use the artifact

In your application (TODO: provide git repo with demo app), require the generated output and use your vocabulary terms directly:

const OBELISK = require("/path/to/generated/artifact/OBELISK")

// The value of sculptorIri will be http://w3id.org/obelisk/Sculptor
const sculptorIri = OBELISK.Sculptor.value;
// The value of sculptorDefaultLabel will be Sculptor
const sculptorDefaultLabel = OBELISK.Sculptor.labelInLang()

If you use an IDE, at this point you have auto-completion on all the terms of your vocabulary.

From there, we can build a simple app that tells you, based on a person’s WebID, if that person is an obelisk sculptor or not. Note that the generated artifact is:

  • imported on line 1,
  • used on line 16 to get an IRI (OBELISK.Sculptor.value),
  • used on line 20 to get a label (OBELISK.Sculptor.labelInLang()).

If you want to be recognised as an obelisk sculptor, you can uncomment line 35. You will have to add this app to your authorized apps to be able to write into your Pod.

Congratulations, you are now familiar with what’s in a vocabulary, and saw how to code using one.

Next step: find out the well-known vocabularies