RDF enables information providers to attach general metadata to published web resources. This metadata 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 Linked Data, using the information to improve the collective utility of the Web for humankind is the true goal. 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.
This document is a detailed specification for the RDF API. The document is primarily intended for the following audiences:
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 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
)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 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.
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:
Concept Stack for the RDF API
Represents and wraps the various RDF Concepts
Provide all basic methods required to work with RDF data.
Set of modular interfaces covering common areas of functionality.
The design goals that drove the creation of the APIs that are described in this document are:
The following list of examples outlines common use cases that can be solved by using the RDF API:
Susan is a Web developer in a company that offers calendar solutions. She is responsible for creating a web client that connects with the REST API of her company's calendar server. This RESTful API uses RDF as input-output format. Susan wants to use the RDF API to parse the RDF data the system returns for each of her JSON requests. In detail, she wants to render an interactive timeline and populate it with events that are described in this RDF data.
//dictionary to store event objects events = {} // filter that create events createEvents = new function(graph) { graph.forEach( function(t) { events[t.subject][t.predicate] = t.object; }); } // create term for URI prefixes.cal = "http://www.w3.org/2002/12/cal#"; // Restful API endpoint to calendar service apiEndpoint = "http://example.org/calendar/susan/events/"; // parse requested RDF result represented in TURTLE turtle.parse(apiEndpoint, new function(graph) { graph.filter( rdf.filters.type( rdf.resolve("cal:Vevent") ) .forEach( function(t) { // iterate over the results, creating a filtered graph for each subject // found of type Event and pass that graph to the createEvents() function createEvents( graph.filter( rdf.filters.s(t.subject) ); // pass created event objects to timeline function renderHTMLTimeline(events); }); });
Pete is an entrepeneur who owns a Web shop where he offers MP3 encoded songs and movies. The content management system thta Pete used as base technology creates RDFa markup for each offered product, product category, and user profiles. Now Pete wants to offer customers an RDF powered shopping cart and browsing history. While browsing through his shop, users can visit products and add these to their shopping cart. Pete plans to implement a recommender algorithms in Javascript that runs local on the customer's browser and processes the RDF data contained in the user's shopping cart and history. Customer's may link their user profile to those of friends. The algorithm also requests shopping histories of these linked friends in order to improve recommender results. Because all the programming logic runs client-side on the customers' browsers, Pete saves server costs and can advertise his job as preserving the customers' privacy. The RDF API offers Pete an all-in-one interface for developing the RDF related software modules.
TODO
Max is a passionate crime author and Web developer. He offers his books in EPUB format and annotates places, persons, companies, and event in his stories with RDFa markup. Pete has developed a Web-based e-book reader and now plans to provide his fans with additional information about occuring scenes, persons, companies, or events by rendering maps, exciting vitas, company logos, etc. He wants to use the RDF API to request and handle background information from DBpedia, Freebase and other data providers.
TODO
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.
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:
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.
"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.
":this"
.This method returns the instance on which it was called.
true
then conflicting prefixes will be
overridden by those specified on the This example illustrates how
:
(single-colon) character:
(single-colon) character:
(single-colon) characterGiven 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.
"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.
iri
with
the term
being resolved.This method returns the instance on which it was called.
true
then conflicting terms will be
overridden by those specified on the This example illustrates how
Profiles provide an easy to use context for negotiating between CURIEs, Terms and IRIs.
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)
setDefault
method on terms
.
":me"
, it is
identical to calling the setDefault
method on prefixes
.
set
method on term
.
:
(single-colon) characterset
method on prefixes
.
This method functions the same as calling prefixes.import(profile.prefixes,
override)
and terms.import(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.
true
then conflicting terms and prefixes will
be overridden by those specified on the A
var people = document.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:
document.data.setMapping("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); document.data.setMapping("foaf", "http://xmlns.com/foaf/0.1/"); var people = document.data.getProjections("rdf:type", "foaf:Person");
You can also get a
var albert = document.data.getProjection("http://example.org/people#albert");
You can also specify a relative IRI and the document IRI will be automatically pre-pended:
var albert = document.data.getProjection("#albert");
You can get a list of
var peopleNamedAlbert = document.data.getProjections("foaf:name", "Albert Einstein");
You can retrieve property values from
var albert = document.data.getProjection("#albert"); var name = albert.get("foaf:name");
You can specify values that you would like to map to a
var albert = document.data.getProjection("#albert", {"name": "foaf:name"}); var name = albert.name;
The
The RDF Environment is an interface which exposes a high level
API for working with RDF in a programming environment, an instance of
this interface MUST be exposed by an rdf
attribute by
libraries implementing the RDF API. For example:
mylib.rdf
data.rdf
The RDF Environment interface extends
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 MUST expose all the methods defined on this interface, as defined by this specification.
Future RDF API extensions and modules SHOULD supplement this interface with methods and attributes which expose the functionality they define, in a manner consistent with this API.
true
is specified then a profile with an
empty TermMap and PrefixMap will be returned, by default the true
is specified then an empty true
is specified then an empty
The
null
is returned.
null
.null
, the match is always positive.null
, the match is always positive.
null
, the match is
always positive.null
, the match is always positive.null
, the match is always positive.
null
, the match is always
positive.null
, the match is always positive.At the time of publication, the members of the RDF Web Application Working Group were: