info343/lectures/semantic-web-metadata-microformats/index.shtml

<!--#include virtual="../s5/commontop.html" -->
      <title>Lecture 18: The Semantic Web — INFO 343 Autumn 2012</title>
   </head>

   <body>
      <div class="layout">
         <div id="controls"><!-- DO NOT EDIT --></div>
         <div id="currentSlide"><!-- DO NOT EDIT --></div>
         <div id="header"></div>
         <div id="footer">
            <h1>INFO 343 Lecture 18</h1>
            <h2>The Semantic Web: Metadata &amp; Microformats</h2>
         </div>
      </div>

      <div class="presentation">
         <div class="slide">
            <h1>The Semantic Web:<br>Metadata &amp; Microformats</h1>
            <h3>Lecture 18</h3>
            <!-- <h4>Reading: 10.3–10.4</h4> -->

            <p class="license">
               © 2012 Morgan Doocy
            </p>

            <div class="w3c">
               <a href="http://validator.w3.org/check/referer"><img src="../s5/images/w3c-xhtml11.png" alt="Valid XHTML 1.1" /></a>
               <a href="http://jigsaw.w3.org/css-validator/check/referer"><img src="../s5/images/w3c-css.png" alt="Valid CSS!" /></a>
            </div>
         </div>
         
         
         <style type="text/css">
            .html5-marker {
               height: 1em;
               background-color: white;
               padding: .15em;
               vertical-align: middle;
            }
         </style>
         
         <div class="slide">
            <h1>Attaching custom data: <a href="http://html5doctor.com/html5-custom-data-attributes/"><code>data-*</code></a> attributes <img class="html5-marker" src="HTML5_logo_512.png" alt="HTML5 Logo" /></h1>
<div class="example">
<pre class="examplecode html">
&lt;ul id="tas" <em>data-course="info343"</em>&gt;
   &lt;li <em>data-section="a" data-netid="stephyma"</em>&gt;&lt;a <em>class="email"</em> href=""&gt;Stephy Ma&lt;/a&gt;&lt;/li&gt;
   &lt;li <em>data-section="b" data-netid="joshv"</em>&gt;&lt;a <em>class="email"</em> href=""&gt;Josh Villars&lt;/a&gt;&lt;/li&gt;
   &lt;li <em>data-section="c" data-netid="sjm15"</em>&gt;&lt;a <em>class="email"</em> href=""&gt;Steven Markham&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</pre>
<pre class="examplecode js">
<span class="comment">// attach mailto: links to each .email link (spam protection!)</span>
$('#tas a<em>.email</em>').each(function(i, a) {
   var li = a.parentNode, ul = li.parentNode;
   a.href = 'mailto:' + <em>li.dataset.netid</em> + '@uw.edu?subject=[' +
            <em>ul.dataset.course</em> + <em>li.dataset.section</em> + ']';
   <span class="comment">// mailto:stephyma@uw.edu?subject=[info343a]</span>
   <span class="comment">// mailto:joshv@uw.edu?subject=[info343b]</span>
   <span class="comment">// mailto:sjm15@uw.edu?subject=[info343c]</span>
});
</pre>
</div>
            <ul>
               <li>HTML5 allows for custom attributes prefixed with <code>data-<var>name</var></code></li>
               <li>Can set/read these via JS using <code>.dataset.<var>name</var></code> on the DOM object</li>
            </ul>
         </div>
         
         
         <div class="slide">
            <h1>Parsing JSON with jQuery’s <code>.data()</code> function</h1>
<div class="example" style="font-size: 75%">
<pre class="examplecode html">
&lt;ul id="tooltip"&gt;&lt;/ul&gt;
&lt;ul id="courses"&gt;
   &lt;li <em>data-tas='{"matty348": "Matt Shannon", "amckenna": "Andrew McKenna", "gmgillie": "GiGi Gillie"}'</em>
       data-course="info343" data-year="2011" data-quarter="aut" <em>data-current="false"</em>&gt;INFO 343 Autumn 2011&lt;/li&gt;
   &lt;li <em>data-tas='{"stephyma": "Stephy Ma", "sjm15": "Steven Markham", "joshv": "Josh Villars"}'</em>
       data-course="info343" data-year="2012" data-quarter="aut" <em>data-current="true"</em>&gt;INFO 343 Autumn 2012&lt;/li&gt; &lt;/ul&gt;
</pre>
<pre class="examplecode js">
$('#courses li').each(function(i, li) {
   $(li).hover(
      function(event) { <span class="comment">// Show tooltip with TAs for this quarter</span>
         <em>var tas = $(li).data('tas');</em> <span class="comment">// magically an object!</span>
         $.each(tas, function(netid, name) {
            $('&lt;li&gt;').text(name + '(' + netid + '@uw.edu)').appendTo('#tooltip');
         });
         if (<em>$(li).data('current')</em>) { <span class="comment">// magically a boolean!</span>
            $('#tooltip').addClass('current');
         }
         $('#tooltip').css({ 'left': event.clientX, 'top': event.clientY }).show();
      },
      function() { <span class="comment">// Empty and hide tooltip</span>
         $('#tooltip').hide().empty().removeClass('current');
      }
   );
});
</pre>
</div>
            <ul>
               <li>
                  jQuery’s <code>.data()</code> function automatically parses <code>data-*</code> as JSON
                  <ul>
                     <li>With optional second parameter, can be used to safely attach useful data to DOM objects:<br>
<pre><code>$(<var>elem</var>).data('foo', { "hello": "world" });
alert($(<var>elem</var>).data('foo').hello); <span class="comment">// "world"</span></code></pre>
</li>
                  </ul>
               </li>
            </ul>
         </div>
         
         
         <div class="slide">
            <h1>
               Web page metadata:
               <a href="http://www.w3schools.com/tags/tag_meta.asp"><code>&lt;meta&gt;</code></a>
               <span class="readingsection">(2.3.3)</span>
            </h1>

            <p class="description">
               information about your page (for a browser, search engine, etc.)
            </p>

<pre class="examplecode html">
&lt;<em>meta</em> charset="utf-8"&gt; <span class="comment">&lt;!-- HTML 5 ONLY! --&gt;</span>
&lt;<em>meta</em> http-equiv=&quot;Content-Type&quot;
         content=&quot;text/html; charset=utf-8&quot; /&gt; <span class="comment">&lt;!-- XHTML --&gt;</span>
&lt;<em>meta</em> name=&quot;description&quot;
   content=&quot;Course web site for INFO 343: Web Programming at the Information School of the University of Washington.&quot;&gt;
&lt;<em>meta</em> name=&quot;author&quot; content=&quot;Morgan Doocy&quot;&gt;
&lt;<em>meta</em> name=&quot;keywords&quot; content=&quot;web programming, web design, informatics&quot;&gt;
</pre>

            <ul>
               <li>placed <strong>in the <code>head</code></strong> section of your HTML page</li>
               <li><code>meta</code> tags often have both the <code>name</code> and <code>content</code> attributes
                  <ul>
                     <li>some <code>meta</code> tags use the <code>http-equiv</code> attribute instead of <code>name</code> (for HTTP headers)</li>
                  </ul>
               </li>
               <li>using a <code>meta</code> tag <code>Content-Type</code> or <code>charset</code> stops browser/validator encoding warnings</li>
               <li>search engines sometimes use this data in search results</li>
            </ul>
         </div>
         
         
         <div class="slide">
            <h1>Microformats: structured data with <code>class</code>, <code>rel</code></h1>
<div class="example">
<pre class="examplecode html">
&lt;small&gt;This article is licensed under a 
  &lt;a <em>rel="license"</em> href="http://creativecommons.org/licenses/by-nc-sa/2.0/"&gt;
  Creative Commons Attribution Non-commercial Share-alike 
  (By-&lt;abbr&gt;NC&lt;/abbr&gt;-&lt;abbr&gt;SA&lt;/abbr&gt;) license&lt;/a&gt;.
&lt;/small&gt;
</pre>
</div>
<div class="example">
<pre class="examplecode html">
&lt;p <em>class="vcard"</em>&gt;&lt;span <em>class="fn"</em>&gt;Foo Barsofsen&lt;/span&gt; &mdash; 
&lt;a <em>class="url" rel="me"</em> href="http://foo.bar/"&gt;http://foo.bar&lt;/a&gt;, or 
&lt;a <em>class="url" rel="me"</em> href="http://twitter.com/foobar"&gt;follow me on Twitter 
(@&lt;span <em>class="nickname"</em>&gt;foobar&lt;/span&gt;)&lt;/a&gt;.&lt;/p&gt;
</pre>
</div>
            <ul>
               <li><strong>Microformats</strong> use agreed-upon values for <em>existing</em> HTML attributes (<code>class</code>, <code>rel</code>, <code>meta</code>) to mark certain types of information</li>
               <li>Examples above: <a href="http://microformats.org/wiki/rel-license">rel-license</a>, <a href="http://microformats.org/wiki/hcard">hCard</a>, <a href="http://gmpg.org/xfn/and/#idconsolidation">XFN</a></li>
               <li>Others: <a href="http://microformats.org/wiki/hcalendar">hCalendar</a>, <a href="http://microformats.org/wiki/hresume">hRecipe</a>, <a href="http://microformats.org/wiki/hproduct">hProduct</a>, <a href="http://microformats.org/wiki/hreview">hReview</a>, <a href="http://microformats.org/wiki/hresume">hResume</a>, <a href="http://microformats.org/wiki/geo">geo</a></li>
               <li>Similar to microdata, but a little more “hackish”</li>
            </ul>
         </div>
         
         
         <div class="slide">
            <h1>Microdata: structured data with <code>item*</code> attributes</h1>
<div class="example">
<pre class="examplecode html">
&lt;p <em>itemscope itemtype="http://schema.org/Person"</em>&gt;
   Hi! My name&rsquo;s &lt;span <em>itemprop="name"</em>&gt;Foo Barsofsen&lt;/span&gt;.
   &lt;a <em>itemprop="url"</em> href="http://foo.bar/"&gt;My website&lt;/a&gt; is really cool.
   I published a book! It&rsquo;s called
      &lt;span <em>itemprop="book" itemscope</em> <em>itemtype="http://schema.org/Book"</em>&gt;
         &lt;cite <em>itemprop="name"</em>&gt;The Nearness of Foo&lt;/cite&gt;
      &lt;/span&gt;.
&lt;/p&gt;
</pre>
</div>
            <ul>
               <li><strong>Microdata</strong> uses newer <code>item*</code> attributes to mark key/value pairs in HTML.
                  <ul>
                     <li><code>itemscope</code> declares an object. (Scopes are nestable.)</li>
                     <li><code>itemtype</code> links to a schema specifying valid properties for this object.</li>
                     <li><code>itemprop</code> is a piece of data (“property”) inside the object.</li>
                     <!-- <li><code>itemid</code> is a global unique identifier for this object (e.g. GUID for people/things, ISBN for books).</li> -->
                  </ul>
               </li>
               <li>Can be validated with various tools: <a href="http://validator.nu">Validator.nu</a>, <a href="http://www.google.com/webmasters/tools/richsnippets">Google Structured Data Testing Tool</a></li>
               <li>Similar to microformats, but a little more “official”
                  <ul>
                     <li><code>item*</code> are dedicated attributes specifically for defining structured data, rather than “overloading” <code>class</code> and <code>rel</code></li>
                  </ul>
               </li>
               <li>Many types of data can be represented using either a microformat or microdata.</li>
            </ul>
         </div>
         
         
         
<!--#include virtual="../s5/commonbottom.html" -->