Skip to content

Ad hoc queries to select models and views

alangrafu edited this page Dec 4, 2012 · 6 revisions

In a normal environment with reasonably well structured data, LODSPeaKr can serve data related to different entities, just based on their type: Thus, if the URI requested is rdf:type foaf:Person, LODSPeaKr will execute the queries for personas and apply the template for persons.

Now, what happens if we have lots of typeless URIs (i.e., we don't have <uri> a :SomeClass) but we know they represent different types of entities (and thus, they have different properties)? Since version 20120704 it is possible to select models and views based on custom SPARQL queries.

  • Run git pull to get the latest version of LODSPeaKr
  • Enable the sparqlFilter module
    • You can run utils/lodspk.sh enable module sparqlFilter 0 (for performance issues, it would be better to put sparqlFilter after services but it must to go before types in the module priority queue. Look at Using lodspk.sh for more info)
    • Alternatively, you can enable the module by hand, by adding the following line in settings.inc.php
      • $conf['modules']['available'] = array('static', 'service', 'sparqlFilter', 'type', 'uri');
  • Create a directory components/sparqlFilter
  • Inside that folder create a new filter directory, say, hasDescription
  • Inside haveHomePage create:
    • filter.query will be an ASK SPARQL query that returns true or false
    • A file html.query which is a template as usual (please refer to "Type Components" in Models for details)
    • A directory queries which contains the sparql queries as usual (please refer to "Type Components" in Models for details)

For example, we may want to display all the URIs that have a dcterms:description by writing the following filter.query

ASK WHERE{
  <{{uri}}> dcterms:description []
}

Then, any URI requested that has a dcterms:description predicate will trigger this module and no other (check Modules for more details on how modules work).

Inside components/sparqlFilter you can create as many filters as you want, but remember that every filter means a new SPARQL query to be executed.

##Warning

This is a new module, so expect bugs (and please report them)

Relevant links

Clone this wiki locally