• Topic
  • Discussion
  • VOS.VirtSparqlCxmlDzcs(Last) -- DAVWikiAdmin? , 2017-06-29 07:40:48 Edit WebDAV System Administrator 2017-06-29 07:40:48

    Pivot Collections (Part 3)


    Part 1: Introduction

    Part 2: SparqlCxml

    Part 3: SparqlCxml Deep Zoom Collections

    Part 4: PivotViewer

    Part 5: Importing CXML

    Part 6: Facet Pivot Bridge

    Part 7: DETs : Persisting SPARQL Query Results to DAV

    Part 8: Frequently Asked Questions (FAQs)

    Part 9: Glossary

    SparqlCxml Deep Zoom Collections

    Dynamic DZCs

    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.

    An item'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.

    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 "/DeepZoomCache/" for this purpose and associates it with a handler procedure WS.WS."/!DeepZoomCache/". The CXML generated by SparqlCxml includes an Items element with attribute ImgBase pointing to /DeepZoomCache/. e.g <Items ImgBase="http://lod.openlinksw.com/DeepZoomCache/cxml29.dzc">. Consequently all HTTP requests to "/DeepZoomCache/?" are intercepted by this handler.

    Path formats recognized include:

    • /DeepZoomCache/cxml%d.dzc
    • /DeepZoomCache/%d.dzi
    • /DeepZoomCache/%d_files/%d/%d_%d.%s

    (The path formats are described using printf format specifiers)

    Supported Image Formats

    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.

    Image Caching

    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 'time to live' to 1 day.

    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's 'last use' 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 'last use' timestamp older than the current time.

    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

    Warning: Use this routine with caution. Whilst CXML-generating queries executed against a /sparql endpoint can regenerate DZCs as needed, this is not 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.

    Default Images for Pivot Collections

    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.

    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.


    prefix foaf: <http://xmlns.com/foaf/0.1/>
    prefix ski: <http://www.openlinksw.com/ski_resorts/schema#>
    prefix camp: <http://www.openlinksw.com/campsites/schema#>
    select * where 
        ?s a ski:SkiResort . ?s ?p ?o . optional { ?s foaf:depiction ?image } 
        ?s a camp:Campsite . ?s ?p ?o . optional { ?s foaf:depiction ?image }

    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 'earth' icon as a fallback image. Campsites without a custom image use the 'parasol' icon.

    Similarly for DESCRIBES, the collection created by the query

    prefix foaf: <http://xmlns.com/foaf/0.1/>
    describe ?s where { ?s a ski:SkiResort . }

    will include all ski resorts, using icons for any without custom images; whereas

    prefix foaf: <http://xmlns.com/foaf/0.1/>
    describe ?s where { ?s a ski:SkiResort ; foaf:depiction ?depiction }

    will include in the collection only those with custom images.

    SparqlCxml Icon Ontology

    Which icon is used for a collection item without its own custom image is controlled through the icon ontology defined by schema graph <http://www.openlinksw.com/schemas/virtpivot>, icon instance data in graph <http://www.openlinksw.com/virtpivot/icons> and rules in graph <virtpivot-rules>. (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 <virtpivot-icon-test> where { ?s ?p ?o }) is shown below.

    View Pivot collection

    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

    The actual image to use for an icon is set through the vp:has_dzi_source property. e.g.:

    • vpi:ThingIcon vp:has_dzi_source "linkeddata" .
    • vpi:Business vp:has_dzi_source "factory_300w" .

    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.

    Which icon is displayed as a fallback image for a particular item is determined by entries in graph <virtpivot-rules> which corresponds to the rule set 'virtpivot-rules' 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 Inference Rules & Reasoning. The extract below, taken from virtpivot_rules.sql, shows some of the rules defined.

    DB.DBA.TTLP ('
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix vpi: <http://www.openlinksw.com/virtpivot/icons/> .
    @prefix c: <http://www.w3.org/2002/12/cal/icaltzd#> .
    @prefix cal: <http://www.w3.org/2002/12/cal#> .
    @prefix foaf: <http://xmlns.com/foaf/0.1/> .
    @prefix sioc: <http://rdfs.org/sioc/ns#> .
    @prefix sioct: <http://rdfs.org/sioc/types#> .
    @prefix vcard: <http://www.w3.org/2006/vcard/ns#> .
    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 .
    ', '', 'virtpivot-rules');
    rdfs_rule_set ('virtpivot-rules', 'virtpivot-rules');

    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 ('virtpivot-rules', 'virtpivot-rules').

    Adding Your Own Icons

    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 <http://www.openlinksw.com/virtpivot/icons> to define new DisplayClass and DisplayClassIcon instances.

    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 "sports_car.jpg", the additions needed to incorporate it might look as follows:

    Graph http://www.openlinksw.com/virtpivot/icons:

    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix vp: <http://www.openlinksw.com/schemas/virtpivot#> .
    @prefix vpi: <http://www.openlinksw.com/virtpivot/icons/> .
    	a vp:DisplayClass ;
    	rdfs:label "Automobile (DisplayClass)" ;
    	rdfs:comment "The DisplayClass type used to represent an automobile" ;
    	vp:has_icon vpi:AutomobileIcon ;
    	vp:display_class_category "vehicles" .
    	a vp:DisplayClassIcon ;
            rdfs:label "Automobile icon" ;
    	rdfs:comment "Pivot icon for an entity belonging to the 'Automobile' DisplayClass" ;
    	vp:has_dzi_source "sports_car" ;
    	vp:belongs_to_icon_collection vpi:GenericIcons1 .

    Graph virtpivot_rules:

    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix veh: <http://purl.org/vehicle_ontol/v1#> .
    @prefix vpi: <http://www.openlinksw.com/virtpivot/icons/> .
    veh:Hatchback rdfs:subClassOf vpi:Automobile . 
    veh:Saloon rdfs:subClassOf vpi:Automobile .
    veh:SportsCar rdfs:subClassOf vpi:Automobile . 

    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.

    QR Codes

    Virtuoso's CXML support includes the ability to generate QR codes for collection items. Each item's QR code typically encodes a string identifier. This is normally the item'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 PivotViewer? adjacent to the item's custom or default image, or be used alone as the main depiction. The choice of which is used is controlled through the SPARQL reserved query variables ?image and ?qrcode.