The necessity of Hypermedia RDF and an approach to achieve it

Vision paper presented at LAPIS 2012, 2012-05-27.

Kjetil Kjernsmo <kjetil@kjernsmo.net>.

Ph.D. Research Fellow, Department of Informatics, University of Oslo, Norway

http://folk.uio.no/kjekje/2012/lapis2012.xhtml

Kjetil Kjernsmo Creative Commons Attribution-Sharealike 3.0 Norway License.

About me

Motivations

What can I do to Knossos?

Consider http://dbpedia.org/data/Knossos

With this URI I can get a description of Knossos with links so that I can get more data and more links!

Seriously, this is where we were at least 5 years ago!

What do I want to do?

How can I do that?

If only it had been done RESTfully...

What is this REST thing?

REST is defined by four interface constraints: identification of resources; manipulation of resources through representations; self-descriptive messages; and, hypermedia as the engine of application state.

Roy Fielding

My emphasis: Note the HATEOAS constraint!

The take-away:

Don't make developers look up the spec!

Linked Data is RESTful, right?

Some suggest that Linked Data is inherently RESTful since RDF serializations are hypermedia types.

My answer: Not really, it depends...

What did I want to do?

RESTfulness must be judged on the basis of applications.

Turning RDF into a Hypermedia Type

First, RDF isn't a media type, serializations are.

Mike Amundsen defines hypermedia types as:

Hypermedia Types are MIME media types that contain native hyper-linking semantics that induce application flow. For example, HTML is a hypermedia type; XML is not.

Mike Amundsen's "H Factor" classification

Hypermedia Factors
CL
CR CU CM
LE LO LT LN LI
  1. Link Support
  2. Control Data Support

(Shameless copy'n'paste).

Embedding links

LE

Support for embedded links (HTTP GET)

<img src="http://www.example.org/images/logo" title="company logo" />
Hypermedia Factors
CL
CR CU CM
LE LO LT LN LI

Closest I got was owl:imports, but is this really important in RDF context?

Outbound links

LO

Support for out-bound navigational links (HTTP GET)

<a href="http://www.example.org/search" title="view search page">Search</a>
Hypermedia Factors
CL
CR CU CM
LE LO LT LN LI

The usual links of RDF, trivially supported.

Templated queries

LT

Support for templated queries (HTTP GET)

<form method="get">
  <label>Search term:</label>
  <input name="query" type="text" value="" />
  <input type="submit" />
</form>
Hypermedia Factors
CL
CR CU CM
LE LO LT LN LI

W3C Submission SPARQL Inferencing Notation (SPIN) embeds SPARQL in RDF.

Non-Idempotent updates

LN

Support for non-idempotent updates (HTTP POST)

    
<form method="post" action="http://www.example.org/my-keywords"/>
  <label>Keywords:</label>
  <input name="keywords" type="text" value="" />
  <input type="submit" />
</form>
Hypermedia Factors
CL
CR CU CM
LE LO LT LN LI

Two cases:

  1. Add some triples to the existing resource.
  2. Let the server decide the URI of the new resource (typically collection management)

How do we indicate updates can be done?

Hypermedia Factors
CL
CR CU CM
LE LO LT LN LI

We add triples to the resource!

Adding triples

<> hm:canBe hm:mergedInto .

Indicates that an RDF Merge of payload into the resource should be done.

Might this be idempotent?

More concrete example

Look up http://dbpedia.org/resource/Knossos, get a 303 to http://dbpedia.org/data/Knossos, with:

<http://dbpedia.org/resource/Knossos> a yago:ArchaeologicalSitesInCrete ,
                yago:FormerPopulatedPlacesInGreece ,
                yago:MinoanArchaeologicalSitesInGreece .
# [...]
<http://dbpedia.org/data/Knossos> hm:canBe hm:mergedInto .

Creating new resource

<> hm:createSimilarAt <../> .

When payload is sent to the object, the server may create a new URI for it.

Idempotent updates

LI

Support for idempotent updates (HTTP PUT, DELETE)

    
function delete(id) 
{
  var client = new XMLHttpRequest();
  client.open("DELETE", "/records/"+id);
}
Hypermedia Factors
CL
CR CU CM
LE LO LT LN LI

Two triples for replace and delete:

<> hm:canBe hm:replaced, hm:deleted .

Can we say that it is possible to PUT a resource to a new URL?

Control data for read requests

CR

Support for modifying control data for read requests
(e.g. HTTP Accept-* headers).

<xsl:include href="http://www.exmaple.org/newsfeed" 
  accept="application/rss" />
Hypermedia Factors
CL
CR CU CM
LE LO LT LN LI

To tell the client to use certain header values?

Control data for update requests

CU

Support for modifying control data for update requests
(e. g. Content-* headers).

<form method="post" 
  action="http://www.example.org/my-keywords"  
  enctype="application/x-www-form-urlencoded" />
  <label>Keywords:</label>
  <input name="keywords" type="text" value="" />
  <input type="submit" />
</form>
Hypermedia Factors
CL
CR CU CM
LE LO LT LN LI

Perhaps triples such as this could be added:

<> hm:acceptsFormat <http://www.w3.org/ns/formats/Turtle> .

Control data for interface methods

CM

Support for indicating the interface method for requests
(e.g. HTTP GET,POST,PUT,DELETE methods).

<form method="post" action="http://www.example.org/my-keywords" />
  <label>Keywords:</label>
  <input name="keywords" type="text" value="" />
  <input type="submit" />
</form>
Hypermedia Factors
CL
CR CU CM
LE LO LT LN LI

Describe e.g. HTTP methods for the predicates:

hm:replaced   hm:httpMethod "PUT" .
hm:deleted    hm:httpMethod "DELETED" .
hm:mergedInto hm:httpMethod "POST" .

Control data for links

CL

Support for adding semantic meaning to link elements using
link relations (e.g. HTML rel attribute).

<entry xmlns="http://www.w3.org/2005/Atom">
  <title>Atom-Powered Robots Run Amok</title>
  <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
  <updated>2003-12-13T18:30:02Z</updated>
  <author><name>John Doe</name></author>
  <content>Some text.</content>
  <link rel="edit" href="http://example.org/edit/first-post.atom"/>
</entry>
Hypermedia Factors
CL
CR CU CM
LE LO LT LN LI

Every object property in RDF is control data for links

Summary of H Factors

Hypermedia Factors
CL
CR CU CM
LE LO LT LN LI

Is there more?

New H Factors

Self-description

Key strength of RDF.

<> void:inDataset [ void:vocabulary <http://purl.org/dc/terms/>, 
                                    <http://vocab/hypermedia#> . ] . 

And then e.g.:

hm:mergedInto rdfs:comment "Perform an RDF merge of payload into resource"@en ;
	      rdfs:seeAlso [ 
	        rdfs:label "RDF Merge" ;
	        rdfs:isDefinedBy <http://www.w3.org/TR/rdf-mt/#graphdefs> . 
              ] .

Very powerful hypermedia factor that is rather unique to RDF.

New H Factors (cont.)

Generate control data for other languages

E.g. RaUL.

Used to generate other hypermedia types

Bridging LOD and SPARQL

Band picture Band picture

From Wikipedia

But who is this?

person

To discover such things, you need either...

SPARQL must be a part of Linked Data

To make the data be effectively linked, someone who only has the URI of something must be able to find their way the SPARQL endpoint.

Tim Berners-Lee in the Linked Data Design Issue.

IOW, REST extends to linking SPARQL endpoints!

<> void:inDataset [ void:sparqlEndpoint </sparql> . ] .

Lets return to Knossos

Linked Data has a unique problem: References may come from many different sources!

Imagine a service description with:

<http://dbpedia.org/data/Knossos>  hm:canBe hm:replaced, hm:deleted .
<http://dbpedia.org/data/Phaistos> hm:canBe hm:replaced, hm:deleted .
[...]

Some triples need to be on every resource!

Question is: How many?

<> hm:canBe hm:mergedInto, hm:replaced, hm:deleted ;
   hm:createSimilarAt <../> ;
   hm:acceptsFormat <http://www.w3.org/ns/formats/Turtle> ;
   void:inDataset [ void:sparqlEndpoint </sparql> ;
                    void:vocabulary     <http://purl.org/dc/terms/> .
                  ] .
<> hm:canBe hm:mergedInto, hm:replaced, hm:deleted ;
   hm:createSimilarAt <../> ;
   void:inDataset </dataset-1>

We're down to 5 triples in most cases!

What's wrong with the SPARQL 1.1 Graph Store Spec?

Intention:

This document describes the use of HTTP operations for the purpose of managing a collection of RDF graphs in the REST architectural style.

Weaknesses of my proposal

Goals for the vocabulary

Acknowledgements

Questions

From the paper:

  1. Is a single service endpoint enough for Linked Data?
  2. Should the SPARQL 1.1 Graph Store HTTP Protocol be replaced by a vocabulary like the above?
  3. Can we create a better vocabulary for hypermedia RDF than the sketch above?

Additionally:

  1. Where does hypermedia RDF and APIs such as linked-data-api complement each other and where do they compete?

A REST API should not be tied to HTTP

Roy Fielding in blog post entitled: REST APIs must be hypertext-driven:

In general, any protocol element that uses a URI for identification must allow any URI scheme to be used for the sake of that identification.

In the case of Linked Data, HTTP may be the most practical.

Addressing unnamed default graph

_:service sd:defaultDataset [
        a sd:Dataset ;
        sd:defaultGraph _:graph ;
        sd:namedGraph [
            a sd:NamedGraph ;
            sd:name <http://www.example/named-graph> ;
            sd:graph _:graph .
        ]
    ] .

Gregory Todd Williams, private communication

URI structure

/rdf-graph-store?graph=http%3A//www.example.com/other/graph

A REST API must not define fixed resource names or hierarchies [...]. Servers must have the freedom to control their own namespace.

Roy Fielding

What methods do

Section 5 Graph Management Operations is all about the use of HTTP verbs.

Any effort spent describing what methods to use on what URIs of interest should be entirely defined within the scope of the processing rules for a media type

Roy Fielding

Overly academic language

Remember: Don't make developers look up the spec!

Intuitively, the set of interpretations that satisfy [RDF-MT] the RDF graph the RDF document serializes can be thought of as this RDF graph content.

This could have been implemented by several thousands...

What the present proposal doesn't address

In both cases, it needs to be defined in the processing rules of the MIME type.

How it addresses the rest

Comprehensive replacement of SPARQL 1.1 Graph Store, but with REST.