Re: hydra:returns for operations returning collections of class instances

On Wed, Jun 18, 2014 at 2:21 PM, Markus Lanthaler
<markus.lanthaler@gmx.net> wrote:
> That's a good question. The "main entity" that is returned is a collection but the thing the client is probably interested in are the instances of :Class. I'd say the best thing would be to be more explicit, i.e., expressing that it returns a Collection of :Class instances. This would be quite trivial to describe with OWL (property restriction on member).

If you hint to use OWL in this case, do you mean something like the following?

In Turtle:

@prefix : <http://api.example.com/> .
@prefix hydra: <http://www.w3.org/ns/hydra/core#"> .
@prefix owl: <http://www.w3.org/2002/07/owl#"> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

:class-collection rdfs:subClassOf hydra:Collection,
  [
    a owl:Restriction ;
    owl:onProperty hydra:member ;
    owl:allValuesFrom :Class
  ] .

Or, in JSON-LD:

{
  "@context" : {
    "@base" : "http://api.example.com/",
    "hydra" : "http://www.w3.org/ns/hydra/core#",
    "owl" : "http://www.w3.org/2002/07/owl#",
    "rdfs" : "http://www.w3.org/2000/01/rdf-schema#",

    "owl:onProperty" : {"@type" : "@id"},
    "owl:allValuesFrom" : {"@type" : "@id"},
    "rdfs:subClassOf" : {"@type" : "@id"}
  },
  "@id" : "class-collection",
  "rdfs:subClassOf" : [
    "hydra:Collection",
    {
      "@type" : "owl:Restriction",
      "owl:onProperty" : "hydra:member",
      "owl:allValuesFrom" : "Class"
    }
  ]
}

I think there may be some minor issues with this design.

Wouldn't this design lead to proliferation of "collection classes" for
many popular classes? I can imagine that if this was recommended
practice, then we could see several classes of collections of
schema:Person or schema:Product etc.

The description is in OWL (albeit in a simple subset) and there might
be few clients and developers, who create these clients, that read
OWL. If the main goal is to support a machine-readable API
description, which is also readable to most web developers, and
reasoning support isn't required, then OWL might not be the best way
how to achieve this goal.

This design doesn't help solving the ISSUE #41 (a.k.a. collections
breaking relationships), which I think is very much related, so a
solution to this issue should be aligned with the solution to ISSUE
#41.

- Jindřich

-- 
Jindřich Mynarz
http://mynarz.net/#jindrich

Received on Wednesday, 18 June 2014 16:16:46 UTC