Work on this document has been put on hold indefinitely due to lack of interest. While a significant amount of design work went into this document, at present, there are no known implementations of the specification. There are numerous design issues with this specification and it is not advised that developers implement this API unless they are fully familiar with the drawbacks present in the current design.

The RDF Interfaces Specification defines a set of standardized interfaces for working with RDF data in a programming environment. This specification outlines three distinct sets of interfaces:

Work on this document has been put on hold indefinitely due to lack of interest. While a significant amount of design work went into this document, at present, there are no known implementations of the specification. There are numerous design issues with this specification and it is not advised that developers implement this API unless they are fully familiar with the drawbacks present in the current design.

Introduction

This document is a detailed specification for the RDF Interfaces. The document is primarily intended for the following audiences:

This is a preliminary specification and is therefore fairly unstable. Implementers are warned that the interfaces in this document may change on a frequent basis until the specification reaches W3C Last Call status.

If you are not familiar with RDF, you should read about the Resource Description Framework (RDF) [[RDF-CONCEPTS]] before reading this document.

Readers who are not familiar with the Terse RDF Triple Language [[TURTLE]] may want to read the specification in order to understand the short-hand RDF notation used in some of the examples.

This document uses the Web Interface Definition Language [[WEBIDL]] to specify all language bindings. If you intend to implement any part of the RDF Interfaces you should be familiar with the Web IDL language [[WEBIDL]].

Examples may contain references to existing vocabularies and use abbreviations in CURIEs and source code. The following is a list of all vocabularies and their abbreviations, as used in this document:

Conformance requirements phrased as algorithms or specific steps may be implemented in any manner, so long as the end result is equivalent. In particular, the algorithms defined in this specification are intended to be easy to follow, and not intended to be performant.

User agents may impose implementation-specific limits on otherwise unconstrained inputs, e.g. to prevent denial of service attacks, to guard against running out of memory, or to work around platform-specific limitations.

Implementations that use ECMAScript or Java to implement the Interfaces defined in this specification must implement them in a manner consistent with the respective ECMAScript or Java Bindings defined in the Web IDL specification, as this specification uses that specification's terminology. [[!WEBIDL]]

Implementations that use any other language to implement the Interfaces defined in this specification that do not have bindings defined in the Web IDL specification should attempt to map the Interfaces as closely as possible to the implementation language's native mechanisms and datatypes. Developers are encouraged to work with other developers who are providing the RDF Interfaces in the same langauge to ensure that implementations are modular and easily exchangable.

RDF Concept Interfaces

The RDF Concept Interfaces in this specification provide a low level API for working with RDF data.

The concepts described in this specification are more generalized than those defined by the RDF Data Model [[RDF-CONCEPTS]]. Whilst this may appear to be a mismatch, the RDF specification is intended to define a notation for transmitting data on the Web, however this specification defines a set of interfaces for working with that data, behind the public interface, where more generalized notions of Triples are often required by libraries and modules.

Overview

The core interfaces for working with RDF defined by this specification are as follows:

Graph
A Graph holds a set of Triples.
Triple

A Triple consists of three components:

  • the subject, which is an RDFNode
  • the predicate, which is an RDFNode
  • the object, which is an RDFNode

Triples are the basic data structure utilized by RDF to express statements.

Throughout documentation and examples, Triples are conventionally written in the order subject, predicate, object - for example:

<http://example.org/hp> rdfs:label "Harry Potter" .

NamedNode

A node identified by an IRI. For example: <http://example.org/people#mark>

Note: IRIs are defined by International Resource Identifier [[!IRI]] and are compatible with RDF URI references as defined by RDF Concepts [[!RDF-CONCEPTS]].

BlankNode

A blank node is a reference to an unnamed resource (one for which an IRI is not known), and may be used in a Triple as a unique reference to that unnamed resource.

BlankNodes are typically stringified by prepending "_:" to a unique value, for instance _:b142 or _:me, this stringified form is referred to as a "blank node identifier".

Note: Blank node identifiers are only guaranteed to be unique within a single instance of a single Graph, the string form of a blank node identifier cannot be relied upon over time; that is to say, two graphs may hold different blank nodes which both stringify as "_:b2", and the same blank node within the same graph may have the stringified identifier "_:x23" in one instance and "_:ui9x" in another.

Literal

A literal value, optionally combined with a language attribute and/or a datatype attribute.

Literals are used for untyped string data, plain text in a natural language, or values which have a specific datatype. For example:

  • "Harry Potter and the Half-Blood Prince"@en is plain text expressed in the English language.
  • "7"^^xsd:integer is a value with a datatype of xsd:integer.

In addition to the above, this specification provides an RDFNode interface, which is implemented by those interfaces which can occupy a position in a Triple.

Implementers may provide additional types and/or a deeper type or class hierarchy so long as it includes these basic types.

Data Structures

Triples

The Triple interface represents an RDF Triple. The stringification of a Triple results in an N-Triples representation as defined in [[!RDF-TESTCASES]].

Implementors should be aware that a UTF-8 version of N-Triples may be defined by the RDF WG, as such the definition/implementation of the toString method may change.

readonly attribute RDFNode subject
The subject associated with the Triple.
readonly attribute RDFNode predicate
The predicate associated with the Triple.
readonly attribute RDFNode object
The object associated with the Triple.
stringifier DOMString toString()
Converts this triple into a string in N-Triples notation.
boolean equals(in Triple otherTriple)
Returns true if otherTriple is equivalent to this triple.
Triple otherTriple
The Triple to test for equivalence with this Triple.

Graphs

A Graph holds a set of one or more Triples.

readonly attribute unsigned long length
A non-negative integer that specifies the number of Triples in the set.
Graph add(in Triple triple)
Adds the specified Triple to the graph. This method returns the graph instance it was called on.
Triple triple
The Triple to add. Graphs MUST NOT contain duplicate triples.
Graph remove(in Triple triple)
Removes the specified Triple from the graph. This method returns the graph instance it was called on.
Triple triple
The Triple to remove.
Graph removeMatches(in any subject?, in any predicate?, in any object?)

This method removes those triples in the current instance which match the given arguments, that is, for each triple in this graph, it is removed, if:

  • calling triple.subject.equals with the specified subject as an argument returns true, or the subject argument is null, AND
  • calling triple.predicate.equals with the specified predicate as an argument returns true, or the predicate argument is null, AND
  • calling triple.object.equals with the specified object as an argument returns true, or the object argument is null
any? subject
The subject value to match against, may be null.
any? predicate
The predicate value to match against, may be null.
any? object
The object value to match against, may be null.
sequence<Triple> toArray()

Returns the set of Triples within the Graph as a host language native sequence, for example an Array in ECMAScript-262.

Note: a sequence in [[!WEBIDL]] is passed by value, not by reference.

Note: the order of the Triples within the returned sequence is arbitrary, since a Graph is an unordered set.

boolean some(in TripleFilter callback)

Existential quantification method, tests whether some Triple in the Graph passes the test implemented by the provided TripleFilter.

This method will return boolean true when the first Triple is found that passes the test.

Note: this method is aligned with Array.prototype.some() in ECMAScript-262.

TripleFilter callback
The TripleFilter to test each Triple in the Graph against.
boolean every(in TripleFilter callback)

Universal quantification method, tests whether every Triple in the Graph passes the test implemented by the provided TripleFilter.

This method will return boolean false when the first Triple is found that does not pass the test.

Note: this method is aligned with Array.prototype.every() in ECMAScript-262.

TripleFilter callback
The TripleFilter to test each Triple in the Graph against.
Graph filter (in TripleFilter filter)

Creates a new Graph with all the Triples which pass the test implemented by the provided TripleFilter.

Note: this method is aligned with Array.prototype.filter() in ECMAScript-262.

TripleFilter filter
The TripleFilter to test each Triple in the Graph against.
void forEach (in TripleCallback callback)

Executes the provided TripleCallback once on each Triple in the Graph.

Note: this method is aligned with Array.prototype.forEach() in ECMAScript-262.

TripleCallback callback
The TripleCallback to execute for each Triple.
Graph match(in any subject?, in any predicate?, in any object?, in optional unsigned long limit)

This method returns a new Graph which is comprised of all those triples in the current instance which match the given arguments, that is, for each triple in this graph, it is included in the output graph, if:

  • calling triple.subject.equals with the specified subject as an argument returns true, or the subject argument is null, AND
  • calling triple.predicate.equals with the specified predicate as an argument returns true, or the predicate argument is null, AND
  • calling triple.object.equals with the specified object as an argument returns true, or the object argument is null

This method implements AND functionality, so only triples matching all of the given non-null arguments will be included in the result.

Note, this method always returns a new Graph, even if that Graph contains no Triples.

Note, Graphs represent Sets of Triples, the order is arbitrary, so this method may result in differing results when called repeatedly with a limit.

any? subject
The subject value to match against, may be null.
any? predicate
The predicate value to match against, may be null.
any? object
The object value to match against, may be null.
optional unsigned long limit
An optional limit to the amount of triples returned, if 0 is passed or the argument is set to null then all matching triples will be contained in the resulting graph.
Graph merge(in Graph graph)
Returns a new Graph which is a concatenation of this graph and the graph given as an argument.
Graph graph
The Graph to concatenate with this graph, the resulting Graph must not contain any duplicates.
Graph addAll(in Graph graph)

Imports the graph in to this graph. This method returns the graph instance it was called on.

This method differes from Graph.merge in that it adds all triples from graph to the current instance, rather than combining the two graphs to create a new instance.

Graph graph
The Graph to import in to this graph, the import must not produce any duplicates.
readonly attribute sequence<TripleAction> actions
An array of actions to run when a Triple is added to the graph, each new triple is passed to the run method of each TripleAction in the array.
Graph addAction(in TripleAction action, in optional boolean run)
Adds a new TripleAction to the array of actions, if the run argument is specified as true then each Triple in the Graph MUST be passed to the TripleAction before this method returns.
TripleAction action
The TripleAction to add.
optional boolean run
A boolean flag specifying whether all triples in the graph should immediately be tried by the action.

Basic Node Types

Nodes

RDFNode is the base class of NamedNode, BlankNode, and Literal.

readonly attribute any nominalValue

The nominalValue of an RDFNode is refined by each interface which extends RDFNode.

readonly attribute DOMString interfaceName

Provides access to the string name of the current interface, normally one of "NamedNode", "BlankNode" or "Literal".

This method serves to disambiguate instances of RDFNode which are otherwise identical, such as NamedNode and BlankNode.

DOMString toString()

The stringification of an RDFNode is defined as follows, if the interfaceName is

  • NamedNode then return the stringified nominalValue.
  • BlankNode then prepend "_:" to the stringified value and return the result.
  • Literal then return the stringified nominalValue.
any valueOf()

This method provides access to the implementations host environment native value for this RDFNode, if the interfaceName is

  • NamedNode or BlankNode then return the stringified nominalValue.
  • Literal then return the language native value for this node where supported, or the stringified nominalValue if the datatype of the Literal is unknown or the value is out of the range supported. See the definition of Literal for further guidance.
DOMString toNT()

Returns the N-Triples representation of the RDFNode as defined by [[!RDF-TESTCASES]].

boolean equals(in any tocompare)

If tocompare is an instance of RDFNode then this method returns true if an only if all attributes on the two interfaces are equivalent.

If tocompare is NOT an instance of RDFNode then the it MUST be compared against the result of calling toValue on this node.

You cannot simply test two RDF Nodes for equivalence using general language constructs such as ==.

any tocompare
The value to test for equivalence with this node.

Named Nodes

A node identified by an IRI. IRIs are defined by International Resource Identifier [[!IRI]].

readonly attribute any nominalValue
The IRI identifier of the node.

Blank Nodes

A BlankNode is a reference to an unnamed resource (one for which an IRI is not known), and may be used in a Triple as a unique reference to that unnamed resource.

BlankNodes are stringified by prepending "_:" to a unique value, for instance _:b142 or _:me, this stringified form is referred to as a "blank node identifier".

readonly attribute any nominalValue

The temporary identifier of the BlankNode, the nominalValue may be of any type, so long as it is unique and can be stringified, for instance a number or a string.

The nominalValue MUST NOT be relied upon in any way between two separate processing runs of the same document, or two instances of Graph containing "the same" triples.

Developers and authors must not assume that the nominalValue of a BlankNode will remain the same between two processing runs. BlankNode nominalValues are only valid for the most recent processing run on the document. BlankNodes nominalValues will often be generated differently by different processors.

Implementers MUST ensure that BlankNode nominalValues are unique within the current environment, two BlankNodes are considered equal if, and only if, their nominalValues are strictly equal.

Literals

Literals represent values such as numbers, dates and strings in RDF data. A Literal is comprised of three attributes:

  • a lexical representation of the nominalValue
  • an optional language represented by a string token
  • an optional datatype specified by a NamedNode

Literals representing plain text in a natural language may have a language attribute specified by a text string token, as specified in [[!BCP47]], normalized to lowercase (e.g., 'en', 'fr', 'en-gb'). They may also have a datatype attribute such as xsd:string.

The RDF Working Group is currently looking at the handling of "Plain Literals", with regards to datatypes, further guidance may result in changes to this specification.

Literals representing values with a specific datatype, such as the integer 72, may have a datatype attribute specified in the form of a NamedNode (e.g., <http://www.w3.org/2001/XMLSchema#integer>).

Literals often represent values for which the host environment of an RDF Interface implementation has a corresponding native value, this value can be accessed by the valueOf method of the Literal interface.

Implementations MUST provide native value type conversion, via the valueOf method, for the following XML Schema datatypes:

  • xsd:string
  • xsd:boolean
  • xsd:dateTime
  • xsd:date
  • xsd:time
  • xsd:int
  • xsd:double
  • xsd:float
  • xsd:decimal
  • xsd:positiveInteger
  • xsd:integer
  • xsd:nonPositiveInteger
  • xsd:negativeInteger
  • xsd:long
  • xsd:int
  • xsd:short
  • xsd:byte
  • xsd:nonNegativeInteger
  • xsd:unsignedLong
  • xsd:unsignedInt
  • xsd:unsignedShort
  • xsd:unsignedByte

When a Literal contains both a datatype and a language, and the serialization or stringification does not support a lexical representation of both attributes, language SHOULD take precedence.

RDF specifies that Literal equality is based on the lexical representation of values rather than the value space, for this reason the Literals "100"^^xsd:double and "1e2"^^xsd:double are not considered equal.

readonly attribute DOMString nominalValue
The lexical representation of the Literals value.
readonly attribute DOMString? language
An optional language string as defined in [[!BCP47]], normalized to lowercase.
readonly attribute NamedNode? datatype
An optional datatype identified by a NamedNode.
any valueOf()

This method provides access to a corresponding host environment specific native value, where one exists.

If the datatype identifier of the Literal is not known by the implementation, or the value is outside of the range handled by the corresponding native type, then valueOf MUST return the DOMString lexical representation of the nominalValue.

The chart below provides a datatype map for the XSD datatypes which must be supported.

Datatype Map:
Specified Datatype IDL ECMAScript
xsd:string DOMString string
xsd:boolean boolean boolean
xsd:dateTime - Date
xsd:date - Date
xsd:time - Date
xsd:int long number
xsd:double double number
xsd:float float number
xsd:decimal double number
xsd:positiveInteger long number
xsd:integer long number
xsd:nonPositiveInteger long number
xsd:negativeInteger long number
xsd:long long number
xsd:int long number
xsd:short short number
xsd:byte short number
xsd:nonNegativeInteger unsigned long number
xsd:unsignedLong unsigned long number
xsd:unsignedInt unsigned long number
xsd:unsignedShort unsigned short number
xsd:unsignedByte unsigned short number
xsd:positiveInteger unsigned long number

Implementations MUST convert xsd:boolean values to native booleans rather than Boolean Objects to limit unexpected behaviour.

Additional Interfaces

Triple Filters

The TripleFilter is a callable interface which is used to implement Triple tests, a response of true means that the test has been passed.

When used with the filter method of the Graph interface a response of true indicates the Triple should be included in the output set.

boolean test (in Triple triple)
A callable function that returns true if the input Triple passes the test this function implements.
Triple triple
The triple to test against the filter.

Example Filters

The following shows an example set of common TripleFilters exposed on a filter attribute of RDFEnvironment:

        
        

Triple Callbacks

The TripleCallback is a callable interface which is used to implement a function which can be called on a Triple.

This interface is typically used with the forEach method of the Graph interface.

void run (in Triple triple, in Graph graph)
A callable function which can be executed on a Triple.
Triple triple
The triple to be used.
Graph graph
The graph which contains the triple.

Triple Actions

TripleAction is an interface which combines the functionality of TripleFilter and TripleCallback, given a test and an action, the run method will execute the action if, and only if, it passes the test.

attribute TripleFilter test
An instance of TripleFilter used to test whether the action should be executed on a specific Triple.
attribute TripleCallback action
The action to call on triple which successfully pass the test.
void run (in Triple triple, in Graph graph)
This method will run the specified action on the specified Triple if it passes the test.
Triple triple
The triple to be tried.
Graph graph
The graph which contains the triple.

RDF Environment Interfaces

Overview

The RDF Environment Interfaces provide all basic functionality needed to work with RDF data in a programming environment, and within specific contexts, for instance within a Parser, Serializer or Data Store.

Terms, Prefixes and Profiles

Within a programming context, and within various RDF serializations, it is increasingly important to be able to simplify access to properties and refer to full IRIs by using CURIEs or Terms.

In order to accomplish this a Profile of Prefix and Term mappings is needed.

This specification includes the definition of three Interfaces which serve to address these needs:

Prefix Maps

omittable getter DOMString get(in DOMString prefix)
DOMString prefix
The prefix MUST not contain any whitespace
omittable setter void set(in DOMString prefix, in DOMString iri)
DOMString prefix
The prefix MUST not contain any whitespace
DOMString iri
An IRI, as defined by [[!IRI]]
omittable deleter void remove(in DOMString prefix)
DOMString prefix
The prefix MUST contain any whitespace
DOMString resolve(in DOMString curie)

Given a valid CURIE for which a prefix is known (for example "rdfs:label"), this method will return the resulting IRI (for example "http://www.w3.org/2000/01/rdf-schema#label")

If the prefix is not known then this method will return null.

DOMString curie
The CURIE to resolve.
DOMString shrink(in DOMString iri)
Given an IRI for which a prefix is known (for example "http://www.w3.org/2000/01/rdf-schema#label") this method returns a CURIE (for example "rdfs:label"), if no prefix is known the original IRI is returned.
DOMString iri
The IRI to shrink to a CURIE
void setDefault(in DOMString iri)
DOMString iri
The iri to be used when resolving CURIEs without a prefix, for example ":this".
PrefixMap addAll(in PrefixMap prefixes, in optional boolean override)

This method returns the instance on which it was called.

PrefixMap prefixes
The PrefixMap to import.
optional boolean override
If true then conflicting prefixes will be overridden by those specified on the PrefixMap being imported, by default imported prefixes augment the existing set.

Example

This example illustrates how PrefixMap can be used to resolve known CURIEs to IRIs, shrink IRIs in to CURIEs, and how to specify and use a default prefix.

      
      

Term Maps

omittable getter DOMString get(in DOMString term)
DOMString term
The term MUST not contain any whitespace or the : (single-colon) character
omittable setter void set(in DOMString term, in DOMString iri)
DOMString term
The term MUST not contain any whitespace or the : (single-colon) character
DOMString iri
An IRI, as defined by [[!IRI]]
omittable deleter void remove(in DOMString term)
DOMString term
The term MUST not contain any whitespace or the : (single-colon) character
DOMString resolve(in DOMString term)

Given a valid term for which an IRI is known (for example "label"), this method will return the resulting IRI (for example "http://www.w3.org/2000/01/rdf-schema#label").

If no term is known and a default has been set, the IRI is obtained by concatenating the term and the default iri.

If no term is known and no default is set, then this method returns null.

DOMString term
The term to resolve.
DOMString shrink(in DOMString iri)
Given an IRI for which an term is known (for example "http://www.w3.org/2000/01/rdf-schema#label") this method returns a term (for example "label"), if no term is known the original IRI is returned.
DOMString iri
The IRI to shrink to an term
void setDefault(in DOMString iri)
DOMString iri
The default iri to be used when an term cannot be resolved, the resulting IRI is obtained by concatenating this iri with the term being resolved.
TermmMap addAll(in TermMap terms, in optional boolean override)

This method returns the instance on which it was called.

TermMap terms
The TermMap to import.
optional boolean override
If true then conflicting terms will be overridden by those specified on the TermMap being imported, by default imported terms augment the existing set.

Example

This example illustrates how TermMap can be used to resolve known terms to IRIs, shrink IRIs for known terms in to terms, and how to specify and use a default vocabulary for unknown terms.

      
      

Profiles

Profiles provide an easy to use context for negotiating between CURIEs, Terms and IRIs.

readonly attribute PrefixMap prefixes
An instance of PrefixMap
readonly attribute TermMap terms
An instance of TermMap
DOMString resolve(in DOMString toresolve)

Given an Term or CURIE this method will return an IRI, or null if it cannot be resolved.

If toresolve contains a : (colon) then this method returns the result of calling prefixes.resolve(toresolve)

otherwise this method returns the result of calling terms.resolve(toresolve)

DOMString toresolve
A string Term or CURIE.
void setDefaultVocabulary(in DOMString iri)
This method sets the default vocabulary for use when resolving unknown terms, it is identical to calling the setDefault method on terms.
DOMString iri
The IRI to use as the default vocabulary.
void setDefaultPrefix(in DOMString iri)
This method sets the default prefix for use when resolving CURIEs without a prefix, for example ":me", it is identical to calling the setDefault method on prefixes.
DOMString iri
The IRI to use as the default prefix.
void setTerm(in DOMString term, in DOMString iri)
This method associates an IRI with a term, it is identical to calling the set method on term.
DOMString term
The term to set, MUST not contain any whitespace or the : (single-colon) character
DOMString iri
The IRI to associate with the term.
void setPrefix(in DOMString prefix, in DOMString iri)
This method associates an IRI with a prefix, it is identical to calling the set method on prefixes.
DOMString prefix
The prefix to set, MUST not contain any whitespace.
DOMString iri
The IRI to associate with the prefix.
Profile importProfile(in Profile profile, in optional boolean override)

This method functions the same as calling prefixes.addAll(profile.prefixes, override) and terms.addAll(profile.terms, override), and allows easy updating and merging of different profiles, such as those exposed by parsers.

This method returns the instance on which it was called.

Profile profile
The Profile to import.
optional boolean override
If true then conflicting terms and prefixes will be overridden by those specified on the Profile being imported, by default imported terms and prefixes augment the existing set.

High level API

The RDF Interfaces are primarily intended to enable interoperability between RDF libraries and extensions, and for usage by advanced users. Implementations are encouraged to provide their own sets of abstracted interfaces and methods tailored to the use-cases they are addressing.

Implementors are encouraged to share implementations of various interfaces defined in this specification, offering specialized or highly optimized implementations of interfaces, for instance rigourously tested parsers and serializers for specific RDF serializations, or highly optimized Graph interfaces.

Methods to instantiate the basic interfaces required to work with RDF data in a programming environment, are all exposed by a single interface, as described in the following section.

RDF Environment

The RDF Environment is an interface which exposes a high level API for working with RDF in a programming environment.

The RDF Environment interface extends Profile and provides the default context for working with CURIEs, Terms and IRIs, implementations are encouraged to offer rich prefix maps by default, and MUST instantiate the environment with the following prefixes defined:

Prefix IRI
owl http://www.w3.org/2002/07/owl#
rdf http://www.w3.org/1999/02/22-rdf-syntax-ns#
rdfs http://www.w3.org/2000/01/rdf-schema#
rdfa http://www.w3.org/ns/rdfa#
xhv http://www.w3.org/1999/xhtml/vocab#
xml http://www.w3.org/XML/1998/namespace
xsd http://www.w3.org/2001/XMLSchema#

This interface also exposes all methods required to create instances of TermMaps, PrefixMaps, Profiles and all the Concept Interfaces.

Implementations of the RDFEnvironment MUST expose all the methods defined on this interface, as defined by this specification.

Future RDF Interface extensions and modules MAY supplement this interface with methods and attributes which expose the functionality they define, in a manner consistent with this API.

BlankNode createBlankNode()
Creates a new BlankNode.
NamedNode createNamedNode()
Creates a NamedNode identified by the given IRI.
DOMString value
An IRI, CURIE or TERM.
Literal createLiteral()
Creates a Literal given a value, an optional language and/or an optional datatype.
DOMString value

The value to be represented by the Literal, the value MUST be a lexical representation of the value.

optional DOMString? language
The language that is associated with the Literal encoded according to the rules outlined in [[BCP47]].
optional NamedNode? datatype
The datatype of the Literal.
Triple createTriple()
Creates a Triple given a subject, predicate and object. If any incoming value does not match the requirements listed below, a Null value MUST be returned by this method.
RDFNode subject
The subject value of the Triple.
RDFNode predicate
The predicate value of the Triple.
RDFNode object
The object value of the Triple.
Graph createGraph()
Creates a new Graph, an optional array of Triples to include within the graph may be specified, this allows easy transition between native arrays and Graphs and is the counterpart for the toArray method of the Graph interface.
optional []Triple triples
An optional array of Triples to be added to the Graph as it is created.
TripleAction createAction(in TripleFilter test, in TripleCallback action)
Creates a TripleAction given a TripleFilter test and a TripleCallback action.
TripleFilter test
The TripleFilter to test the Triple against.
TripleCallback action
The action to run should the Triple being tried pass the test.
Profile createProfile(in optional boolean empty)
optional boolean empty
If true is specified then a profile with an empty TermMap and PrefixMap will be returned, by default the Profile returned will contain populated term and prefix maps replicating those of the current RDF environment.
TermMap createTermMap(in optional boolean empty)
optional boolean empty
If true is specified then an empty TermMap will be returned, by default the TermMap returned will be populated with terms replicating those of the current RDF environment.
PrefixMap createPrefixMap(in optional boolean empty)
optional boolean empty
If true is specified then an empty PrefixMap will be returned, by default the PrefixMap returned will be populated with prefixes replicating those of the current RDF environment.

RDF Data Interfaces

Overview

The RDF Data Interfaces are modular, standalone interfaces which can be implemented by RDF Libraries and API extensions to enable interoperability.

Developers and Specification authors are encouraged to use these interfaces when defining functionality within one of the realms covered by these interfaces.

Parser and Serializer implementors SHOULD provide relevant parse, process or serialize methods on the RDF Environment interface for their implementations. For example a Turtle parser SHOULD augment RDFEnvironment with parseTurtle and processTurtle methods which accept a String toparse argument, whilst an RDFa parser SHOULD augment RDFEnvironment with a parseRDFa method which accepts a Document argument.

Parsing and Serializing Data

Data Parsers

The DataParser is a generic RDF document parser which can be used to either parse the triples serialized within an RDF document in to a Graph, or to process an RDF document by passing each triple found to a TripleCallback for processing.

readonly attribute Graph processorGraph
An optional Graph produced by RDF Parsers containing additional parsing information and errors.
boolean parse(in any toparse, ParserCallback callback, in optional DOMString base, in optional TripleFilter filter, in optional Graph graph)

Parses the triples serialized within an input RDF document in to a Graph, then executes a given ParserCallback on the populated Graph.

If a TripleFilter is passed to the parser, then each Triple found in the document will only be added to the output Graph if it passes the test implemented by the TripleFilter.

By default a new Graph is provided, however users may optionally specify a Graph to which the parsed triples will be added. This allows users to provide a custom or persistent Graph implementation, or to automatically merge the triples from several documents in to a single Graph.

A boolean response is given indicating if the parse was successful or not.

any toparse
The document to parse, the type of argument required may further be constrained by implementations of this interface, for instance an RDFa parser may require an instance of Document, whilst a Turtle parser may require a String.
ParserCallback? callback
The ParserCallback to execute once the parse has completed, the ParserCallback will be passed a single argument which is the propulated Graph.
optional DOMString base
An optional base to be used by the parser when resolving relative IRI references.
optional TripleFilter filter
An optional TripleFilter to test each Triple against before adding to the output Graph, only those triples successfully passing the test will be added to the output graph.
optional Graph graph
An optional Graph to add the parsed triples to, if no Graph is provided then a new, empty, Graph will be used.
boolean process(in any toparse, ProcessorCallback callback, in optional DOMString base, in optional TripleFilter filter)

Parses the triples serialized within an input RDF document and passes each (non filtered) Triple found to a TripleCallback, this interface allows RDF documents to be processed by SAX-like parsers whilst maintaining a minimal memory footprint.

If a TripleFilter is passed to the parser, then each Triple found in the document will only be passed to the TripleCallback if it passes the test implmented by the filter.

any toparse
The document to parse, the type of argument required may further be constrained by implementations of this interface, for instance an RDFa parser may require an instance of Document, whilst a Turtle parser may require a String.
ProcessorCallback callback
The ProcessorCallback to execute on each (non-filtered) Triple found by the parser.
optional DOMString base
An optional base to be used by the parser when resolving relative IRI references.
optional TripleFilter filter
An optional TripleFilter to test each Triple against before adding to the output Graph, only those triples successfully passing the test will be added to the output graph.

Examples

Example of basic and advanced DataParser.parse usage:

        
        

Example of basic and advanced DataParser.process usage:

        
        

Data Serializers

The DataSerializer is a generic interface implemented by Graph serializers.

Implementations of this interface may further constrain the return type, for instance an RDFa serializer may return an instance of Document, whilst a Turtle serializer may return a String.

any serialize(Graph graph)
A method, which when called will serialize the given Graph and return the resulting serialization.
Graph graph
The Graph to serialize.

Additional Interfaces

The ParserCallback interface is used by the parse method of the DataParser interface.

void run(Graph graph)
A function to be executed on a Graph produced by a parse operation on an RDF Document.
Graph graph
The Graph on which this function is to be executed.

The ProcessorCallback interface is used by the process method of the DataParser interface.

void run(Triple triple)
A function to be executed on a Triple produced by a process operation on an RDF Document.
Triple triple
The Triple on which this function is to be executed.

Acknowledgements

At the time of publication, the members of the RDF Web Application Working Group were: