Skip to main content

Ontologies

LINCD.js allows creators of packages to make ontologies easily accessible in code, wether that's an existing ontology or a newly created one.

New or existing ontology?

For Linked Data to work best, we need to reuse the same ontologies as much as possible. So if you can, use an existing ontology.

LINCD.org aims to help with this by creating the best index of existing quality ontologies.

Some checks to determine if you can use an existing technology:

  • look through all existing ontologies on LINCD.org
  • consider using the massive schema.org ontology. It supports many use cases.
  • Check Linked Open Vocabularies (LOV) for other existing ontologies

If you considered all these options and you still believe you need to make your own ontology, please go ahead. Know that creating an ontology is an art. It is something LINCD.org aims to help with over time. For the time being however we offer no further support on this yet.

If you decided you can use an existing ontology, check if it's already available through another LINCD module. If it is, simply import that. If it's not, then it would still make sense to follow through this page so that your module can import it and make it more easily accessible.

Adding an ontology to your module

Generating the files

Go to the root folder of your module and run the following command to generate all the required files:

yarn lincd create-ontology [prefix] [url]

Prefix

If you're adding an existing ontology, it usually already has an often used prefix (like rdfs, foaf, etc).

If you're creating your own ontology, you can determine the prefix yourself.

URL

If you're importing an existing URL you should provide the URL of the ontology as last parameter.

If you're creating a new ontology you can leave it blank, since LINCD will host it for you and provide a URL.

Gather the ontology data

The create-ontology command will have created an example data file in

/src/data/[prefix].json

It is here that you can define the classes and properties of your ontology.

Importing data of existing ontologies

You will need to obtain the data of the existing ontology you want to use in JSON-LD format and copy it into /src/data/[prefix].json

If it's not available as JSON-LD you can use EasyRDF Converter to convert it from various other formats (XML, Turtle) to JSON-LD.

Defining the data of your own ontology

As said before, this is something LINCD.org aims to help with over time. For the time being however we offer no further support on this yet. You can either directly create the desired ontology in JSON-LD or use any of the ontology building tools you're already familiar with and export your data in JSON-LD format.

Make your ontology accessible in code

LINCD uses Ontology Accessor Files. These are typescript files that

  • make the entities of a single ontology (so the properties and classes that it defines) available as NamedNodes with the appropriate URI already set.
  • allow you to load the data of that ontology into memory

The create-ontology command will have created such a file for you in

/src/ontologies/[prefix].ts

If you open this file you will see how it already implements a method to load the data of your ontology.

It also has a list of exports for each entity of the ontology

//A list of all the entities (Classes & Properties) of this ontology, each exported as a NamedNode
export var ExampleClass: NamedNode = ns('ExampleClass');
export var exampleProperty: NamedNode = ns('exampleProperty');

And then each of those variables is again listed in a final group export:

//An extra grouping object so all the entities can be accessed from the prefix/name
export const prefix = {
ExampleClass,
exampleProperty,
};

Note: make sure all the Classes & Properties of the ontology occur in this list and in the group object.

Adding a new class or property

Generally, to make a class or property available through this file you need to:

  1. duplicate an export var line
  2. change the variable name and the string at the end of the line (which generates the URI)
  3. add the new variable to the group export

Linking your ontology

To notify LINCD.js of your ontology, use linkedOntology()

This is already generated in the template code:

linkedOntology(_this, ns, 'myOntology', loadData, dataFile);

Note that the third parameter is string that indicates the suggested prefix for this ontology. It should be the same as the name of the exported group object:

See linkedOntology() for the full specification and examples

Using Ontologies

Once an ontology has been made available this way (by you or the creator of another LINCD ontology) you can use it as follows:

import {example} from './src/ontologies/example';

and then you can access each Class or Property of the onolotgy like this:

//logs true
console.log(example.SomeClass instanceof NamedNode);

//logs the URI of this property, for example http://lincd.org/ont/example/someProperty
console.log(example.someProperty.uri);