Semantic Hybridization: Mixing RDFa and JSON-LD

February 14th, 2015

R. Alexander Miłowski

alex@milowski.com

School of Information, UC Berkeley

JSON-LD 💘 or 💔 RDFa?

It's a love story of two soul-formats for semantics:

Can't we just all get along?

Yes, we can and so can they...

I'm here to be their relationship counselor for the day.

A simple problem

Encoding a person's contact information on the Web using schema.org:

Alex Miłowski
alex@milowski.com
http://www.milowski.com/

School of Information
University of California, Berkeley
http://www.ischool.berkeley.edu/             
          
@prefix s: <http://schema.org/>
<http://www.milowski.com/#alex> a s:Person ;
  s:name         "Alex Miłowski";
  s:email        "alex@milowski.com";
  s:url          "http://www.milowski.com/";
  s:organization <_:1> .
<_:1> a        s:Organization ;
  s:name       "University of California, Berkeley" ;
  s:department <_:2> .
<_:2> a s:Organization ;
  s:name "School of Information" ;
  s:url  "http://www.ischool.berkeley.edu/" .             
          

💘 RDFa?

RDFa likes to collaborate with others.
<div vocab="http://schema.org/" 
     resource="http://www.milowski.com/#alex" 
     typeof="Person">
<p><a property="url" href="http://www.milowski.com/">
      <span resource="http://www.milowski.com/#alex" 
            property="name">Alex Miłowski</span>
   </a>; 
   <a property="email" href="mailto:alex@milowski.com" 
      content="alex@milowski.com">(personal e-mail)</a>;
</p>
<p property="organization" typeof="Organization">
  <span property="department" typeof="Organization">
    <span property="name">School of Information</span>
    <a property="url" 
       href="http://www.ischool.berkeley.edu/">(website)</a>
  </span>; 
  <span property="name">
      University of California, Berkeley</span>
</p>
</div>                
             

💘 JSON-LD?

JSON-LD has a hard time relating.
{
  "@context": "http://schema.org/",
  "@type" : "Person",
  "@id"   : "http://www.milowski.com/#alex",
  "name"  : "Alex Miłowski",
  "email" : "alex@milowski.com",
  "url"   : "http://www.milowski.com",
  "organization" : {
     "@type" : "Organization",
     "name"  : "University of California, Berkeley",
     "department" : {
        "@type" : "Organization",
        "name" : "School of Information",
        "url"  : "http://www.ischool.berkeley.edu/"
    }
  }
}             
          

💘 Soul-formats

RDFa and JSON-LD almost seem made to compliment each other.

Using the right representation

The excellence of grammar as a guide is proportional to the paucity of the inflexions, i.e. to the degree of analysis effected by the language considered. — Bertrand Russell
(in a footnote of Principles of Mathematics)

Some of you have seen this from me for years ...

Our choice of syntax and format affects how we organize information.

By using the right representation we don't force information into to do unnatural acts.

Use the right format for the information being represented.

Strategy for Reuniting JSON-LD and RDFa

  1. Identify resources in hypertext (HTML) using RDFa.
  2. Annotate information in markup without unnecessary intrusions.
  3. Augment information using JSON-LD avoiding duplication.
  4. Represent the remaining information with JSON-LD.

An example of RDFa/JSON-LD love

<p vocab="http://schema.org/">

<span resource="http://www.milowski.com/#alex" 
         typeof="Person">
  <span property="name">Alex Miłowski</span>
</span>

works at 
<span resource="http://www.berkeley.edu/" 
      typeof="Organization">
  <span property="name">
     University of California, Berkeley</span>'s
  <span resource="http://www.ischool.berkeley.edu/" 
        typeof="Organization" 
        property="department">
    <span property="name">School of Information</span>
  </span>
</span>

</p>             
          
<script type="application/ld+json">
{
  "@context" : "http://schema.org/",
  "@id" : "http://www.milowski.com/#alex",
  "givenName" : "Raymond",
  "otherName" : "Alexander",
  "familyName" : "Miłowski",
  "email" : "alex@milowski.com",
  "url" : "http://www.milowski.com/",
  "organization" : { 
     "@id": "http://www.berkeley.edu/" 
   }
}
</script>
          

A Demonstration

We'll use RDFa and JSON-LD to simplify expression of information about media (photographs).

Step #1 — Elegance in RDFa

We encode a gallery of images, annotating each type and resource with RDFa...

<div typeof="ImageGallery" vocab="http://schema.org/">
  <img typeof="Photograph" src="10153548161924517.jpg"/>
  <img typeof="Photograph" src="10153548161944517.jpg"/>
  ...
</div>
          

Step #2 — Linking to the JSON-LD

Link to additional information in JSON-LD:

<script type="application/ld+json" src="10153548161924517.json"></script>
<script type="application/ld+json" src="10153548161944517.json"></script>
...
          

Step #3 — Add detail with JSON-LD

{
  "@context" : "http://schema.org/",
  "@id" : "10153548161924517.jpg",
  "@type" : "Photograph",
  "dateCreated" : "2015-01-18T14::25:29-08:00",
  "description" : "A crane at China Camp",
  "contentLocation" : {
     "@type" : "Place",
     "geo" : { "@type" : "GeoCoordinates", "latitude" : 38.009463888889, "longitude" : -122.49190555556 }
   },
   "comment" : {
       "text" : "A crane!",
       "x" : 230, "y": 260,
       "width": 25, "height": 25
   }
}             
          

The Working Demo (source)

Together Again

RDFa 💘 JSON-LD

(with some help from HTML)