<docbook><section><title>VirtSparqlCxmlDzcs</title><title>Pivot Collections (Part 3)</title>Pivot Collections (Part 3)
<bridgehead class="http://www.w3.org/1999/xhtml:h2">Contents</bridgehead>
<para>Part 1: <ulink url="VirtSparqlCxml">Introduction</ulink></para>
<para>Part 2: <ulink url="VirtSparqlCxml">SparqlCxml</ulink></para>
<para>Part 3: SparqlCxml Deep Zoom Collections</para>
<itemizedlist mark="bullet" spacing="compact"><listitem><ulink url="#AncSparqlCxmlDzcs"><span style="color: red">
      UNKNOWN tag:
      http://www.w3.org/1999/xhtml:nowikiSparqlCxml</span> Deep Zoom Collections</ulink> <itemizedlist mark="bullet" spacing="compact"><listitem><ulink url="#AncDynamicDeepZoomCollections">Dynamic DZCs</ulink> </listitem>
<listitem><ulink url="#AncSupportedImageFormats">Supported Image Formats</ulink> </listitem>
<listitem><ulink url="#AncImageCaching">Image Caching</ulink> </listitem>
</itemizedlist></listitem>
<listitem><ulink url="#AncPivotIcons">Default Images for Pivot Collections</ulink> <itemizedlist mark="bullet" spacing="compact"><listitem><ulink url="#AncSparqlCxmlIconOntology"><span style="color: red">
      UNKNOWN tag:
      http://www.w3.org/1999/xhtml:nowikiSparqlCxml</span> Icon Ontology</ulink> </listitem>
<listitem><ulink url="#AncAddingYourOwnIcons">Adding Your Own Icons</ulink> </listitem>
</itemizedlist></listitem>
<listitem><ulink url="#AncQrCodes">QR Codes</ulink></listitem>
</itemizedlist><para>Part 4: <ulink url="VirtSparqlCxmlPivotViewer">PivotViewer</ulink></para>
<para>Part 5: <ulink url="VirtSparqlCxmlImport">Importing CXML</ulink></para>
<para>Part 6: <ulink url="VirtSparqlCxmlFacetPivotBridge">Facet Pivot Bridge</ulink></para>
<para>Part 7: <ulink url="VirtSparqlCxmlDETs">DETs : Persisting SPARQL Query Results to DAV</ulink></para>
<para>Part 8: <ulink url="VirtSparqlCxmlFAQs">Frequently Asked Questions (FAQs)</ulink></para>
<para>Part 9: <ulink url="VirtSparqlCxmlGlossary">Glossary</ulink></para>
<para> <ulink url="">
 </ulink></para>
<bridgehead class="http://www.w3.org/1999/xhtml:h2">SparqlCxml Deep Zoom Collections</bridgehead>
<ulink url="">
<para> </para>
<bridgehead class="http://www.w3.org/1999/xhtml:h3">Dynamic DZCs</bridgehead>
SparqlCxml generates Deep Zoom collections (DZCs) dynamically.
 Source images identified in the SPARQL query, either through the ?image reserved query variable or through graph virtcxml, are retrieved, stored and converted to Deep Zoom Image (DZI) format when a collection is generated.<para>An item&#39;s image is fetched asynchronously using an HTTP GET, multiplexed over a thread pool, and then stored in table DB.DBA.DZC_IMAGE_CACHE.
 Icons for items without a custom image are handled similarly - the icon is retrieved from WebDAV and again stored in DZC_IMAGE_CACHE.
 An image tile is created on demand at the time PivotViewer requests it.
 Each tile is then cached as a BLOB in table DB.DBA.DZC_TILE.</para>
<para>The image tiles and XML descriptor files which constitute a DZC are not stored in a web-accessible directory tree.
 Rather than serving files, the HTTP response content is derived directly from the database; from table DZC_TILE, in the case of image tiles, or tables DZC_COLLECTION and DZC_LIST in the case of the descriptor files.
 SparqlCxml creates a virtual directory &quot;/DeepZoomCache/&quot; for this purpose and associates it with a handler procedure WS.WS.&quot;/!DeepZoomCache/&quot;.
 The CXML generated by SparqlCxml includes an Items element with attribute ImgBase pointing to /DeepZoomCache/.
 e.g  &lt;Items ImgBase=&quot;http://lod.openlinksw.com/DeepZoomCache/cxml29.dzc&quot;&gt;.
 Consequently all HTTP requests to &quot;/DeepZoomCache/?&quot; are intercepted by this handler.</para>
<para>Path formats recognized include: </para>
<itemizedlist mark="bullet" spacing="compact"><listitem>/DeepZoomCache/cxml%d.dzc </listitem>
<listitem>/DeepZoomCache/%d.dzi </listitem>
<listitem>/DeepZoomCache/%d_files/%d/%d_%d.%s</listitem>
</itemizedlist><para>(The path formats are described using printf format specifiers)</para>
<ulink url="">
<para> </para>
<bridgehead class="http://www.w3.org/1999/xhtml:h3">Supported Image Formats</bridgehead>
<para>The DZC generation supports both the JPEG and PNG image formats, with JPEG as the preferred option.
 (PNGs used as icons may occasionally display with a black background as an artifact of processing with ImageMagick.) Silverlight itself does not handle GIFs.</para>
<ulink url="">
<para> </para>
<bridgehead class="http://www.w3.org/1999/xhtml:h3">Image Caching</bridgehead>
<para>Deep Zoom images generated by SparqlCxml are cached for 24 hours, after which they will be regenerated when next requested.
 Requesting the image within this 24 hour window resets its &#39;time to live&#39; to 1 day.</para>
<para>Images loaded by DZC_LOAD_IMAGE() have the date and time of their last use recorded.
 When caching an image, DZC_LOAD_IMAGE() first checks table DB.DBA.DZC_IMAGE_CACHE to see if the image with the given URI has already been cached.
 If found, it&#39;s &#39;last use&#39; timestamp is updated to 24 hours from the current time, similarly when adding an image to the cache for the first time.
 Each time DZC_LOAD_IMAGE() is called, it deletes any cached images, and the corresponding image tiles, with a &#39;last use&#39; timestamp older than the current time.</para>
<para>If for some reason you need to force the image cache to be cleared, you can use procedure DB.DBA.DZC_RESET ().
 This routine deletes the contents of all the tables used by the SparqlCxml DZC generation, i.e.
 DB.DBA.DZC_IMAGE_CACHE, DB.DBA.DZC_TILE, DB.DBA.DZC_COLLECTION and DB.DBA.DZC_LIST</para>
 <para><emphasis>Warning</emphasis>: Use this routine with caution.
 Whilst CXML-generating queries executed against a /sparql endpoint can regenerate DZCs as needed, this is <emphasis>not</emphasis> the case for CXML snapshots generated from the /fct endpoint and the Facet Pivot Bridge.
 Clearing the DZC cache will break these snapshots.
 Because the source query used to create them is not recorded, the associated DZC cannot be recreated transparently.
 Facet Pivot Bridge CXML snapshots must be created from scratch if the DZC cache is cleared.</para>
<ulink url="">
<para> </para>
<bridgehead class="http://www.w3.org/1999/xhtml:h2"> Default Images for Pivot Collections</bridgehead>
<para>While the SPARQL CXML generation is able to generate a Deep Zoom image (DZI) for a collection item from an image associated with it, it is not a requirement that every item in the collection has one.
 If a depiction of the item is not available, SparqlCxml substitutes an icon for the missing image.
 A small set of icons is included in the SparqlCxml VAD to provide a base set of default images, together with an icon ontology and icon data graph which controls which icon is used for a particular item type.
 The base set of icons and the icon data graph can be customised to include default images reflecting the application domain the collection data is drawn from.</para>
<para>The form of the SPARQL SELECT query determines whether items without a depiction (custom image) are included in the collection and hence whether icons will be used.
 For items without custom images to be included, the image triple pattern must be qualified by the OPTIONAL keyword.</para>
<para>e.g.
</para>
<programlisting>prefix foaf: &lt;http://xmlns.com/foaf/0.1/&gt;
prefix ski: &lt;http://www.openlinksw.com/ski_resorts/schema#&gt;
prefix camp: &lt;http://www.openlinksw.com/campsites/schema#&gt;

select * where 
{
  { 
    ?s a ski:SkiResort . ?s ?p ?o . optional { ?s foaf:depiction ?image } 
  }
  union
  {
    ?s a camp:Campsite . ?s ?p ?o . optional { ?s foaf:depiction ?image }
  }
}
</programlisting><para> The  image below shows part of the resulting Pivot collection.
 The piste map images are provided by the foaf:depiction predicates.
 Ski resorts without an associated piste map image use the &#39;earth&#39; icon as a fallback image.
 Campsites without a custom image use the &#39;parasol&#39; icon.
  <figure><graphic fileref="VirtSparqlCxmlDzcs/pivot_icons1.jpg" /></figure></para>
<para>Similarly for DESCRIBES, the collection created by the query </para>
<programlisting>prefix foaf: &lt;http://xmlns.com/foaf/0.1/&gt;

describe ?s where { ?s a ski:SkiResort . }
</programlisting><para>will include all ski resorts, using icons for any without custom images; whereas </para>
<programlisting>prefix foaf: &lt;http://xmlns.com/foaf/0.1/&gt;

describe ?s where { ?s a ski:SkiResort ; foaf:depiction ?depiction }
</programlisting><para>will include in the collection only those with custom images.</para>
<ulink url="">
<para> </para>
<bridgehead class="http://www.w3.org/1999/xhtml:h3">SparqlCxml Icon Ontology</bridgehead>
<para>Which icon is used for a collection item without its own custom image is controlled through the icon ontology defined by schema graph &lt;http://www.openlinksw.com/schemas/virtpivot&gt;, icon instance data in graph &lt;http://www.openlinksw.com/virtpivot/icons&gt; and rules in graph &lt;virtpivot-rules&gt;.
 (The corresponding source files in DAV/VAD/sparql_cxml are virtpivot_icon_ontology.n3, virtpivot_icon_instance_data.n3 and virtpivot_rules.sql respectively.) Together, the icon schema graph and instance data define various generic display classes: vpi:Thing, vpi:Person, vpi:Place, vpi:Book, vpi:Music etc and associate an icon with each, e.g.
 vpi:ThingIcon, vpi:PersonIcon etc.
 The default icon set (generated by describe ?s from &lt;virtpivot-icon-test&gt; where { ?s ?p ?o }) is shown below.</para>
<figure><graphic fileref="VirtSparqlCxmlDzcs/icon_collection.jpg" /></figure> <ulink url="http://linkeddata.uriburner.com/PivotViewer/?url=http%3A%2F%2Flinkeddata.uriburner.com%2Fsparql%2F%3Fdefault-graph-uri%3D%26should-sponge%3D%26query%3Ddescribe%2B%253Fs%2Bfrom%2B%253Cvirtpivot-icon-test%253E%2Bwhere%2B%7B%2B%253Fs%2B%253Fp%2B%253Fo%2B%7D%26debug%3Don%26timeout%3D%26format%3Dtext%252Fcxml%26CXML_redir_for_subjs%3D%26CXML_redir_for_hrefs%3D%26save%3Ddisplay%26fname%3D%23%2524facet0%2524%3DSubject%2520Type%26%2524view%2524%3D1%26%24tab%24%3D0%26%24zoom%24%3D2">View Pivot collection</ulink><para>The set of predefined DisplayClasses includes: AddressBook, BeachResort, Book, BookmarkFolder, Briefcase, Business, Calendar, Community, ElectronicGood, Event, ImageGallery, MailMessage, MessageBoard, Music, Person, Place, SkiResort, SubscriptionList, SurveyCollection, Thing, TouristDestination, VCard, Weblog, Wiki</para>
<para>The actual image to use for an icon is set through the vp:has_dzi_source property.
 e.g.: </para>
<itemizedlist mark="bullet" spacing="compact"><listitem>vpi:ThingIcon vp:has_dzi_source &quot;linkeddata&quot; . </listitem>
<listitem>vpi:Business vp:has_dzi_source &quot;factory_300w&quot; .</listitem>
</itemizedlist><para>The corresponding images used to generate the icon Deep Zoom images (DZIs) can be found in WebDAV folder DAV/VAD/sparql_cxml/generic_dzc_images, e.g.
 linkeddata.jpg, factory_300w.jpg etc.</para>
<para> Which icon is displayed as a fallback image for a particular item is determined by entries in graph &lt;virtpivot-rules&gt; which corresponds to the rule set &#39;virtpivot-rules&#39; created by DAV/VAD/sparql_cxml/virtpivot_rules.sql.
 The rule set provides an inference context for SPARQL CXML when selecting icons.
 For more information on rule sets, please refer to the Virtuoso Documentation, section  <ulink url="http://docs.openlinksw.com/virtuoso/rdfsparqlrule.html">Inference Rules &amp; Reasoning</ulink>.
 The extract below, taken from virtpivot_rules.sql, shows some of the rules defined.
</para>
<programlisting>DB.DBA.TTLP (&#39;
@prefix rdfs: &lt;http://www.w3.org/2000/01/rdf-schema#&gt; .
@prefix vpi: &lt;http://www.openlinksw.com/virtpivot/icons/&gt; .
@prefix c: &lt;http://www.w3.org/2002/12/cal/icaltzd#&gt; .
@prefix cal: &lt;http://www.w3.org/2002/12/cal#&gt; .
@prefix foaf: &lt;http://xmlns.com/foaf/0.1/&gt; .
@prefix sioc: &lt;http://rdfs.org/sioc/ns#&gt; .
@prefix sioct: &lt;http://rdfs.org/sioc/types#&gt; .
@prefix vcard: &lt;http://www.w3.org/2006/vcard/ns#&gt; .

c:Vevent rdfs:subClassOf vpi:Event .
cal:vevent rdfs:subClassOf vpi:Event .
foaf:Person rdfs:subClassOf vpi:Person .
vcard:VCard rdfs:subClassOf vpi:VCard .

sioct:AddressBook rdfs:subClassOf vpi:AddressBook .
sioct:BookmarkFolder rdfs:subClassOf vpi:BookmarkFolder .
sioct:Briefcase rdfs:subClassOf vpi:Briefcase .
sioct:Calendar rdfs:subClassOf vpi:Calendar .
sioc:Community rdfs:subClassOf vpi:Community .
sioct:ImageGallery rdfs:subClassOf vpi:ImageGallery .
sioct:MailMessage rdfs:subClassOf vpi:MailMessage .
sioct:MessageBoard rdfs:subClassOf vpi:MessageBoard .
sioct:SubscriptionList rdfs:subClassOf vpi:SubscriptionList .
sioct:SurveyCollection rdfs:subClassOf vpi:SurveyCollection .
sioct:Weblog rdfs:subClassOf vpi:Weblog .
sioct:Wiki rdfs:subClassOf vpi:Wiki .
...
&#39;, &#39;&#39;, &#39;virtpivot-rules&#39;);

rdfs_rule_set (&#39;virtpivot-rules&#39;, &#39;virtpivot-rules&#39;);
</programlisting><para> To specify that a particular icon should be used to represent an instance of a class, add an entry to virtpivot-rules which declares that class as a subclass of the DisplayClass represented by the icon, then refresh the rule set by executing rdfs_rule_set (&#39;virtpivot-rules&#39;, &#39;virtpivot-rules&#39;).</para>
<ulink url="">
<para> </para>
<bridgehead class="http://www.w3.org/1999/xhtml:h3">Adding Your Own Icons</bridgehead>
<para>The default icon collection is intended only to provide a small set of icons for a sample of broad concepts and the main entity types handled by ODS applications.
 You can add your own icons, to represent entity types specific to your own application domain, by copying them to the WebDAV folder DAV/VAD/sparql_cxml/generic_dzc_images and adding entries to graph &lt;http://www.openlinksw.com/virtpivot/icons&gt; to define new DisplayClass and DisplayClassIcon instances.</para>
<para>Suppose, for example, that you had defined your own vehicle ontology, hosted at http://purl.org/vehicle_ontol/v1#, and wanted to add an automobile icon to the icon set to represent instances of vehicle classes from this ontology.
 Assuming your icon is to be provided by image file &quot;sports_car.jpg&quot;, the additions needed to incorporate it might look as follows:</para>
<bridgehead class="http://www.w3.org/1999/xhtml:h5">Graph http://www.openlinksw.com/virtpivot/icons:</bridgehead>
 <programlisting>@prefix rdfs: &lt;http://www.w3.org/2000/01/rdf-schema#&gt; .
@prefix vp: &lt;http://www.openlinksw.com/schemas/virtpivot#&gt; .
@prefix vpi: &lt;http://www.openlinksw.com/virtpivot/icons/&gt; .

vpi:Automobile
	a vp:DisplayClass ;
	rdfs:label &quot;Automobile (DisplayClass)&quot; ;
	rdfs:comment &quot;The DisplayClass type used to represent an automobile&quot; ;
	vp:has_icon vpi:AutomobileIcon ;
	vp:display_class_category &quot;vehicles&quot; .

vpi:AutomobileIcon
	a vp:DisplayClassIcon ;
        rdfs:label &quot;Automobile icon&quot; ;
	rdfs:comment &quot;Pivot icon for an entity belonging to the &#39;Automobile&#39; DisplayClass&quot; ;
	vp:has_dzi_source &quot;sports_car&quot; ;
	vp:belongs_to_icon_collection vpi:GenericIcons1 .
</programlisting><para> </para>
<bridgehead class="http://www.w3.org/1999/xhtml:h5">Graph virtpivot_rules:</bridgehead>
 <programlisting>@prefix rdfs: &lt;http://www.w3.org/2000/01/rdf-schema#&gt; .
@prefix veh: &lt;http://purl.org/vehicle_ontol/v1#&gt; .
@prefix vpi: &lt;http://www.openlinksw.com/virtpivot/icons/&gt; .

veh:Hatchback rdfs:subClassOf vpi:Automobile . 
veh:Saloon rdfs:subClassOf vpi:Automobile .
veh:SportsCar rdfs:subClassOf vpi:Automobile . 
</programlisting><para>With these changes, any veh:Hatchback, veh:Saloon or veh:SportsCar instance in the collection will, in the absence of a custom image, be represented by the sports_car icon.</para>
<ulink url="">
<para> </para>
<bridgehead class="http://www.w3.org/1999/xhtml:h2">QR Codes</bridgehead>
<para>Virtuoso&#39;s CXML support includes the ability to generate <ulink url="http://en.wikipedia.org/wiki/QR_Code">QR codes</ulink> for collection items.
 Each item&#39;s QR code typically encodes a string identifier.
 This is normally the item&#39;s URI, which courtesy of Linked Data, can serve as a globally unique dereferenceable ID providing a link to further information about the item.
 However, the content used for the QR code is configurable and any item facet can be used, for instance a product SKU (stock keeping unit) or UPC (universal product code).
 A generated QR code can appear in <ulink url="PivotViewer">PivotViewer</ulink> adjacent to the item&#39;s custom or default image, or be used alone as the main depiction.
 The choice of which is used is controlled through the <ulink url="VirtSparqlCxml">SPARQL reserved query variables</ulink> ?image and ?qrcode.
</para>
</ulink></ulink></ulink></ulink></ulink></ulink></ulink></section></docbook>