RDF for the (Non-Semantic) Web

Victor Charpenay

Outline

  1. How Useful is RDF To Web Developers?
  2. JSON for Linked Data
  3. Schema.org
  4. Adoption on the (Non-Semantic) Web

How Useful is RDF To Web Developers?

Despite its original XML syntax, the RDF data model is not aligned with existing Web formats: HTML (XML), JSON.

A revision of the RDF/XML syntax was designed to appeal to Web developers.

It didn't.

One possible reason for this lack of adoption is the lack of idiomatic representations of RDF data in object-oriented programming languages.

The gap between objects and triples is "too wide"...

...despite numerous object-triple mapping libraries (Ledvinka, 2018)

In addition, Web developers typically build "full-stack" applications, including a front-end, a back-end and communication between the two.

They don't particularly need to expose data in an interoperable way (i.e. with URIs everywhere).

But full-stack Web applications are not the only kind of Web app.

On the Linked Open Data (LOD) cloud, the effort is split:

  • Web servers provide raw data
    of quality
  • The Web browser renders facets of data
    of interest to the user
"The next web", by Tim Berners-Lee (2009); source: TED

RDF can help redistribute the effort between client and server applications on the Web.

Two technologies (among others) tend towards that objective:

  • JSON-LD
  • Schema.org

JSON for Linked Data

JSON: JavaScript Object Notation

JSON values can be objects, arrays or simple values.

Type Example
Null null
Boolean true, false
Number 2.4
String "abc"
Object { "a": 2.4, "b": "abc", ... }
Array [ 2.4, "abc", ... ]
Six JSON types

"That’s it. That is all of JSON." — Douglas Crockford (Crockford, 2008)

Objects (in Java, Python, C#, etc.) can easily be (de)serialized in JSON.

RDF-based applications often require a transformation from/to objects.

Can there be a standard JSON serialization of RDF?

@Namespaces({
  "frbr", "http://vocab.org/frbr/core#",
  "dc",   "http://purl.org/dc/terms/",
  "foaf", "http://xmlns.com/foaf/0.1/"
})
@RdfsClass("frbr:Expression")
@Entity
public class Book implements SupportsRdfId {

  @RdfProperty("dc:title")
  private String mTitle;

  @RdfProperty("dc:publisher")
  private String mPublisher;

  @RdfProperty("dc:issued")
  private Date mIssued;

  @RdfProperty("foaf:primarySubjectOf")
  private URI mPrimarySubjectOf;

  @OneToMany(fetch = FetchType.LAZY,
             cascade = { CascadeType.PERSIST, CascadeType.MERGE })
  @RdfProperty("frbr:embodiment")
  private Collection<Manifestation> mEmbodiments = new HashSet<Manifestation>();

  // ...
}
Example of a Book class with object-triple mapping, from the Empire library (Java); source: Github.com
{
  "@context": {
    "frbr": "http://vocab.org/frbr/core#",
    "dc":   "http://purl.org/dc/terms/",
    "foaf": "http://xmlns.com/foaf/0.1/",
    "mTitle": "dc:title",
    "mPublisher": "dc:publisher",
    "mIssued": {
      "@id": "dc:issued",
	  "@type": "http://www.w3.org/2001/XMLSchema#date"
	}, "mPrimarySubjectOf": {
      "@id": "foaf:primarySubjectOf",
      "@type": "@id"
	}, "mEmbodiments": {
      "@id": "frbr:embodiment",
      "@container": "@set"
    }
  },
  "@id": "http://www.wikidata.org/entity/Q13912",
  "@class": "frbr:Expression",
  "mTitle": "Where the Wild Things Are",
  "mPublisher": "Harper & Raw",
  "mIssued": "1963-11-13",
  "mPrimarySubjectOf": "https://en.wikipedia.org/wiki/Where_the_Wild_Things_Are",
  "mEmbodiments": [
    ...
  ]
}
JSON-LD representation of a Book object.

JSON-LD: JSON for Linked Data

A JSON-LD document has (at least) two forms:

  • a compacted form
  • an expanded form

Try the JSON-LD Playground to process all forms of JSON-LD.

[
  {
    "@id": "http://www.wikidata.org/entity/Q13912",
    "http://purl.org/dc/terms/title": [
      {
        "@value": "Where the Wild Things Are"
      }
    ],
    "http://purl.org/dc/terms/publisher": [
      {
        "@value": "Harper & Raw"
      }
    ],
    "http://purl.org/dc/terms/issued": [
      {
        "@value": "1963-11-13",
        "@type": "http://www.w3.org/2001/XMLSchema#date"
      }
    ],
    "http://xmlns.com/foaf/0.1/primarySubjectOf": [
      {
        "@id": "https://en.wikipedia.org/wiki/Where_the_Wild_Things_Are"
      }
    ],
    "http://vocab.org/frbr/core#embodiment": [ ... ],
  }
  ]
JSON-LD expanded representation of a Book object.

A JSON-LD object can be:

  • a node object (with key @id)
    ~ IRI resource or blank node
  • a value object (with key @value)
    ~ literal

In its compacted form, a JSON-LD document has a context (with key @context).

A JSON-LD context maps arbitrary JSON strings to IRIs.

A JSON-LD context includes several kinds of definitions.

See section 6 "Advanced concepts" of the JSON-LD W3C specification.

Compact IRIs: instead of full IRIs, JSON object keys can map to IRIs compacted with a declared prefix.

{
  "@context": {
    "dc":   "http://purl.org/dc/terms/",
    "mTitle": "dc:title",
    "mPublisher": "dc:publisher"
  }
}

Typed Values: a default datatype range can be given to JSON object keys.

{
  "@context": {
    "dc": "http://purl.org/dc/terms/",
    "mIssued": {
      "@id": "dc:issued",
      "@type": "http://www.w3.org/2001/XMLSchema#date"
    }
  }
}

Type Coercion: a JSON string can map to a string literal or to an IRI.

{
  "@context": {
    "foaf": "http://xmlns.com/foaf/0.1/",
    "mPrimarySubjectOf": {
      "@id": "foaf:primarySubjectOf",
      "@type": "@id"
    }
  }
}

Sets and Lists: JSON arrays can map to unordered sets of triples or to RDF lists.

{
  "@context": {
    "frbr": "http://vocab.org/frbr/core#",
    "mEmbodiments": {
      "@id": "frbr:embodiment",
      "@container": "@set"
    }
}

Schema.org

Schema.org is a collection of RDF classes and properties to describe entities typically described in Web pages.

Schema.org also provides a default JSON-LD context for Web developers to use.

"From String to Things", by Markus Lanthaler; source Slideshare

JSON-LD data can be embedded in any Web page...

...including this one. To embed data:

  1. open HTML source
  2. add a <script> element
  3. give attribute "type"="application/ld+json"

Schema.org annotations are everywhere on the Web.

E.g. on Rotten Tomatoes.

But not on Google or Amazon websites.

Web developers have tools for testing their schema.org annotations:

Other Web annotations framework have got lesser attention but pursue the same goal:

Adoption on the (Non-Semantic) Web

JSON-LD, Schema.org and, to a lesser extent, RDFa and Microdata are present in:

HTTP Archive's dataset is based on user browsing habits whereas Web Data Commons is based on pure hypermedia navigation, hence some discrepancy between the two.