-
Notifications
You must be signed in to change notification settings - Fork 15
How to use results
The [LODSPeaKr templating system](Templating system in LODSPeaKr) comprises model queries that feed view templates. Values obtained by applying model queries are available to subsequent model queries and view templates. This page describes the values that are available in both of these situations.
LODSPeaKr uses Haanga as its template engine. For detailed examples on how to use Haanga, please refer to their documentation.
Result values can be used in views as well as in other models. Values have the following syntax (where periods (.
) are literal and <model>
and <variable>
should be replaced with the name of your model and variable, respectively.
{{models(.<model>)+.<variable>.value}}
So far, what you can get from variables are
-
{{models(.<model>)+.<variable>.value}}
the actual value -
{{models(.<model>)+.<variable>.uri}}
contains value "1" if it is a URI -
{{models(.<model>)+.<variable>.blank}}
contains value "1" if it is a Blank Node -
{{models(.<model>)+.<variable>.literal}}
contains value "1" if it is a Literal -
{{models(.<model>)+.<variable>.curie}}
contains the curie form of the URI (if it is a literal, it contains the same value as.value
) -
{{models(.<model>)+.<variable>.localname}}
contains the last part of the curie (for example, if a curie isfoaf:name
, the localname will bename
) -
{{models(.<model>)+.<variable>.mirroredUri}}
contains the original URI (if it has been mirrored) -
{{models(.<model>)+.<variable>.type}}
contains the datatype, if the variable contains a typed literal -
{{models(.<model>)+.<variable>.lang}}
contains the language tag of the literal, if exist.
###Taking the first value
-
{{first(.<model>)+.<variable>.value}}
the actual value -
{{first(.<model>)+.<variable>.uri}}
contains value "1" if it is a URI -
{{first(.<model>)+.<variable>.blank}}
contains value "1" if it is a Blank Node -
{{first(.<model>)+.<variable>.literal}}
contains value "1" if it is a Literal -
{{first(.<model>)+.<variable>.curie}}
contains the curie form of the URI (if it is a literal, it contains the same value as.value
) -
{{first(.<model>)+.<variable>.localname}}
contains the last part of the curie (for example, if a curie isfoaf:name
, the localname will bename
) -
{{first(.<model>)+.<variable>.mirroredUri}}
contains the original URI (if it has been mirrored) -
{{first(.<model>)+.<variable>.type}}
contains the datatype, if the variable contains a typed literal -
{{first(.<model>)+.<variable>.lang}}
contains the language tag of the literal, if exist.
The tree structure is
models/
|
-> type.foaf:Person/ # This directory contains queries to apply to instances of class
|
->html.queries/
|
-> main.query # This file contains a SPARQL query
|
-> friends1.query
|
->endpoint.dbpedia/
|
->friends2.query
Also, lets suppose friends1
and friends2
contains the following query
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?s
WHERE {
?s ?p ?o .
}
In this case we can access the variables in friends1
by writing
{%for i in models.friends1%}
{{i.s.value}} {{i.p.curie}}
{%endfor%}
While friends2
{%for i in models.dbpedia.friends2%}
{{i.s.value}} {{i.p.curie}}
{%endfor%}
To obtain only the first value, we can use a shortcut
{{first.friends1.name.value}} is the FIRST name of the list
{{first.dbpedia.friends2.name.value}} is the FIRST name of the other list
Which is equivalent to
{%for i in models.friends1%}
{%if forloop.first%}
"{{i.name.value}}" is the FIRST name of the list
{%endif%}
{%endfor%}
{%for i in models.dbpedia.friends2%}
{%if forloop.first%}
"{{i.name.value}}" is the FIRST name of the other list
{%endif%}
{%endfor%}
{%if !forloop.last%}
can be used for "not last value", as illustrated below in a simple JSON view template:
[
{% for row in r.main %}
"{{row.input.value}}"{%if !forloop.last%},{%endif%}
{% endfor %}
]
If a model query selects an optional value, the {%if row.dump%}{%endif%}
construct can be used to omit the value in the view template. {%else}
can also be used.
{% for row in models.main %}
<tr>
<td>{{row.name.value}}</td>
<td>{%if row.dump%}<a href="{{row.dump.value}}">dump</a>{%else%}not found{%endif%}</td>
</tr>
{% endfor %}
Sometimes it is cumbersome to do a for
just to get the first (sometimes the only) value. For that purpose it is possible to replace r
for first
and access directly the first variable
{%for i in models.details%}
{%if forloop.first%}
"{{i.name.value}}" is the FIRST name of the list
{%endif%}
{%endfor%}
is equivalent to
{%for i in models.details%}
"{{first.details.name.value}}" is the FIRST name of the list
{%endfor%}
TODO: are these available in model queries AND views?
There are a few variables available by default
-
{{uri}}
Contains the URI that is being requested (this is a shortcut for{{lodspk.this.value}}
) -
{{lodspk.this.value}}
is the URI requested and{{lodspk.this.curie}}
in its CURIE form -
{{lodspk.this.contentType}}
The content type that will be served -
{{lodspk.local.value}}
is the mirrored/local URI requested (if the data is in domainhttp://a/
buy is served in domainhttp://b/
, the mirrored URI will use the second domain). Analogously,{{lodspk.this.curie}}
is the mirrored/local uri in CURIE form. -
{{lodspk.local.contentType}}
The content type that will be served -
{{lodspk.ns.NAMESPACE}}
The URI for a particular namespace (e.g.,{{lodspk.ns.foaf}}
,{{lodspk.ns.rdfs}}
) -
{{lodspk.queries}}
contains the URLs of the queries used by this component. The format is the same as in models. For more details, see Obtaining URLs of the queries used in a component
Haanga supports multiple filters (i.e., functions that preprocess the values passed). They are applied by using |
after the variable.
{%for i in models.names%}
{{i.name.value|title}}
{%endfor%}
Will turn the first letter to uppercase and the rest to lowercase. The best place to find the filters available in Haanga is to look at its repository. In addition to those provided by Haanga, LODSPeaKr provides [filters](Filters in LODSPeaKr) that can be used to display data using different visualizations.
{% for row in models.main %}
<li> {{row.resource.value|safe|urifragment}} </li>
{% endfor %}
- Refer to Default Values in Template.
- Remember you can Include your own variables
You can handle crazy query results using this pattern like this does:
{%for row in models.all_property_details%}
{%ifchanged row.property.value%}
{%if !forloop.first%}
</div>
</table>
{%endif%}
<div id="{{row.property.value|safe|urifragment}}">
<table class="prov-detail">
<tr><th colspan="2" style="background-color:#EAF2D3; color:black;">
<a href="#{{row.property.value|safe|urifragment}}">{{row.property.curie}}</a></th>
</tr>
<tr><td>IRI</td><td><span style="font-family: sans-serif">{{row.property.value}}</span></td></tr>
{%endifchanged%}
{%if row.comment%}
<tr><td>comment</td><td>{{row.comment.value}}}</a></td></tr>
{%endif%}
{%if row.domain%}
<tr><td>has domain</td>
<td><a href="#{{row.domain.value|safe|urifragment}}">{{row.domain.curie}}</a></td>
</tr>
{%endif%}
{%if row.range%}
<tr><td>has range</td>
<td><a href="#{{row.range.value|safe|urifragment}}">{{row.range.curie}}</a></td>
</tr>
{%endif%}
{%if row.inverse%}
<tr><td>has inverse</td>
<td><a href="#{{row.inverse.value|safe|urifragment}}">{{row.inverse.curie}}</a></td>
</tr>
{%endif%}
{%if forloop.first%}
</table>
</div>
{%endif%}
{%endfor%}
- Filters-in-LODSPeaKr for more advance handling of model query values.
- How you can Include your own variables
- Obtaining URLs of the queries used in a component