Tuesday, November 1, 2016

Distribution Analysis of Portraits and Deities

Building on recent advancements in distribution visualizations I rolled into production on Nomisma.org last month, I have extended the complexity of these visualizations to include portraits and deities both as distribution categories and parameters for generating subsets of results from the Nomisma SPARQL endpoint. Deities, in particular, required some extra work. While we have incorporated URIs from the British Museum thesaurus for deities into our data throughout ANS projects, there had been no accompanying triples for these URIs to provide human-readable labels. I wrote a simple script to extract labels from the British Museum SPARQL endpoint in order to generate a fairly simple SKOS-based taxonomy for the entities, which I then uploaded into Nomisma's endpoint. You yourself can download this small RDF dataset from http://nomisma.org/datasets.

Distribution of mints for Augustan coin types of Victory vs. Mars

This required rewriting the underlying XSLT templates in the XPL for generating the XML model (which would be serialized into the JSON view required by d3plus, a chart extension for d3js). The previous XSLT stylesheet stored a generic SPARQL query as text, which had bits and pieces replaced with variables passed in via HTTP request parameters. This worked well enough when querying predicates stored directly within the coin type data object. However, portraits and deities are expressed at a deeper level--within the triples describing the obverse or reverse of the coin. Thus, a query for coin types depicting Agrippina the Younger is as follows:

?s a nmo:TypeSeriesItem ;
  nmo:hasObverse ?obv ;
  nmo:hasReverse ?rev .
{?obv nmo:hasPortrait nm:agrippina_ii}
UNION {?rev nmo:hasPortrait nm:agrippina_ii}

As a result, the simple textual search-and-replace technique for constructing the SPARQL query was reconceived as a data object (represented as XML within an XSLT variable) generated by HTTP request parameters. Each triple XML element contains a subject, predicate, and object attribute. Union and optional queries are contained within relevant XML tags.

<triple s="?coinType" p="nmo:hasObverse" o="?obv"/>
<triple s="?coinType" p="nmo:hasReverse" o="?rev"/>
<union>
    <triple s="?obv" p="nmo:hasPortrait" o="{$object}"/>
    <triple s="?rev" p="nmo:hasPortrait" o="{$object}"/>
 </union>

Where the $object is the object in the "compare" or "filter" request parameter (in this case, nm:agrippina_ii). This XML expression of a SPARQL query is then transformed via XSLT templates into the plain text which is then used to GET the response from the endpoint. I have posted this XSLT stylesheet to gist.

Enhancing geographic distribution

I added one little, but very useful tweak. As previously discussed, the data for any visualization can be downloaded as a CSV file. I enhanced this CSV file by including the entity URIs, but, more importantly, when the distribution category is set to "Mint", the underlying SPARQL query will extract the latitude and longitude if available. As a result, you can drop the CSV directly into Google Fusion Tables to generate a map or import it into GIS software (like QGIS), and using the count or percentage column, adjust the size or coloration for a more accurate, graduated visualization (like below).

Distribution of Augustan issues depicting Victory