Search

More model-driven RDF generation

The model-driven approach seems promising.  Here is the current model, the new XML files (constituencies, parties and results),  the new RDF files (constituencies, parties and results) and the RDF vocab. The three  RDF documents  has been loaded into a Talis Data store and the dataset is queriable via the SPARQL interface.  URIs are now de-referable with a primitive RDF browser e.g. Bristol West (no content negotiation yet).

 

For example to get the names of the constituencies and candidates fielded by the SNP in the 2005 Election (the only one for which there is data at present but more will surely follow)



PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX : <http://www.cems.uwe.ac.uk/xmlwiki/rdf/election/vocab#>
PREFIX xs: <http://www.w3.org/2001/XMLSchema#> 
select ?cname ?name where {
  ?election rdf:type :Election;
        :election-name "UK2005";
        :party ?party.
  ?party :party-name "SNP".
  ?cand :party ?party;
       :candidate-name ?name.
  ?cons :candidate ?cand;
       :constituency-name ?cname.

}


Result

The number of seats won by Labour in the 2005 election:




PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>  
PREFIX : <http://www.cems.uwe.ac.uk/xmlwiki/rdf/election/vocab#>  

select (count($cons) as ?mps where {
  ?election rdf:type :Election;
        :election-name "UK2005";
        :constituency ?cons.
  ?cons :MP ?MP.
  ?MP :party ?party.
  ?party :party-name "Labour".


Result

The model-based approach simplifies XML generation since the new XML-to RDF code uses the ER model to add the correct data type and to generate resource-resource links.  This was relatively easy for the nested structures in XML but for general references, I had to generate the primary keys in the XML - more work needed.

Troubles

The first was to define the rdf:datatype as for example "xs"string" instead of with a full URI "http://www.w3.org/2001/XMLSchema#string". I  forgot  that prefixes are only expanded in element and attribute names, not values. 

The second was to use xs:string at all.  This conflicts with the use of a xml:lang attribute (although I haven't in this data) and forces SPARQL queries to specify the datatype:



PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
 PREFIX : <http://www.cems.uwe.ac.uk/xmlwiki/rdf/election/vocab#> 
 PREFIX xs: <http://www.w3.org/2001/XMLSchema#> 
 select * where { 
   ?party rdf:type :Party; 
        :party-name "Labour"^^xs:string.


It seems good practice to use datatypes when the literal is a typed value, for example xs:decimal for the turnout but care is needed to ensure that the values are valid for the defined type.