Skip to main content

Ontologies

This package provides ontologies management utilities.

Features

  • Manage ontologies with prefixes, OWL files and JSON-LD contexts
  • Allow services to register the ontologies they need
  • Allow to persist ontologies if they must be kept on server restart
  • Allow to find ontologies prefixes through prefix.cc

Dependencies

Sub-services

  • OntologiesRegistryService

Install

$ yarn add @semapps/ontologies

Usage

const { OntologiesService } = require('@semapps/ontologies');

module.exports = {
mixins: [OntologiesService],
settings: {
ontologies: [
{
prefix: 'ont1',
namespace: 'https://www.w3.org/ns/ontology1#',
owl: 'https://www.w3.org/ns/ontology1.ttl',
jsonldContext: 'https://www.w3.org/ns/ontology1.ttl', // Can also be a array or an object
preserveContextUri: false // If true, the jsonldContext won't be merged in the local context file
}
],
persistRegistry: false,
setingsDataset: 'settings'
}
};

Persisting registry

Any services may call the register action to add new ontologies. That's how most core services register the ontologies they need.

By default, ontologies are not persisted. They are kept in memory and so the register action must be called again on every restart.

If you wish ontologies to be persisted, you must set the persistRegistry setting to true and call the register action with persist: true.

By default, they will be persisted in a dataset named settings (the same used by the auth.account service). If you wish to use another dataset name, you can change the settingsDataset setting.

Note that only the prefix and namespaces properties can be persisted.

Settings

PropertyTypeDefaultDescription
ontologies[Array]List of (custom) ontologies to be registered
persistRegistryBooleanfalseIf true, registered ontologies can be persisted in a dataset
settingsDatasetString"settings"The dataset where to persist ontologies (if persistRegistry is true )

Core ontologies

These ontologies can be imported individually using their prefixes, or as a whole with coreOntologies.

PrefixNamespace
aclhttp://www.w3.org/ns/auth/acl#
ashttps://www.w3.org/ns/activitystreams#
dchttp://purl.org/dc/terms/
foafhttp://xmlns.com/foaf/0.1/
ldphttp://www.w3.org/ns/ldp#
rdfhttp://www.w3.org/1999/02/22-rdf-syntax-ns#
rdfshttp://www.w3.org/2000/01/rdf-schema#
sechttps://w3id.org/security#
skoshttp://www.w3.org/2008/05/skos#
semappshttp://semapps.org/ns/core#
vcardhttp://www.w3.org/2006/vcard/ns#
voidhttp://rdfs.org/ns/void#
xsdhttp://www.w3.org/2001/XMLSchema#

These ontologies can be imported individually using their prefixes, or as a whole with solidOntologies.

PrefixNamespace
apodshttp://activitypods.org/ns/core#
interophttp://www.w3.org/ns/solid/interop#
notifyhttp://www.w3.org/ns/solid/notifications#
oidchttp://www.w3.org/ns/solid/oidc#
pimhttp://www.w3.org/ns/pim/space#
solidhttp://www.w3.org/ns/solid/terms#

Actions

The following service actions are available:

findPrefix

Fetch prefix.cc to find the prefix of the provided URI.

Parameters
PropertyTypeDefaultDescription
uriStringrequiredURI of the ontology or of a predicate
Return

The prefix, or null if no prefix was found.

findNamespace

Fetch prefix.cc to find the namespace associated with a prefix.

Parameters
PropertyTypeDefaultDescription
prefixStringrequiredPrefix of the ontology
Return

The namespace, or null if the prefix doesn't exist in prefix.cc.

get

Return a registered ontology by its prefix, namespace or URI.

Parameters
PropertyTypeDefaultDescription
prefixStringPrefix of the ontology
namespaceStringNamespace of the ontology
uriStringURI to match with the namespace of the ontology
Return

The ontology, or null if no registered ontology was found.

getPrefixes

Return the registered prefixes as an object.

Return

An object with the prefix in keys, and the associated URLs in values.

getRdfPrefixes

Return the registered ontologies' prefixes as a string to be used in SPARQL queries.

Return

A string of type PREFIX ont1: <https://www.w3.org/ns/ontology1#>, split with new lines.

list

Return the registered ontologies

Return

An array of object, formatted as above.

register

Register a new ontology.

Parameters
PropertyTypeDefaultDescription
prefixStringrequiredPrefix of the ontology
namespaceStringrequiredNamespace of the ontology
owlStringURL of the OWL file (used by the InferenceService)
jsonldContextString, Array or ObjectJSON-LD context associated with the ontology. Can be an URL, a array or an object
preserveContextUriBooleanfalseIf true, the jsonldContext will not be merged in the local context file. Works only if jsonldContext is an URL or an array of URLs.
persistBooleanfalseIf true, the ontology will be persisted (see above)