Reconciling hydra rest semantics for collections with typical RDF entity relationships

Excuse me for some random thoughts, but I've been reconciling using Hydra for an API which typically returns JSON-LD representations of entities described using schema.org. Similar issues may exist with the schema.org action vocabulary as well. As a simple example, I may want to express follows information for a Person. In Turtle, this might look like the following:

<http://example/people/gregg> a schema:Person;
  schema:name "Gregg Kellogg"@en;
  schema:follows <http://example/people/markus>, <http://example/people/kingsley> ...

However, given that the list of potentially people I follow could be large; using Hydra I may construct this using a separate relationship to a Collection:

<http://example/people/gregg> a schema:Person, :ApiPerson;
  :follows <http://example/people/gregg/follows> .

:ApiPerson a hydra:Class;
  hydra:supportedProperties [hydra:property schema:name], [hydra:property :follows] .

:follows a hydra:Link
    rdfs:label "follows";
    rdfs:comment "Collection of followed people";
    rdfs:domain schema:Person;
    rdfs:range schema:Person;
    hydra:supportedOperations [
      hydra:method "GET";
      hydra:returns hydra:Collection
  ] .

If the referenced collection contained the following data:

<http://example/people/gregg/follows> a hydra:Collection;
  hydra:members (<http://example/people/markus> <http://example/kingsley> .

After loading both the original document and the collection into a graph, I would now have the following:

<http://example/people/gregg> a schema:Person, :ApiPerson;
  :follows <http://example/people/gregg/follows> .
<http://example/people/gregg/follows> a hydra:Collection;
  hydra:members (<http://example/people/markus> <http://example/kingsley> .

This now does not describe what I would want using the schema.org definitions. One way to reconstruct what I want would be to add more data to the collection document:

<http://example/people/gregg/follows> a hydra:Collection;
  hydra:members (<http://example/people/markus> <http://example/kingsley> .
<http://example/people/gregg> schema:follows <http://example/people/markus>, <http://example/people/kingsley> .

This is actually easier to do in JSON-LD:

{
  "@context": {
    "hydra": "http://www.w3.org/ns/hydra/core#",
    "schema": "http://schema.org/",
    "follower": {"@reverse": "schema:follows"}
  }
  "@id": "http://example/people/gregg/follows",
  "@type": "hydra:Collection",
  "members": [
    { "@id": "http://example/people/markus", "follower": "http://example/people/gregg"},
    { "@id": "http://example/people/kingsley", "follower": "http://example/people/gregg"}
  ]
}

The issue is better for single-valued properties, as the property value would be the same as the entity identifier, which would result in what you would expect when merging both entity definitions.

I guess the question is, is this an expected usage pattern? Should the collection examples represent this, or should it be described as a recommended practice? Perhaps I've missed something.

Gregg Kellogg
gregg@greggkellogg.net

Received on Monday, 3 February 2014 22:24:55 UTC