Skip to content

Example: How to set up a class

alangrafu edited this page Feb 17, 2012 · 10 revisions

In Example: How to set up a service, we showed how to create a new service. The example displayed a list of epochs. When clicking on one, we want to recognize that the URI requested is a datafaqs:Epoch and show specific aspects about the epoch that the generic type.rdfs:Resource model/view will do. So let's fire up utils/lodspk.sh again:

/var/www/datafaqs/DataFAQs-lodspeakr$ utils/lodspk.sh 
Usage: utils/lodspk.sh create|delete uri|type|service foo [html|rdf|ttl|nt|json]

Here, we want to make a type handler called for datafaqs:Epoch, and we only want an html template (the machine formats come for free):

/var/www/datafaqs/DataFAQs-lodspeakr$ utils/lodspk.sh create class datafaqs:Epoch html
...
class.datafaqs:Epoch created/modified successfully!

Although lodspk.sh made the models/class.datafaqs\:Epoch/html.queries/main.query model query for us, we anticipate a variety of queries to select different characteristics about the epoch. Se we'll rename main.query to subsets.query.

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/class.datafaqs\:Epoch/html.queries/subsets.query
  • /var/www/datafaqs/DataFAQs-lodspeakr$ vi views/class.datafaqs\:Epoch/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 subsets.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 ?subset
WHERE {
  GRAPH ?name {
     {{uri}} void:subset ?subset
  }
}

Then, visit an Epoch with a web browser: http://aquarius.tw.rpi.edu/datafaqs/epochs

What's next?

Clone this wiki locally