On this page

    RDF/JS logo

    RDF/JS offers a set of RDF specifications for JavaScript libraries that are defined by the RDF JavaScript Libraries W3C community group. Most of the popular JavaScript libraries adhere to these specifications, which makes it possible to use them interchangeably, and in any combination. This allows you to for example use an RDF parser from one developer, and pipe its output into an RDF store from another developer.

    For most of these specifications, corresponding TypeScript typings exist, and many libraries ship with their own typings as well, which makes RDFJS especially useful if you want to develop more strongly-typed JavaScript applications.

    Comunica is conformant to the following RDF/JS specifications.

    Data model specification

    The foundational part of RDFJS is its low-level data model specification, in which JavaScript interfaces are described for representing RDF terms and RDF quads. Five types of terms exist:

    • Named Node: Represents a thing by IRI, such as https://www.rubensworks.net/#me.
    • Blank Node: Represents a thing without an explicit name.
    • Literal: Represents a raw value of a certain datatype, such as "Ruben" or 1992.
    • Variable: Represents a variable, which can be used for matching values within queries.
    • Default Graph: Represents the default graph in RDF. Other graphs can be represented with named or blank nodes.

    RDF quads are defined as an object with RDF terms for subject, predicate, object and graph. An RDF triple is an alias of a quad, where the graph is set to the default graph. For the remainder of this document, I will just refer to RDF quads.

    Finally, a Data Factory interface is defined, which allows you to easily create terms and quads that conform to this interface. Different Data Factory implementations exist, such as rdf-data-factory and the factory from N3.js. For example, creating a quad for representing someone's name with a data factory can be done like this:

    import { DataFactory } from 'rdf-data-factory';
    const factory = new DataFactory();
    const quad = factory.quad(
      factory.namedNode('https://www.rubensworks.net/#me'), // subject
      factory.namedNode('http://schema.org/name'),          // predicate
      factory.literal('Ruben')                              // object

    Reading raw values from the quad can be done as follows:

    quad.subject.value === 'https://www.rubensworks.net/#me';
    quad.predicate.value === 'http://schema.org/name';
    quad.object.value === 'Ruben';

    For checking whether or not quads and terms are equal to each other, the equals method can be used:

    factory.literal('Ruben').equals(factory.literal('Ruben'));  // true
    factory.literal('Ruben').equals(factory.literal('Ruben2')); // false
    quad.equals(quad); // true

    Stream interfaces

    Comunica handles most parts of query execution in a streaming manner, which means that some query results may already be returned even though other results are still being processed.

    Next to the RDFJS data model, a dedicated specification exist for handling RDF streams, which is of high important to Comunica.

    One interface of high importance is the RDF/JS Source interface. You can pass a custom Source to Comunica to execute queries over it.

    The RDF/JS Store interface is an extension of Source that also allows quads to be added and removed. You can pass a custom Store to Comunica to execute update queries over it.