RDF Editing on the Web Claus Stadler Natanael Arndt Department of Computer Department of Computer Science, University of Leipzig Science, University of Leipzig cstadler@informatik.uni- arndt@informatik.uni- leipzig.de leipzig.de Michael Martin Jens Lehmann Department of Computer Department of Computer Science, University of Leipzig Science, University of Leipzig martin@informatik.uni- lehmann@informatik.uni- leipzig.de leipzig.de ABSTRACT lution is based on using the popular AngularJS framework2 While several tools for simplifying the task of visualizing to define a custom set of HTML attributes which add an (SPARQL accessible) RDF data on the Web are available RDF context to form controls in the DOM-tree. While this today, there is a lack of corresponding tools for exploiting approach is similar to RDFa3 , there are two fundamental standard HTML forms directly for RDF editing. The few differences: First, RDFa is intended for static annotation of related existing systems roughly fall in the categories of (a) HTML documents, whereas our annotations are processed applications that are not aimed at being reused as compo- by AngularJS and our framework at runtime based on the nents, (b) form generators, which automatically create forms applications’ state. Second, RDFa is aligned with the HTML from a given schema – possibly derived from instance data standard, whereas our approach exploits concepts of Angu- – or (c) form template processors which create forms from a larJS and builds upon its abstractions, most prominently manually created specification. Furthermore, these systems the one introduced by ngModel 4 Also, a key distinguish- usually come with their own widget library, which can only ing feature that contrasts current related work is, that our be extended by wrapping existing widgets. In this paper, we system does not introduce a widget framework of its own. present the AngularJS-based Rdf Edit eXtension (REX) sys- Instead, by building on the AngularJS framework and its tem, which facilitates the enhancement of standard HTML abstractions, many already available widgets can be re-used forms as well as many existing AngularJS widgets with RDF directly without the need of wrapping. editing support by means of a set of HTML attributes. We demonstrate our system though the realization of several Our contributions in this paper are twofold: First, we present usage scenarios. the Rdf Edit eXtension system (REX), which makes HTML forms RDF-aware using a set of custom HTML attributes. Second, we devise several usage patterns of our system for 1. INTRODUCTION solving common problems related to RDF editing. RDF is designed to provide a uniform data model for repre- senting knowledge across domain boundaries. However, sus- Our RDF editing system is implemented as a user interface taining this flexibility in the context of RDF editing systems module as part of our Javascript S uite for S PARQL Access has turned out to be a difficult task. While there are Web (Jassa) library [5]. The module is freely available on Github5 applications for editing RDF data, such as WebProtege1 , and is registered for use as a dependency with the popular there is a lack of components for the light-weight integra- bower tool6 under the name jassa-ui-angular-edit. Fur- tion of such capabilities into Web applications. In this pa- ther, demos are available online7 . per, we present a novel approach to RDF authoring, which, to the best of our knowledge, delivers unprecedented flexi- The structure of this paper is as follows: In Section 2, we bility and ease in converting HTML form data to RDF and introduce our REX approach and discuss its use in several demonstrate its applicability in various use cases. Our so- scenarios. A brief outline of use cases is given in Section 3. In Section 4, we review existing approaches to RDF authoring 1 http://protegewiki.stanford.edu/wiki/WebProtege and presentation on the Web and discuss their strengths and weaknesses. Finally, in Section 5 we conclude this paper. 2 https://angularjs.org/ 3 http://www.w3.org/TR/rdfa-syntax/ 4 https://docs.angularjs.org/api/ng/directive/ng Model 5 https://github.com/GeoKnow/Jassa-UI-Angular/tree /master/jassa-ui-angular-edit 6 http://bower.io/ 7 http://js.geoknow.eu/demos/rex/ 96 2. RDF EDIT EXTENSIONS Note, that the Talis RDF JSON is used as an intermediate In this section we, explain our REX annotation system for representation. The final RDF graph, that corresponds to extending HTML forms with support for RDF editing. We the form state, can be serialized in any RDF syntax, includ- introduce our approach using a simple example, then explain ing JSON-LD10 . what types of data REX manages and finally we present sev- eral patterns for solving common problems. Note, that our For convenience, prefixes can be used to abbreviate IRIs. By annotations can also be used for retrieving data intended default, all prefixes of the RDFa initial context11 are readily for display. However, REX is focused on the support of bi- available. Custom namespaces can be enabled by specifying directional mapping of values between an RDF graph and rex-prefix, where the argument must follow the same syn- the model of form controls. Thus, support for arbitrary tax as in RDFa12 . Also, REX features the short hands rex- SPARQL queries and post-processing of result sets, such as iri="m" and rex-literal="m", which are expanded to rex- chosing the best label in regard to preferences on vocabular- type="‘uri’", rex-value="m" and rex-type="‘literal’" ies and languages, is not part of the core. and rex-value="m", respectively. It is important to understand, that AngularJS makes it pos- Whenever multiple attributes occur on the same element, sible to annotate HTML form controls with ng-model="foo", the order of processing depends on their priority value. For which declares a JavaScript variable foo as the model of the details please refer to the documentation on Github. control. When the user enters input, the model’s value is changed accordingly, and when the model changes, Angu- 2.2 Accessing the Data and Modifications larJS automatically updates the form control to reflect the The rexContext object is a container for all relevant infor- new state. Our approach is based on the introduction of a mation about the state of the form and performed modifi- set of annotations which give model values an RDF context. cations. It provides the following attributes: In the subsequent sections we explain the REX attributes. 2.1 Core HTML Attributes • .base The base RDF graph, in Talis RDF JSON, which Consider the example in Listing 1. First of all, the rex- holds information about the resources referenced by context is used to activate the REX system on a DOM the form controls. This information is automatically element and its descendants. The presence of the attribute updated accordingly when the set of subject resources creates the rexContext object in the corresponding scope, and or lookup functions change. whose purpose is to keep track of (a) RDF values referenced in form controls, (b) initial data for prefilling forms, (c) mod- • .override A (partial) Talis RDF JSON object which ifications to the initial data for computing diffs, and (d) the holds the state of the data entered into the form and final RDF data. which can be seen to “override” any base data. 1
the ith RDF term for a given subject and predicate. Inter- 2 {{graphToTurtle(rc.graph, rexPrefixMapping)}}
nally, the Talis RDF JSON9 model is used for representing 3 {{createInsertRequest(rc. diff .added, rexPrefixMapping)}}
RDF data. Hence, RDF objects comprise four components 4 {{createDeleteRequest(rc. diff .removed, rexPrefixMapping)}}
5
of type string, that can be accessed using the annotations
rex-type, rex-value, rex-lang, and rex-datatype. In ad- Listing 2: Example of serializing the current state of the
dition, rex-deleted can be used to flag an object at a cer- RDF graph as turtle, and creating SPARQL 1.1 Update
tain index – and thus the corresponding triple – as deleted. queries from the diff
We refer to the combination of a subject IRI, predicate IRI,
object index and component name as a coordinate. A coordi-
nate uniquely references a primitive value in an RDF graph. 10
http://json-ld.org/
8 11
https://docs.angularjs.org/api/ng/service http://www.w3.org/2011/rdfa-context/rdfa-1.1
12
/$interpolate http://www.w3.org/TR/rdfa-syntax/#A-prefix
9 13
http://www.w3.org/TR/rdf-json/ http://www.w3.org/TR/rdf-interfaces/
97
2.3 Conditional RDF generation
There are cases when RDF output should be constructed 1