Copyright © 2010-2011 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C liability, trademark and document use rules apply.
RDF enables providers to publish various types of data on the Web in a unified format. This data intends to be machine-interpretable so that web developers can access it by programming languages in order to create applications for i.e., crawling, aggregating, summarizing, or highlighting contained information. While publishing RDF data on the web is vital to the growth of the Semantic Web, using the information to improve the collective utility of the Web is the true goal of the Semantic Web. To accomplish this goal, the RDF Application Programming Interface (RDF API) defines a set of standardized interfaces for working with RDF data in a web-based programming environment.
As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, and notes in this specification are non-normative. Everything else in this specification is normative.
The key words must, must not, required, should, should not, recommended, may, and optional in this specification are to be interpreted as described in [RFC2119].
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.
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.
This document was published by the RDF Web Applications Working Group as an Editor's Draft. If you wish to make comments regarding this document, please send them to public-rdfa-wg@w3.org (subscribe, archives). All feedback is welcome.
Publication as a Editor's Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
This section is non-normative.
RDF provides a means to publish and exchange machine-readable data about resources on the Web. A Web document can be attached with metadata in RDF in order to add a machine-interpretable layer underneath the document's content which is intended to be read by humans. By publishing RDF conform to the principles of Linking Open Data metadata about resources can be interlinked across different Web servers. This enables web developers to process published metadata about for example a News article and combine it with additional information from other sources.
This specification defines the RDF API, which may be used by developers and Web Applications to access and work with RDF data on the Web, while programing in a Web environment. The RDF API is designed to define a standardized programming interface for processing RDF within a Browser environment. The primary target language for the RDF API is ECMAScript, although other languages may also be considered.
This section is non-normative.
This document is a detailed specification for the RDF API. The document is primarily intended for web developers who want to process RDF data in a browser environment.
If you are not familiar with RDF, you should read about the Resource Description Framework (RDF) [RDF-CONCEPTS] before reading this document.
This document uses the Web Interface Definition Language [WEBIDL] to specify all language bindings. If you intend to implement any part of the RDF API 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:
rdf
, e.g., rdf:type
)xsd
, e.g., xsd:integer
)rdfs
, e.g., rdfs:label
)foaf
, e.g., foaf:name
)This section is non-normative.
More and more information providers put RDF data to published Web content. Although a variety of Web browsers have been extended to enable RDF support for viewing, browsing, collecting, and aggregating existing RDF data, a common programming interface for processing RDF data similarly across different programming languages, like it is possible for XML, is still missing.
This specification defines all necessary means for processing RDF within a Browser environment. The RDF API comprises the following functionalities:
The following section contains all of the interfaces that RDFa API implementers are expected to provide as well as guidance to ensure that implementations are conformant.
This section is non-normative.
A Projection is an object-oriented view of a particular subject that is expressed in the document. For example, to get all projections that express people in an RDF document, a developer can do the following:
var people = data.getProjections("http://www.w3.org/1999/02/22-rdf-syntax-ns#type", "http://xmlns.com/foaf/0.1/Person");A developer can also specify short-cuts to use when specifying the URI:
data.setMapping("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); data.setMapping("foaf", "http://xmlns.com/foaf/0.1/"); var people = data.getProjections("rdf:type", "foaf:Person");
This section is non-normative.
You can also get a Projection by its subject:
var albert = data.getProjection("http://example.org/people#albert");
You can get a list of Projection s by their properties:
var peopleNamedAlbert = data.getProjections("foaf:name", "Albert Einstein");
This section is non-normative.
You can retrieve property values from Projection s like so:
var albert = data.getProjection("http://example.org/people#albert"); var name = albert.get("foaf:name");
You can specify values that you would like to map to a Projection :
var albert = data.getProjection("http://example.org/people#albert", {"name": "foaf:name"}); var name = albert.name;
This section is non-normative.
In order to retrieve a list of all Projection s in the document that are similar to a Projection pattern, developers can use the query method.
For example, assume our source document contains the following event, marked up using the Data Vocabulary Event format:
<div prefix="v: http://rdf.data-vocabulary.org/#" typeof="v:Event"> <a rel="v:url" href="http://amyandtheredfoxies.example.com/events" property="v:summary">Tour Info: Amy And The Red Foxies</a> <span rel="v:location"> <a typeof="v:Organization" rel="v:url" href="http://www.kammgarn.de/" property="v:name">Kammgarn</a> </span> <div rel="v:photo"><img src="foxies.jpg"/></div> <span property="v:summary">Hey K-Town, Amy And The Red Foxies will rock Kammgarn in October.</span> When: <span property="v:startDate" content="20091015T19:00">15. Oct., 7:00 pm</span>- <span property="v:endDate" content="20091015T21:00">9:00 pm</span> </span> Category: <span property="v:eventType">concert</span> </div>
To query for all Event Projection s we know that we can do this:
var events = data.getProjections("rdf:type", "http://rdf.data-vocabulary.org/#Event");
However, to build a special Projection that contains the summary, start date and end date, we can also do this:
var events = data.query( { "rdf:type": "http://rdf.data-vocabulary.org/#Event" }, { "type": "rdf:type", "summary": "v:summary", "start": "v:startDate", "end": "v:endDate" } );
The Projection interface is used to build language-native objects that can be accessed in a way that is natural for the implementation language.
[NoInterfaceObject]
interface Projection {
DOMString[] getProperties ();
DOMString getSubject ();
getter any get (in DOMString uriOrCurie);
setter object set (in DOMString uriOrCurie, in object value);
any[] getAll (in DOMString uriOrCurie);
};
get
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
uriOrCurie | DOMString | ✘ | ✘ | The name of the property to retrieve. The argument can be either an absolute URI or a CURIE that will be resolved using the default document mapping. |
getter any
getAll
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
uriOrCurie | DOMString | ✘ | ✘ | The name of the property to retrieve. The argument can be either a full URI or a CURIE that will be resolved using the default document mapping. |
any[]
getProperties
DOMString[]
getSubject
DOMString
set
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
uriOrCurie | DOMString | ✘ | ✘ | The name of the property to set the value. The argument can be either an absolute URI or a CURIE that will be resolved using the default document mapping. |
value | object | ✘ | ✘ | The value of the property as a language-native datatype. |
setter object
The
RDFParser
is a generic RDF document parser which can be used to parse the
triples serialized within an RDF document in to a list of
Projections
[NoInterfaceObject]
interface RDFParser {
readonly attribute Projection
[] processorGraph;
boolean parse (in any toparse, in optional ParserCallback
callback, in optional DOMString base, in optional Projection
filter, in optional object template);
};
processorGraph
of type array of Projection
, readonlyparse
Parses the triples serialized within an input RDF document in to a
Sequence of
Projection
s, then executes a given
ParserCallback
on the populated
Sequence
.
If a Projection is passed to the parser as pattern, then each RDF data found in the document will only be added to the output Sequence of Projection s if it matches the null values used as wildcarts in the passed pattern.
A boolean response is given indicating if the parse was successful or not.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
toparse | any | ✘ | ✘ |
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
.
|
callback |
| ✘ | ✔ |
The
ParserCallback
to execute once the parse has completed, the
ParserCallback
will be passed a single argument which is the created Sequence of
Projection
s.
|
base | DOMString | ✘ | ✔ | An optional base to be used by the parser when resolving relative IRI references. |
filter |
| ✘ | ✔ | The Projection filter is used as a filter definition. Null values of projected entries are processed as wildcards. |
template | object | ✘ | ✔ | The Projection template is used to build the return value. The template consists of a key-value associative array where the key is the name of the property to create in the Projection and the value is the URI to use when matching against predicates in each triple. |
boolean
The
ParserCallback
interface is used by the
parse
method of the
RDFParser
interface.
[NoInterfaceObject, Callback]
interface ParserCallback {
void run (in sequence<Projection
> projections);
};
run
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
projections | sequence< | ✘ | ✘ |
void
The
Data
interface is used to access the structured data in the RDF document.
[NoInterfaceObject]
interface Data {
Projection
getProjection (in DOMString subject, in optional object template);
sequence<Projection
> getProjections (in optional object template);
sequence<Projection
> getProjections (in optional DOMString property, in optional DOMString? value, in optional object template);
sequence<DOMString> getProperties (in optional DOMString? subject);
sequence<DOMString> getSubjects (in optional DOMString? property, in optional DOMString? value);
sequence<any> getValues (in optional DOMString? subject, in optional DOMString? property);
sequence<Projection
> query (in object pattern, in object template);
DOMString setMapping (in DOMString mapping, in DOMString uri);
boolean parse (in RDFParser
parser, in any toparse, in ParserCallback
callback, in optional DOMString base, in optional Projection
filter, in optional object template);
};
getProjection
null
is returned.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
subject | DOMString | ✘ | ✘ |
The subject to use when matching against triples. The subject can
be either an absolute URI or a CURIE. The subject is used to match
against the URI in the first part of a triple. An implementation
must coerce the DOMString to the same type as the triple's subject
being compared. If the type coercion will result in a URI, the
CURIE mappings must be queried first for a mapping and the given
property expanded as a CURIE if a mapping is found. If the subject
does not exist in the RDF document, the return value must be
null
.
|
template | object | ✘ | ✔ | The Projection template is used to build the return value. The template consists of a key-value associative array where the key is the name of the property to create in the Projection and the value is the URI to use when matching against predicates in each triple. |
Projection
getProjections
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
template | object | ✘ | ✔ | The Projection template is used to build the return value. The template consists of a key-value associative array where the key is the name of the property to create in the Projection and the value is the URI to use when matching against predicates in each triple. |
sequence<Projection
>
getProjections
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
property | DOMString | ✘ | ✔ |
The property to use when matching against triples. The property
can be either an absolute URI or a CURIE. The property is used to
match against the URI in the second part of a triple, also known
as the predicate. An implementation must coerce the DOMString to
the same type as the predicate being compared. If the type
coercion will result in a URI, the CURIE mappings must be queried
first for a mapping and the given property expanded as a CURIE if
a mapping is found. If the value is
null
, the match is always positive.
|
value | DOMString | ✔ | ✔ |
The value to use when matching against triples. The value can be
either an absolute URI or a CURIE. The value is used to match
against the final part of a triple, also known as the object. An
implementation must coerce the DOMString to the same type as the
object being compared. If the type coercion will result in a URI,
the CURIE mappings must be queried first for a mapping and the
given value expanded as a CURIE if a mapping is found. If the
value is
null
, the match is always positive.
|
template | object | ✘ | ✔ | The Projection template is used to build the return value. The template consists of a key-value associative array where the key is the name of the property to create in the Projection and the value is the URI to use when matching against predicates in each triple. |
sequence<Projection
>
getProperties
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
subject | DOMString | ✔ | ✔ |
The subject to use when matching against triples. The subject is
used to match against the URI in the first part of a triple. The
subject can be either an absolute URI or a CURIE. The subject is
used to match against the first part of a triple. An
implementation must coerce the DOMString to the same type as the
triple's subject that is being compared. If the type coercion will
result in a URI, the CURIE mappings must be queried first for a
mapping and the given property expanded as a CURIE if a mapping is
found. If the given subject is
null
, the match is always positive.
|
sequence<DOMString>
getSubjects
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
property | DOMString | ✔ | ✔ |
The property to use when matching against triples. The property
can be either an absolute URI or a CURIE. The property is used to
match against the URI in the second part of a triple, also known
as the predicate. An implementation must coerce the DOMString to
the same type as the predicate being compared. If the type
coercion will result in a URI, the CURIE mappings must be queried
first for a mapping and the given property expanded as a CURIE if
a mapping is found. If the value is
null
, the match is always positive.
|
value | DOMString | ✔ | ✔ |
The value to use when matching against triples. The value can be a
number, a boolean, a DOMString, an absolute URI or a CURIE. The
value is used to match against the final part of a triple, also
known as the object. An implementation must coerce the DOMString
to the same type as the triple object being compared. If the type
coercion will result in a URI, the CURIE mappings must be queried
first for a mapping and the given property expanded as a CURIE if
a mapping is found. If the value is
null
, the match is always positive.
|
sequence<DOMString>
getValues
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
subject | DOMString | ✔ | ✔ |
The subject to use when matching against triples. The subject can
be either an absolute URI or a CURIE. The subject is used to match
against the URI in the first part of a triple. An implementation
must coerce the DOMString to the same type as the subject being
compared. If the type coercion will result in a URI, the CURIE
mappings must be queried first for a mapping and the given
property expanded as a CURIE if a mapping is found. If the value
is
null
, the match is always positive.
|
property | DOMString | ✔ | ✔ |
The property to use when matching against triples. The property
can be either an absolute URI or a CURIE. The property is used to
match against the URI in the second part of a triple, also known
as the predicate. An implementation must coerce the DOMString to
the same type as the predicate being compared. If the type
coercion will result in a URI, the CURIE mappings must be queried
first for a mapping and the given property expanded as a CURIE if
a mapping is found. If the value is
null
, the match is always positive.
|
sequence<any>
parse
A boolean response is given indicating if the parse was successful or not.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
parser |
| ✘ | ✘ | The parser used to read the passed document. |
toparse | any | ✘ | ✘ |
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
.
|
callback |
| ✘ | ✘ |
The
ParserCallback
to execute once the parse has completed, the
ParserCallback
will be passed a single argument which is the created Sequence of
Projection
s.
|
base | DOMString | ✘ | ✔ | An optional base to be used by the parser when resolving relative IRI references. |
filter |
| ✘ | ✔ | The Projection filter is used as a filter definition. Null values of projected entries are processed as wildcards. |
template | object | ✘ | ✔ | The Projection template is used to build the return value. The template consists of a key-value associative array where the key is the name of the property to create in the Projection and the value is the URI to use when matching against predicates in each triple. |
boolean
query
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
pattern | object | ✘ | ✘ | The Projection pattern is used as a query definition. |
template | object | ✘ | ✘ | The Projection template is used to build the return value. The template consists of a key-value associative array where the key is the name of the property to create in the Projection and the value is the URI to use when matching against predicates in each triple. |
sequence<Projection
>
setMapping
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
mapping | DOMString | ✘ | ✘ | The shortened form of the URI to map. |
uri | DOMString | ✘ | ✘ | An absolute URI that the mapping should expand to when used with any of the structured data APIs. |
DOMString
At the time of publication, the members of the RDF Web Application Working Group were: