This is a step by step demonstration and occasional explanation of the RDF2h features. You can edit all examples in the browser and executed scripts again to see the effects of changes in the code.
rdfs
:Resource
Applied to the following data graph:
return new RDF2h(renderers).render(data, "http://example.org/");
dc
:title
)to its value. The renderer defined in the following graph follows the
foaf
:knows
property backwards and then the
foaf
:knows
property forwards.
Applied to the following data graph:
return new RDF2h(renderers).render(data, "http://example.org/a");
return new RDF2h(renderers).render(data, "http://example.org/a");
+
, the resulting expression evaluates to true when the path exists and to false otherwise. Note that this doesn't change
the evaluation context, so that the value of
.
doesn't change and the property needs to be accesses like outside the block. It may be used in combination with a loop over
the property.
:render
a resource is given back to the rendering engine for rendering. Typically
:render
is invoked between triple-braces to avoid double escaping.
Applied to the following data graph:
return new RDF2h(renderers).render(data, "http://example.org/a");
foaf
:OnlineChatAccount
that can be used instead of the more generic renderer for
foaf
:OnlineAccount
. To allow RDF2h to know which type is more specific we also added the statement
foaf
:OnlineChatAccount
rdfs
:subClassOf
foaf
:OnlineAccount
.
return new RDF2h(renderers).render(data, "http://example.org/a");
r2h
:javaScript
property which points to some js code writing that returns the rendering result. The code has access to the following
variables:
n
,
context
,
$rdf
and to the function
render(graphNode, context)
.
Applied to the following data graph:
return new RDF2h(renderers).render(data, "http://example.org/a");
Note the recursive invocation of the renderer. This would lead to an infinite loop if one of the persons known by Alice
would know her back. A way to avoid this would be to change context by invoking the
render
function with a second argument and to provide a renderer that doesn't further expands the value of the
foaf
:knows
property.