PushBackDataToLegacySourcesFusion
From W3C Wiki
This note describes the so called fusion, the creation of RDForms from an input RDF graph and an HTML form used in pushback.
main responsible: |
contributors: |
Back to pushback home
See also: RDForms
Contents
Fusion: pushback - Write Data Back From RDF to Non-RDF Sources
Index
Mapping to RDForms Vocabulary
The SPARQL query mapping the input RDF graph to the RDForms vocabulary could look like
PREFIX pb: <http://ld2sd.deri.org/pb#> PREFIX sioc: <http://rdfs.org/sioc/ns#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> CONSTRUCT { <http://ld2sd.deri.org/demo#form1> a pb:RDForm ; pb:field <http://ld2sd.deri.org/demo#field1> . <http://ld2sd.deri.org/demo#field1> rdf:type pb:UpdateableField ; pb:key ?post . } WHERE { <http://twitter.com/pushback_demo> sioc:container_of ?post . FILTER regex(str(?post), "1287833002", "i") }
You can try this query on an exemplary SIOC RDF graph.
Creation of the RDForm
- Parse HTML formular (yields: fields)
- Map RDF input graph as described above (yields: KVP representation)
- Create dynamically an HTML formular+RDFa decorated with the output of step 1. and 2. yielding the RDForm
The core of a first implementation looks like follows (see source code at the Google code Subversion repository for more details):
function fuse(){ var pbNS = "http://ld2sd.deri.org/pb/ns#"; var rdf_type = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; var pb_RDForm = pbNS + "RDForm"; var pb_UpdateableField = pbNS + "UpdateableField"; var pb_field = pbNS + "field"; var inputHTMLForm = $("#inputHTMLForm").val(); var baseURI = $("#baseURI").val(); var rdformRDFaHTML =""; var rdforms = rdfdoc.Match(null, null, rdf_type, pb_RDForm); $("#rdform").val(""); rdformURI = rdforms[0].subject; // the URI of the RDForm $(inputHTMLForm, "[id='" + rdformURI.slice(rdformURI.indexOf("#") + 1) + "']").each(function (i) {// look up in th input for the corresponding form rdformRDFaHTML += startForm(rdformURI, this.id, this.action, this.method); var rdformfields = rdfdoc.Match(null, rdformURI, pb_field, null); // get fields of this RDForm //alert(rdformfields.toNTriples()); for (rdformfield in rdformfields) { var rdformfieldURI = rdformfields[rdformfield].object; if(rdformfieldURI != undefined) { //alert(rdformfieldURI); var fieldID = rdformfieldURI.slice(rdformfieldURI.indexOf("#") + 1); // select C(R)UD op here: rdformRDFaHTML += addCRUDop(baseURI, rdformfieldURI, fieldID); // for each field set the according decorations rdformRDFaHTML += startField(rdformfieldURI, fieldID); // look up the correct label here: rdformRDFaHTML += addFieldKey(rdformfieldURI + ".key", fieldID, "LABEL"); //make case distinction on field type here: rdformRDFaHTML += startTextFieldValue(rdformfieldURI + ".val", fieldID); rdformRDFaHTML += endFieldValue(fieldID); rdformRDFaHTML += endField(fieldID); } } rdformRDFaHTML += endForm(this.id); }); $("#rdform").val(rdformRDFaHTML); showStatus("Fusion done. RDForm created."); }
RDForms Generator
A tool that let's you create RDForms based on an HTML form and a SPARQL CONSTRUCT query (mapping). A first fusion prototype is now available and looks as follows (please be patient, everything works online, here ;):