-
Notifications
You must be signed in to change notification settings - Fork 15
Example: How to set up a service
utils/lodspk.sh helps set up new model/view pairs.
First, let's check the usage:
/var/www/datafaqs/DataFAQs-lodspeakr$ utils/lodspk.sh
Usage: utils/lodspk.sh create|delete uri|class|service foo [html|rdf|ttl|nt|json]
Here, we want to make a service called "epochs", and we only want an html template (the machine formats come for free):
/var/www/datafaqs/DataFAQs-lodspeakr$ utils/lodspk.sh create service epochs html
...
service.epochs created/modified successfully!
We'll want to modify the model query and the view template that lodspk.sh made for us:
/var/www/datafaqs/DataFAQs-lodspeakr$ vi models/service.epochs/html.queries/main.query
/var/www/datafaqs/DataFAQs-lodspeakr$ vi views/service.epochs/html.template
Usually, you want to develop the SPARQL query that you want using the endpoint's UI. Once you have the essential structure, plop it into the main.query:
PREFIX void: <http://rdfs.org/ns/void#>
PREFIX sd: <http://www.w3.org/ns/sparql-service-description#>
PREFIX datafaqs: <http://purl.org/twc/vocab/datafaqs#>
SELECT DISTINCT ?epoch
WHERE {
GRAPH ?name {
?epoch a datafaqs:Epoch .
}
}
Then, visit the service with a web browser: http://aquarius.tw.rpi.edu/datafaqs/epochs
You'll probably see a list of empty values.
Go edit the view template
/var/www/datafaqs/DataFAQs-lodspeakr$ vi views/service.epochs/html.template
The default view template will be something like:
<ul>
{% for row in models.main %}
<li><a href="{{lodspk.baseUrl}}special/instances/{{ row.resource.curie }}">{{row.resource.curie}}</a></li>
{% endfor %}
</ul>
But our SPARQL query selects ?epoch
, so we need to change row.resource
to row.epoch
to access the query result.
change it to:
<ul>
{% for row in models.main %}
<li><a href="{{row.epoch.value}}">{{row.epoch.curie}}</a></li>
{% endfor %}
</ul>
See Creating services with slashes
- Check Introduction to Content Negotiation to learn how content negotiation works in services
- Example: How to set up a class
- Example: How to set up a uri
- Creating services with slashes
- Example: how to pass uris as arguments