haudio-serialization: Difference between revisions

From Microformats Wiki
Jump to navigation Jump to search
(Created JSON for speech example)
(Added JSON Serialization example for Album w/ Song)
Line 152: Line 152:
   <span class="album">Underdog World Strike</span>
   <span class="album">Underdog World Strike</span>
</div>
</div>
</pre>
RDF-based JSON representation:
<pre>
{
  "_: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" }
      ]
  }
}
</pre>
Pure Microformat JSON representation:
<pre>
{
  "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" }
      ]
  }
}
</pre>
</pre>



Revision as of 03:57, 4 January 2008

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>

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>

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>