Most of the time, raw RDF data retrieved from the web must be adapted in order for it to be displayed in the application view. SemanticKO makes possible to pre-process RDF data to be displayed in different ways:
data-bind
attribute.data-bind
attribute.
The function sko.current
can be used inside the data-bind
attribute to retrieve the RDF node object bound to the current DOM node. Properties of this RDF node can be then retrieved using the function sko.current().tryProperty
or sko.current().getProp
. These function can also be used to define properties in the view model.
A more re-usable way of defining adapter functions is to define RDF class objects. These objects are collection of functions that will be added to a bound RDF node if the triples for that node matches the description of the RDF class. Descriptions for RDF classes can be build combining simple constructs: URIs, CURIEs, ObjectUnionOf
, ObjectIntersectionOf
and ObjectSomeValuesFrom
. These building blocks can be combined to form complex class expressions testing for the presence of certain properties and or belonging to a list of RDF types.
In the example, four different ways of computing an adapted value for the foaf:name
property of a RDF node is shown. Two of these ways involve the definition of two RDF class objects, one associated to all the RDF nodes whose type is foaf:Person
and another one for all the RDF nodes with a value for the propert foaf:name
: ObjectSomeValuesFrom([foaf:name])
.