haudio-serialization

From Microformats Wiki
Revision as of 05:11, 4 January 2008 by ManuSporny (talk | contribs) (Added JSON serialization for opera example)
Jump to navigation Jump to search

Introduction

This page contains ongoing research into serialization mechanisms for hAudio semantic objects. Note that this is not part of the hAudio specification, it is a developer note on how to properly serialize hAudio semantic objects across all semantic markup languages (Microformats, eRDF and RDFa). The goal is to allow easy inter-operation of applications that produce and consume hAudio semantic data. ManuSporny 19:37, 3 Jan 2008 (PST)

Why JSON?

JSON is a very simple object representation format that can be produced from and read by almost all programming languages. There are many JSON libraries available for all the popular languages including C, C++, Java, C#, PHP, Javascript, Perl, Python, and Ruby.

It is easy to produce, easy to read, terse, and human-readable.

Inspiration

The method of mapping the hAudio Microformat to RDF and back can be found on the Digital Bazaar hAudio Mapping page.

Much of the JSON RDF representation work was done by Keith Alexander, for more information on the thought process behind this representation format RDF-JSON Specification

JSON Serialization Examples

These examples show simple HTML, the Microformatted HTML, and the resulting JSON serialization.

Simple Song Example

Display:

Start Wearing Purple by Gogol Bordello

Microformatted XHTML:

<div class="haudio">
   <span class="fn">Start Wearing Purple</span> by 
   <span class="contributor">Gogol Bordello</span>
</div>

RDF-based JSON representation:

{
   "_:haudio1" : 
   {
      "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" : 
      [
         { "value" : "http://xmlns.com/haudio/1.0/Recording", "type" : "uri"}
      ],
      "http://purl.org/dc/elements/1.1/title" : 
      [
         { "value" : "Start Wearing Purple", "type" : "literal", "lang" : "en" }
      ],
      "http://purl.org/dc/elements/1.1/contributor" : 
      [
         { "value" : "Gogol Bordello", "type" : "literal", "lang" : "en" }
      ]
   }
}

Pure Microformat JSON representation:

{
   "haudio1": 
   {
      "fn" : 
      [
         { "value" : "Start Wearing Purple", "type" : "literal", "lang" : "en" }
      ],
      "contributor" : 
      [
         { "value" : "Gogol Bordello", "type" : "literal", "lang" : "en" }
      ]
   }
}

Speech Example

Display:

I Have a Dream, a speech by Martin Luther King Jr.

Microformatted XHTML:

	 
<div class="haudio">	 
   <span class="fn">I Have a Dream</span>, a 	 
   <span class="category">speech</span> by 	 
   <span class="contributor">Martin Luther King, Jr.</span>
</div>	 

RDF-based JSON representation:

{
   "_:haudio1" : 
   {
      "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" : 
      [
         { "value" : "http://xmlns.com/haudio/1.0/Recording", "type" : "uri"}
      ],
      "http://purl.org/dc/elements/1.1/title" : 
      [
         { "value" : "I Have a Dream", "type" : "literal", "lang" : "en" }
      ],
      "http://purl.org/dc/elements/1.1/type" : 
      [
         { "value" : "speech", "type" : "literal", "lang" : "en" }
      ],
      "http://purl.org/dc/elements/1.1/contributor" : 
      [
         { "value" : "Martin Luther King, Jr.", "type" : "literal", "lang" : "en" }
      ]
   }
}

Pure Microformat JSON representation:

{
   "haudio1": 
   {
      "fn" : 
      [
         { "value" : "I Have a Dream", "type" : "literal", "lang" : "en" }
      ],
      "category" : 
      [
         { "value" : "speech", "type" : "literal", "lang" : "en" }
      ],
      "contributor" : 
      [
         { "value" : "Martin Luther King, Jr.", "type" : "literal", "lang" : "en" }
      ]
   }
}

Song and Album Example

Display:

Start Wearing Purple by Gogol Bordello found on Underdog World Strike

Microformatted XHTML:

<div class="haudio">
   <span class="fn">Start Wearing Purple</span> by 
   <span class="contributor">Gogol Bordello</span>
   found on
   <span class="album">Underdog World Strike</span>
</div>

RDF-based JSON representation:

{
   "_:haudio1" :
   {
      "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" : 
      [
         { "value" : "http://xmlns.com/haudio/1.0/Album", "type" : "uri"}
      ],
      "http://purl.org/dc/elements/1.1/title" : 
      [
         { "value" : "Start Wearing Purple", "type" : "literal", "lang" : "en" }
      ],
      "http://purl.org/dc/elements/1.1/contributor" : 
      [
         { "value" : "Gogol Bordello", "type" : "literal", "lang" : "en" }
      ],
      "http://xmlns.com/hmedia/1.0/contains" : 
      [
         { "value" : "_:haudio2", "type" : "bnode" }
      ]
   },
   "_:haudio2" : 
   {
      "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" : 
      [
         { "value" : "http://xmlns.com/haudio/1.0/Recording", "type" : "uri"}
      ],
      "http://purl.org/dc/elements/1.1/title" : 
      [
         { "value" : "Start Wearing Purple", "type" : "literal", "lang" : "en" }
      ],
      "http://purl.org/dc/elements/1.1/contributor" : 
      [
         { "value" : "Gogol Bordello", "type" : "literal", "lang" : "en" }
      ]
   }
}

Pure Microformat JSON representation:

{
   "haudio1": 
   {
      "fn" : 
      [
         { "value" : "Start Wearing Purple", "type" : "literal", "lang" : "en" }
      ],
      "contributor" : 
      [
         { "value" : "Gogol Bordello", "type" : "literal", "lang" : "en" }
      ]
      "album" : 
      [
         { "value" : "Underdog World Strike", "type" : "literal", "lang" : "en" }
      ]
   }
}

Complete Album Example

An example that uses every element of hAudio:

[Image] Live Phish, Volume 15 by Phish
Released: October 31, 2002
Acquire: Sample, Live Recording, Buy High Quality Track
Category: live
Duration: 145 minutes, 27 seconds
Price: $14.99

Tracks:
1. Sanity (5:48)
2. Highway To Hell (3:39)

Here is the hAudio Microformat markup:

<div class="haudio">
   <img class="photo" src="images/live_phish_vol_15.jpg" alt="" />
   <span class="album">Live Phish, Volume 15</span>
   <span class="contributor">
      <span class="vcard">
         <span class="fn org">Phish</span>
      </span>
   </span>
   <br/>
   Released on:
   <abbr class="published" title="2002-10-31">October 31, 2002</abbr>
   <br/>
   Acquire: 
   <a rel="sample" href="/samples/live_phish_vol_15_sample.mp3">Sample</a>, 
   <a rel="enclosure" href="/live/phish_live_phish_vol_15.mp3">Live Recording</a>,
   <a rel="payment" href="/buy/phish_live_phish_vol_15">Buy High Quality Track</a>
   Category: <a class="category" rel="tag" href="http://www.example.org/tags/live">live</a>
   Duration: <abbr class="duration" title="PT145M27S">145 minutes, 27 seconds</abbr>
   Price: <div class="price"><abbr class="currency" title="USD 14.99">$14.99</abbr></div>
   Tracks:
   <div class="item">
      <span class="position">1</span>.
      <span class="fn">Sanity</span>
      (<abbr class="duration" title="PT5M48S">5:48</abbr>)
    </div>
    <div class="item">
     <span class="position">2</span>.
     <span class="fn">Highway To Hell</span> 
     (<abbr class="duration" title="PT3M39S">3:39</abbr>)
  </div>
</div>

RDF-based JSON representation:

{
   "_:haudio1" :
   {
      "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" : 
      [
         { "value" : "http://xmlns.com/haudio/1.0/Album", "type" : "uri"}
      ],
      "http://xmlns.com/hmedia/1.0/depiction" : 
      [
         { "value" : "http://www.example.org/images/live_phish_vol_15.jpg", "type" : "uri" }
      ],
      "http://purl.org/dc/elements/1.1/title" : 
      [
         { "value" : "Live Phish, Volume 15", "type" : "literal", "lang" : "en" }
      ],
      "http://purl.org/dc/elements/1.1/contributor" : 
      [
         { "value" : "_:vcard1", "type" : "bnode"}
      ],
      "http://purl.org/dc/elements/1.1/date" : 
      [
         { "value" : "2002-10-31", "type" : "http://www.w3.org/2001/XMLSchema#date", "lang" : "en" }
      ],
      "http://xmlns.com/hmedia/1.0/sample" : 
      [
         { "value" : "http://www.example.org/samples/live_phish_vol_15_sample.mp3", "type" : "uri" }
      ],
      "http://xmlns.com/hmedia/1.0/download" : 
      [
         { "value" : "http://www.example.org/live/phish_live_phish_vol_15.mp3", "type" : "uri" }
      ],
      "http://xmlns.com/commerce/1.0/payment" : 
      [
         { "value" : "http://www.example.org/buy/phish_live_phish_vol_15", "type" : "uri" }
      ],
      "http://purl.org/dc/elements/1.1/type" : 
      [
         { "value" : "live", "type" : "literal", "lang" : "en" }
      ],
      "http://xmlns.com/hmedia/1.0/duration" : 
      [
         { "value" : "PT145M27S", "type" : "literal", "lang" : "en" }
      ],
      "http://xmlns.com/commerce/1.0/price" : 
      [
         { "value" : "USD 14.99", "type" : "literal", "lang" : "en" }
      ],
      "http://xmlns.com/hmedia/1.0/contains" : 
      [
         { "value" : "_:haudio2", "type" : "bnode" }
      ],
      "http://xmlns.com/hmedia/1.0/contains" : 
      [
         { "value" : "_:haudio3", "type" : "bnode" }
      ]
   },
   "_:vcard1" :
   {
      "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" : 
      [ 
         { "value" : "http://www.w3.org/2001/vcard-rdf/3.0", "type" : "uri"}
      ],
      "http://www.w3.org/2001/vcard-rdf/3.0#FN" : 
      [
         { "value" : "Phish", "type" : "literal", "lang" : "en" }
      ],
      "http://www.w3.org/2001/vcard-rdf/3.0#ORG" : 
      [
         { "value" : "Phish", "type" : "literal", "lang" : "en" }
      ],

   },
   "_:haudio2" : 
   {
      "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" : 
      [
         { "value" : "http://xmlns.com/haudio/1.0/Recording", "type" : "uri"}
      ],
      "http://xmlns.com/hmedia/1.0/position" : 
      [
         { "value" : "1", "type" : "literal", "lang" : "en" }
      ],
      "http://purl.org/dc/elements/1.1/title" : 
      [
         { "value" : "Sanity", "type" : "literal", "lang" : "en" }
      ],
      "http://xmlns.com/hmedia/1.0/duration" : 
      [
         { "value" : "PT5M48S", "type" : "literal", "lang" : "en" }
      ],
   },
   "_:haudio3" : 
   {
      "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" : 
      [
         { "value" : "http://xmlns.com/haudio/1.0/Recording", "type" : "uri"}
      ],
      "http://xmlns.com/hmedia/1.0/position" : 
      [
         { "value" : "2", "type" : "literal", "lang" : "en" }
      ],
      "http://purl.org/dc/elements/1.1/title" : 
      [
         { "value" : "Highway to Hell", "type" : "literal", "lang" : "en" }
      ],
      "http://xmlns.com/hmedia/1.0/duration" : 
      [
         { "value" : "PT3M39S", "type" : "literal", "lang" : "en" }
      ],
   }
}

Pure Microformat JSON representation:

{
   "haudio1" :
   {
      "photo" : 
      [
         { "value" : "http://www.example.org/images/live_phish_vol_15.jpg", "type" : "uri" }
      ],
      "fn" : 
      [
         { "value" : "Live Phish, Volume 15", "type" : "literal", "lang" : "en" }
      ],
      "contributor" : 
      [
         { 
            "vcard1" :
            {
               "fn" : 
               [
                  { "value" : "Phish", "type" : "literal", "lang" : "en" }
               ],
               "org" : 
               [
                  { "value" : "Phish", "type" : "literal", "lang" : "en" }
               ]
            }
         }
      ],
      "published" : 
      [
         { "value" : "2002-10-31", "type" : "literal", "lang" : "en" }
      ],
      "sample" : 
      [
         { "value" : "http://www.example.org/samples/live_phish_vol_15_sample.mp3", "type" : "uri" }
      ],
      "enclosure" : 
      [
         { "value" : "http://www.example.org/live/phish_live_phish_vol_15.mp3", "type" : "uri" }
      ],
      "payment" : 
      [
         { "value" : "http://www.example.org/buy/phish_live_phish_vol_15", "type" : "uri" }
      ],
      "category" : 
      [
         { "value" : "live", "type" : "literal", "lang" : "en" }
      ],
      "duration" : 
      [
         { "value" : "PT145M27S", "type" : "literal", "lang" : "en" }
      ],
      "price" : 
      [
         { "value" : "USD 14.99", "type" : "literal", "lang" : "en" }
      ],
      "item" : 
      [
         {
            "position" : 
            [
               { "value" : "1", "type" : "literal", "lang" : "en" }
            ],
            "fn" : 
            [
               { "value" : "Sanity", "type" : "literal", "lang" : "en" }
            ],
            "duration" : 
            [
               { "value" : "PT5M48S", "type" : "literal", "lang" : "en" }
            ],
         },
         {
            "position" : 
            [
               { "value" : "2", "type" : "literal", "lang" : "en" }
            ],
            "fn" : 
            [
               { "value" : "Highway to Hell", "type" : "literal", "lang" : "en" }
            ],
            "duration" : 
            [
               { "value" : "PT3M39S", "type" : "literal", "lang" : "en" }
            ],
         }
      ]
   }
}

Multi-part Podcast Example

DigitalPlanet Podcast: 29 Oct 07

Forensic computing: is it really possible to delete data from your machine? Grand plans for getting broadband into Africa, checking out the sky at night via the internet and answering your emails to the programme.

Download MP3

<div class="haudio">
<p>
   <span class="fn">DigitalPlanet Podcast</span>
   :
   <abbr class="published" title="20071029">29 Oct 07</abbr>
</p>
<p>
   <div class="item">
      <span class="fn">Forensic computing: is it really possible to delete data from your machine?</span>
   </div>
   <div class="item">
      <span class="fn">Grand plans for getting broadband into Africa</span>
   </div>
   , 
   <div class="item">
      <span class="fn">checking out the sky at night via the internet</span>
   </div> 
   and 
   <div class="item">
      <span class="fn">answering your emails</span>
   </div>
   to the programme.
</p>
<p>
   <a rel="enclosure" href="/download/episode/DigitalPlanet-2007-10-29">Download MP3</a>
</p>
</div>
{
   "_:haudio1" :
   {
      "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" : 
      [
         { "value" : "http://xmlns.com/haudio/1.0/Recording", "type" : "uri"}
      ],
      "http://purl.org/dc/elements/1.1/title" : 
      [
         { "value" : "DigitalPlanet Podcast", "type" : "literal", "lang" : "en" }
      ],
      "http://purl.org/dc/elements/1.1/date" : 
      [
         { "value" : "2002-10-31", "type" : "http://www.w3.org/2001/XMLSchema#date", "lang" : "en" }
      ],
      "http://xmlns.com/hmedia/1.0/download" : 
      [
         { "value" : "http://www.example.org/download/episode/DigitalPlanet-2007-10-29", "type" : "uri" }
      ],
      "http://xmlns.com/hmedia/1.0/contains" : 
      [
         { "value" : "_:haudio2", "type" : "bnode" }
      ],
      "http://xmlns.com/hmedia/1.0/contains" : 
      [
         { "value" : "_:haudio3", "type" : "bnode" }
      ],
      "http://xmlns.com/hmedia/1.0/contains" : 
      [
         { "value" : "_:haudio4", "type" : "bnode" }
      ],
      "http://xmlns.com/hmedia/1.0/contains" : 
      [
         { "value" : "_:haudio5", "type" : "bnode" }
      ]
   },
   "_:haudio2" : 
   {
      "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" : 
      [
         { "value" : "http://xmlns.com/haudio/1.0/Recording", "type" : "uri"}
      ],
      "http://purl.org/dc/elements/1.1/title" : 
      [
         { "value" : "Forensic computing: is it really possible to delete data from your machine?", "type" : "literal", "lang" : "en" }
      ],
   },
   "_:haudio3" : 
   {
      "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" : 
      [
         { "value" : "http://xmlns.com/haudio/1.0/Recording", "type" : "uri"}
      ],
      "http://purl.org/dc/elements/1.1/title" : 
      [
         { "value" : "Grand plans for getting broadband into Africa", "type" : "literal", "lang" : "en" }
      ],
   },
   "_:haudio4" : 
   {
      "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" : 
      [
         { "value" : "http://xmlns.com/haudio/1.0/Recording", "type" : "uri"}
      ],
      "http://purl.org/dc/elements/1.1/title" : 
      [
         { "value" : "checking out the sky at night via the internet", "type" : "literal", "lang" : "en" }
      ],
   },
   "_:haudio5" : 
   {
      "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" : 
      [
         { "value" : "http://xmlns.com/haudio/1.0/Recording", "type" : "uri"}
      ],
      "http://purl.org/dc/elements/1.1/title" : 
      [
         { "value" : "answering your emails", "type" : "literal", "lang" : "en" }
      ]
   }
}

Pure Microformat JSON representation:

{
   "haudio1" :
   {
      "fn" : 
      [
         { "value" : "DigitalPlanet Podcast", "type" : "literal", "lang" : "en" }
      ],
      "published" : 
      [
         { "value" : "2002-10-31", "type" : "http://www.w3.org/2001/XMLSchema#date", "lang" : "en" }
      ],
      "enclosure" : 
      [
         { "value" : "http://www.example.org/download/episode/DigitalPlanet-2007-10-29", "type" : "uri" }
      ],
      "item" : 
      [
         {
            "fn" : 
            [
               { "value" : "Forensic computing: is it really possible to delete data from your machine?", "type" : "literal", "lang" : "en" }
            ],
         },
         {
            "fn" : 
            [
               { "value" : "Grand plans for getting broadband into Africa", "type" : "literal", "lang" : "en" }
            ],
         },
         {
            "fn" : 
            [
               { "value" : "checking out the sky at night via the internet", "type" : "literal", "lang" : "en" }
            ],
         },
         {
            "fn" : 
            [
               { "value" : "answering your emails", "type" : "literal", "lang" : "en" }
            ]
         }
      ]
   },
}

Opera Example

La Bohème is an opera in four acts by Giacomo Puccini to an Italian libretto by Luigi Illica and Giuseppe Giacosais. I saw it performed last week and found Act III to be pretty interesting, especially the "Sa dirmi, scusi" and "O buon Marcello, aiuto!" arias.

<div class="haudio" lang="en">
   <span class="fn" lang="it">La Bohème</span> 
   is an 
   <span class="category">opera</span> 
   in four acts by 
   <span class="contributor" lang="it">Giacomo Puccini</span>
   to an 
   <span class="category">Italian liberetto</span>
   by
   <span class="contributor" lang="it">Luigi Illica</span>
   and
   <span class="contributor" lang="it">Giuseppe Giacosais</span>.
   I saw it performed last week and found
   <div class="item">
      <span class="fn">Act III</span>
       to be pretty interesting, especially the
      <div class="item">
         "<span class="fn" lang="it">Sa dirmi, scusi</span>"
      </div>
      and
      <div class="item">
         "<span class="fn" lang="it">O buon Marcello, aiuto!</span>"
      </div>
      arias.
   </div>
</div>

RDF-based JSON representation:

{
   "_:haudio1" :
   {
      "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" : 
      [
         { "value" : "http://xmlns.com/haudio/1.0/Recording", "type" : "uri"}
      ],
      "http://purl.org/dc/elements/1.1/title" : 
      [
         { "value" : "La Bohème", "type" : "literal", "lang" : "it" }
      ],
      "http://purl.org/dc/elements/1.1/contributor" : 
      [
         { "value" : "Giacomo Puccini", "type" : "literal", "lang" : "it" },
         { "value" : "Luigi Illica", "type" : "literal", "lang" : "it" },
         { "value" : "Giuseppe Giacosais", "type" : "literal", "lang" : "it" }
      ],
      "http://purl.org/dc/elements/1.1/type" : 
      [
         { "value" : "opera", "type" : "literal", "lang" : "en" },
         { "value" : "Italian liberetto", "type" : "literal", "lang" : "en" }
      ],
      "http://xmlns.com/hmedia/1.0/contains" : 
      [
         { "value" : "_:haudio2", "type" : "bnode" }
      ]
   },
   "_:haudio2" : 
   {
      "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" : 
      [
         { "value" : "http://xmlns.com/haudio/1.0/Recording", "type" : "uri"}
      ],
      "http://purl.org/dc/elements/1.1/title" : 
      [
         { "value" : "Act III", "type" : "literal", "lang" : "en" }
      ],
      "http://xmlns.com/hmedia/1.0/contains" : 
      [
         { "value" : "_:haudio3", "type" : "bnode" },
      ]
      "http://xmlns.com/hmedia/1.0/contains" : 
      [
         { "value" : "_:haudio4", "type" : "bnode" }
      ]
   },
   "_:haudio3" : 
   {
      "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" : 
      [
         { "value" : "http://xmlns.com/haudio/1.0/Recording", "type" : "uri"}
      ],
      "http://purl.org/dc/elements/1.1/title" : 
      [
         { "value" : "Sa dirmi, scusi", "type" : "literal", "lang" : "it" }
      ]
   }
   "_:haudio4" : 
   {
      "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" : 
      [
         { "value" : "http://xmlns.com/haudio/1.0/Recording", "type" : "uri"}
      ],
      "http://purl.org/dc/elements/1.1/title" : 
      [
         { "value" : "O buon Marcello, aiuto!", "type" : "literal", "lang" : "it" }
      ]
   }
}

Pure Microformat JSON representation:

{
   "haudio1" :
   {
      "fn" : 
      [
         { "value" : "La Bohème", "type" : "literal", "lang" : "it" }
      ],
      "contributor" : 
      [
         { "value" : "Giacomo Puccini", "type" : "literal", "lang" : "it" },
         { "value" : "Luigi Illica", "type" : "literal", "lang" : "it" },
         { "value" : "Giuseppe Giacosais", "type" : "literal", "lang" : "it" }
      ],
      "category" : 
      [
         { "value" : "opera", "type" : "literal", "lang" : "en" },
         { "value" : "Italian liberetto", "type" : "literal", "lang" : "en" }
      ],
      "item" : 
      [
         {
            "fn" : 
            [
               { "value" : "Act III", "type" : "literal", "lang" : "en" }
            ],
            "item" : 
            [
               {
                  "fn" : 
                  [
                     { "value" : "Sa dirmi, scusi", "type" : "literal", "lang" : "it" }
                  ]
               },
               {
                  "fn" : 
                  [
                     { "value" : "O buon Marcello, aiuto!", "type" : "literal", "lang" : "it" }
                  ]
               }
            ]
         }
      ]
   }
}