dret / I-D

Internet Drafts I've authored or contributed to.
17 stars 13 forks source link

Expand/tidy JSON-LD linkset section #129

Closed stain closed 4 years ago

stain commented 4 years ago

This should tidy up #119 so #89 is good to go - we could change the JSON top level linkset to _linkset or LinkSet to also allow linkset as a link relationship in JSON-LD mapping, but I guess that is a bit silly and too late to change now, so I added it as a caveat in the text instead.

Tagging @hvdsomp @csarven

Considerations

Below is a quick rendering of the new text (via xml2rpc)

Appendix B. JSON-LD Context

A linkset rendered according to the JSON serialization defined in Section 4.2 can be interpreted as RDF triples by adding a JSON-LD context [W3C.REC-json-ld-20140116], which map the JSON keys to corresponding Linked Data terms.

Below is a context that can map JSON linkset representations to Dublin Core Terms, with the link relations interpreted as properties with absolute URIs corresponding to [RFC8288] appendix A.2.

GET https://example.org/contexts/linkset.jsonld HTTP/1.1
Connection: close

HTTP/1.1 200 OK
Content-Type: application/ld+json
Content-Length: 773
{
  "@context": [
    {
      "@vocab":  "http://www.iana.org/assignments/relation/",
      "anchor":  "@id",
      "href":    "@id",
      "linkset": "@graph",
      "_linkset": "@graph",
      "title":   {
        "@id":    "http://purl.org/dc/terms/title"
      },
      "title*":  {
        "@id":    "http://purl.org/dc/terms/title"
      },
      "type":    {
        "@id":    "http://purl.org/dc/terms/format"
      }
    },
    {
      "language": "@language",
      "value":    "@value",
      "hreflang": {
        "@id":        "https://www.w3.org/ns/activitystreams#hreflang",
        "@container": "@set"
      }
    }
  ]
} 

Figure 7: JSON-LD Context mapping to schema.org and IANA assignments

HTTP servers can indicate that a JSON Linkset can be interpreted as RDF by providing a link to a JSON-LD context using the link relation http://www.w3.org/ns/json-ld#context according to [W3C.REC-json-ld-20140116] section 6.8 as shown below:

HTTP/1.1 200 OK
Date: Mon, 12 Aug 2019 10:48:22 GMT
Server: Apache-Coyote/1.1
Content-Type: application/linkset+json
Link: <https://example.org/contexts/linkset.jsonld>;
        rel="http://www.w3.org/ns/json-ld#context";
        type="application/ld+json"
Content-Length: 848
{
  "linkset": [
    {
      "anchor": "https://example.org/article/view/7507",
      "author": [
        {
          "href": "https://orcid.org/0000-0002-1825-0097"
        }
      ],
      "item": [
        {
          "href": "https://example.org/article/7507/item/1",
          "type": "application/pdf"
        },
        {
          "href": "https://example.org/article/7507/item/2",
          "type": "text/csv"
        }
      ],
      "cite-as": [
        {
          "href": "https://doi.org/10.5555/12345680",
          "title": "A Methodology for the Emulation of Architecture"
        }
      ]
    },
    {
      "anchor": "https://example.com/links/article/7507",
      "alternate": [
        {
          "href": "https://mirror.example.com/links/article/7507",
          "type": "application/linkset"
        }
      ]
    }
  ]
}

Figure 8: JSON-LD link relation

An application consuming Linkset JSON can apply their own context, either through a JSON-LD Processor or by merging the "@context" key into the Linkset JSON root object to transform the application/linkset+json document to a application/ld+json document. Below shows how a content-negotiation HTTP server could dynamically render linksets as RDF formats showing the interpreted triples from the above.

GET https://example.com/links/article/7507 HTTP/1.1
Accept: text/turtle
Connection: close

HTTP/1.1 200 OK
Date: Mon, 12 Aug 2019 10:49:22 GMT
Server: Apache-Coyote/1.1
Content-Type: text/turtle
Content-Length: 1164
<https://example.org/article/view/7507>
    <http://www.iana.org/assignments/relation/author>
    <https://orcid.org/0000-0002-1825-0097> .

<https://example.org/article/view/7507>
    <http://www.iana.org/assignments/relation/item>
    <https://example.org/article/7507/item/1> .

<https://example.org/article/7507/item/1>
    <http://purl.org/dc/terms/format>
    "application/pdf" .

<https://example.org/article/view/7507>
    <http://www.iana.org/assignments/relation/item>
    <https://example.org/article/7507/item/2> .

<https://example.org/article/7507/item/2>
    <http://purl.org/dc/terms/format>
    "text/csv" .

<https://example.org/article/view/7507>
    <http://www.iana.org/assignments/relation/cite-as>
    <https://doi.org/10.5555/12345680> .

<https://doi.org/10.5555/12345680>
    <http://purl.org/dc/terms/title>
    "A Methodology for the Emulation of Architecture" .

<https://example.com/links/article/7507>
    <http://www.iana.org/assignments/relation/alternate>
    <https://mirror.example.com/links/article/7507> .

<https://mirror.example.com/links/article/7507>
    <http://purl.org/dc/terms/format>
    "application/linkset" .

Figure 9: Triples returned by applying JSON-LD context

Note that the context in Figure 7 does not handle (meta)link relations of type "linkset" as they are in conflict with the top-level key. A workaround is to rename the top-level key to "_linkset" in the Linkset JSON before JSON-LD Processing.