200 likes | 280 Views
Ceri Binding Hypermedia Research Unit, University of Glamorgan, Wales http://hypermedia.research.glam.ac.uk/kos/STELLAR/. STELLAR Data Conversions. SQL2CSV SQL2TAB. SQLEXECUTE. Delimited Data. Database. CSV2DB TAB2DB. CSV2STG TAB2STG DELIM2STG. SQL2STG. User-defined template. XML.
E N D
Ceri Binding Hypermedia Research Unit, University of Glamorgan, Wales http://hypermedia.research.glam.ac.uk/kos/STELLAR/
STELLAR Data Conversions SQL2CSV SQL2TAB SQLEXECUTE Delimited Data Database CSV2DB TAB2DB CSV2STG TAB2STG DELIM2STG SQL2STG User-defined template XML RDF [other textual formats]
User Defined Templates • STELLAR uses the “StringTemplate” engine http://www.stringtemplate.org/ • String Template Group - text files (*.stg) • Textual templates with named placeholders, populated by data at runtime • User defined vs. inbuilt templates: • Advantage - more flexibility in output format • Disadvantage - no validation of output format
String Template Group – layout • Delimiters • Define characters that will be used to identify start & end of named placeholders within the template • Imports • Import externally defined templates • Dictionaries • Define lookup dictionaries • Templates • Define templates
String Template Group - example // Define delimiters (if not defined, default is "$") delimiters "$", "$" // Import external templates (allows template libraries) import "myGroup.stg" // Define a lookup dictionary. Usage: my_dictionary.(“EBA”) my_dictionary ::= [ "EBA" : "Early Bronze Age", "MBA" : "Middle Bronze Age", "LBA" : "Late Bronze Age", default : key // Unknown value passed through ] // Define a template my_template1(period) ::= "Period is $my_dictionary.(period)$" // e.g. my_template("EBA")$ => "Period is Early Bronze Age"
STELLAR-Specific Templates • STELLAR.Console looks for 3 key templates: HEADER, RECORD & FOOTER delimiters "$", "$" // define delimiter character to use for data ‘placeholders’ import "MyTemplates.stg" // import to use templates held in other *.stg files // 1. HEADER is written first (if the template exists) HEADER(options) ::= "List of $options.site_name$ finds" // 2. RECORD is written once per row of input data RECORD(options, data) ::= << Find Number : $data.id$ // “id” here is the column name from the input data Find Type : $data.type$// the placeholders get replaced by the actual data values Description : $data.desc$ $write_some_stars()$ // example of calling another user defined template >> // 3. FOOTER is written last (if the template exists) FOOTER(options) ::= "End of list" // other templates can be defined and called from main templates write_some_stars() ::= "*************"
Example template input & output (delimited CSV data input): id, type, desc 12345, ”hobnail”, ”Rusted nail shaft, possibly a hobnail?” 23456, ”brooch”, ”Gold brooch with inlaid mother of pearl” 34567, ”cleat”, “Heavily corroded” (template output): List of South Downs finds Find Number : 12345 Find Type : hobnail Description : Rusted nail shaft, possibly a hobnail? ************* Find Number : 23456 Find Type : brooch Description : Gold brooch with inlaid mother of pearl ************* Find Number : 34567 Find Type : cleat Description : Heavily corroded ************* End of list (HEADER) “List of $options.site_name$ finds” (RECORD) Find Number : $data.id$ Find Type : $data.type$ Description : $data.desc$ write_some_stars() (write_some_stars) “*************” (FOOTER) “End of list”
Using templates to produce RDF delimiters "$", "$” // write RDF header HEADER(options) ::= << <?xml version="1.0" encoding="UTF-8"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"> >> // write RDF entities and properties based on each data row RECORD(options, data) ::= << <rdf:Description rdf:about="http://tmp/$data.id$"> <rdfs:label>$data.title$</rdfs:label> </rdf:Description> >> // write RDF footer – closure of RDF element from header FOOTER(options) ::= "</rdf:RDF>"
Template Dependencies RDF.stg Imports CRM.stg Imports CRMEH.stg Imports Imports Imports CRMEH_GROUPS.stg CRMEH_CONTEXTS.stg CRMEH_Etc.
Consistent URIs - Convention • Namespace prefix • E.g. “http://stellar/silchester/” • Entity type • E.g. “EHE0007” (i.e. Context) • Identifier (data value) • E.g. “1015” • URI pattern: {prefix}{entity type}_{value} • E.g. “http://stellar/silchester/EHE0007_1015” • Consistent identifiers facilitate incremental enrichment of data
CRM-EH entity / CRM property chain • Context A stratigraphically below Context B: • crmeh:EHE0007_Context [EHE0007_A] • crm:P7i_witnessed • crmeh:EHE1001_ContextEvent [EHE1001_A] • crm:P120_occurs_before • crmeh:EHE1001_ContextEvent [EHE1001_B] • crm:P7_took_place_at • crmeh:EHE0007_Context [EHE0007_B]
Example: CRMEH_CONTEXTS: strat_lower_id crmeh:EHE0007_Context data:EHE0007_123 Example template input ecrm:P7i_witnessed ecrm:P7_took_place_at crmeh:EHE1001_ContextEvent data:EHE1001_123 ecrm:P120i_occurs_after ecrm:P120_occurs_before crmeh:EHE1001_ContextEvent data:EHE1001_456 ecrm:P7_took_place_at ecrm:P7i_witnessed crmeh:EHE0007_Context data:EHE0007_456 Resultant template output Data model
Browsing RDF Data (“Gruff” tool) • Import, consolidation, browsing & querying of RDF data
Querying RDF Data - SPARQL • Structured semantic queries • Similar(ish) syntax to SQL • Use same query across multiple datasets • Possibly develop templates to build queries?
Issues Validation of output Versioning of templates
Ceri Binding Hypermedia Research Unit, University of Glamorgan, Wales http://hypermedia.research.glam.ac.uk/kos/STELLAR/