This document provides a specification of a low level interface definition representing RDF data independent of a serialized format in a JavaScript environment. The task force which defines this interface was formed by RDF JavaScript library developers with the wish to make existing and future libraries interoperable. This definition strives to provide the minimal necessary interface to enable interoperability of libraries such as serializers, parsers and higher level accessors and manipulators.

Design elements and principles

A list of these properties maintained on the RDFJS Representation Task Force wiki .

Data interfaces

UML data interface diagram

Term interface

    [Exposed=(Window,Worker)]
    interface Term {
      attribute DOMString termType;
      attribute DOMString value;
      boolean equals(optional Term? other);
    };
    

Term is an abstract interface.

termType contains a value that identifies the concrete interface of the term, since Term itself is not directly instantiated. Possible values include "NamedNode", "BlankNode", "Literal", "Variable", "DefaultGraph" and "Quad".

value is refined by each interface which extends Term.

equals() returns true when called with parameter other on an object term if all of the conditions below hold:

otherwise, it returns false.

NamedNode interface

    [Exposed=(Window,Worker)]
    interface NamedNode : Term {
      attribute DOMString termType;
      attribute DOMString value;
      boolean equals(optional Term? other);
    };
    

termType contains the constant "NamedNode".

value the IRI of the named node (example: "http://example.org/resource").

equals() returns true if all general Term.equals conditions hold and term.value is the same string as other.value; otherwise, it returns false.

BlankNode interface

    [Exposed=(Window,Worker)]
    interface BlankNode : Term {
      attribute DOMString termType;
      attribute DOMString value;
      boolean equals(optional Term? other);
    };
    

termType contains the constant "BlankNode".

value blank node name as a string, without any serialization specific prefixes, e.g. when parsing, if the data was sourced from Turtle, remove "_:", if it was sourced from RDF/XML, do not change the blank node name (example: "blank3")

equals() returns true if all general Term.equals conditions hold and term.value is the same string as other.value; otherwise, it returns false.

Literal interface

    [Exposed=(Window,Worker)]
    interface Literal : Term {
      attribute DOMString termType;
      attribute DOMString value;
      attribute DOMString language;
      attribute NamedNode datatype;
      boolean equals(optional Term? other);
    };
    

termType contains the constant "Literal".

value the text value, unescaped, without language or type (example: "Brad Pitt")

language the language as lowercase [[BCP47]] string (examples: "en", "en-gb") or an empty string if the literal has no language.

datatype a NamedNode whose IRI represents the datatype of the literal.

If the literal has a language, its datatype has the IRI "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString". Otherwise, if no datatype is explicitly specified, the datatype has the IRI "http://www.w3.org/2001/XMLSchema#string".

equals() returns true if all general Term.equals conditions hold, term.value is the same string as other.value, term.language is the same string as other.language, and term.datatype.equals(other.datatype) evaluates to true; otherwise, it returns false.

Variable interface

    [Exposed=(Window,Worker)]
    interface Variable : Term {
      attribute DOMString termType;
      attribute DOMString value;
      boolean equals(optional Term? other);
    };
    

termType contains the constant "Variable".

value the name of the variable without leading "?" (example: "a").

equals() returns true if all general Term.equals conditions hold and term.value is the same string as other.value; otherwise, it returns false.

DefaultGraph interface

    [Exposed=(Window,Worker)]
    interface DefaultGraph : Term {
      attribute DOMString termType;
      attribute DOMString value;
      boolean equals(optional Term? other);
    };
    

An instance of DefaultGraph represents the default graph. It's only allowed to assign a DefaultGraph to the graph property of a Quad.

termType contains the constant "DefaultGraph".

value contains an empty string as constant value.

equals() returns true if all general Term.equals conditions hold; otherwise, it returns false.

Quad interface

    [Exposed=(Window,Worker)]
    interface Quad : Term {
      attribute DOMString termType;
      attribute DOMString value;
      attribute Term subject;
      attribute Term predicate;
      attribute Term _object;
      attribute Term graph;
      boolean equals(optional Quad? other);
    };
    

termType contains the constant "Quad".

value contains an empty string as constant value.

subject the subject, which is a NamedNode, BlankNode, Variable or Quad.

predicate the predicate, which is a NamedNode or Variable.

object the object, which is a NamedNode, Literal, BlankNode or Variable.

graph the named graph, which is a DefaultGraph, NamedNode, BlankNode or Variable.

Triple MUST be represented as Quad with graph set to a DefaultGraph

equals() returns true when called with parameter other on an object quad if all of the conditions below hold:

otherwise, it returns false.

DataFactory interface

    [Exposed=(Window,Worker)]
    interface DataFactory {
      NamedNode namedNode(DOMString value);
      BlankNode blankNode(optional DOMString value);
      Literal literal(DOMString value, optional (DOMString or NamedNode) languageOrDatatype);
      Variable variable(DOMString value);
      DefaultGraph defaultGraph();
      Quad quad(Term subject, Term predicate, Term _object, optional Term? graph);
      Term fromTerm(Term original);
      Quad fromQuad(Quad original);
    };
    

For default values of the instance properties and valid values requirements, see the individual interface definitions.

namedNode() returns a new instance of NamedNode.

blankNode() returns a new instance of BlankNode. If the value parameter is undefined a new identifier for the blank node is generated for each call.

literal() returns a new instance of Literal. If languageOrDatatype is a NamedNode, then it is used for the value of datatype. Otherwise languageOrDatatype is used for the value of language.

variable() returns a new instance of Variable. This method is optional.

defaultGraph() returns an instance of DefaultGraph.

quad()returns a new instance of Quad. If graph is undefined or null it MUST set graph to a DefaultGraph.

fromTerm() returns a new instance of the specific Term subclass given by original.termType (e.g., NamedNode, BlankNode, Literal, etc.), such that newObject.equals(original) returns true.

fromQuad() returns a new instance of Quad, such that newObject.equals(original) returns true.