Skip to content

Filters in LODSPeaKr

alangrafu edited this page Feb 26, 2013 · 39 revisions

What is first

Let's get to it

The [LODSPeaKr templating system](Templating system in LODSPeaKr) comprises model queries that feed view templates.

Filters preprocess result values before inserting it into the view template. LODSPeaKr provides a way to embed javascript objects using Haanga filters.

Example

Lets say we have a model and view for foaf:Person

components/types/foaf:Person/    # This directory contains queries for instances of class foaf:Person 
                            |->queries/
                            |         |-> personalDetails.query # This file contains a SPARQL query
                            |         |-> friends.query         # This file contains a SPARQL query
                            |->html.template

In friends we have the following query

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name ?lastname WHERE{
  <{{uri}}> foaf:knows [ foaf:firstName ?name;
                         foaf:lastName ?lastname
                       ].
}

In the view foaf:Person.view.html we can do the following

<html>
  <head>
    <title>My Page</title>
  </head>
  <body>
    My friends {{models.friends|GoogleVizTable:"name,lastname"}}
  </body>
</html>

The whole array is passed to the filter, and the parameters and passed after it in quotes and separated by commas. The result (assuming there is data that matches the query) is something like this:

Filter for Google Table

List of implemented filter in LODSPeaKr

Besides the existing filters in Haanga, LODSPeaKr have a few (but soon the list should increase)

TODO: The arguments should be more consistent!

  • Explode, returns an array based on a string and a delimiter
    • {{first.myModel.myString.value|explode:" "|length}} returns the number of words (separated by " ") in the variable
  • Pop, returns the last value in an array
    • {{first.myModel.myString.value|explode:" "|pop}}
  • Date (look at the php documentation for formatting options)
    • {{first.myModel.myDate.value|date:"l jS \of F Y h:i:s A"}}
    • {{first.myModel.myDate.value|date:"H:i l F jS \o"}}
  • hostname, returns which hostname (e.g., www.example.org) from a URI
  • URIScheme, returns which scheme (e.g., http, https) is used in the URI
    • {{first.myModel.myUri.value|urischeme}} returns https
  • URIPath, returns the path (without the hostname or URI fragment) of a URI
    • {{first.myModel.myUri.value|uripath}} returns something like /my/path/foo/bar.html
  • URIFragment, returns the fragment after a # in a URI. If no # is found, returns the whole URI
    • {{first.myModel.myDate.value|urifragment}}
    • http://www.w3.org/2004/02/skos/core#Concept will return Concept
    • http://xmlns.com/foaf/0.1/Group will return http://xmlns.com/foaf/0.1/Group
  • Urifier, converts an URI in a set of segments so it can be used as arguments by a service. A details example is available at Example: how to pass uris as arguments
  • Deurifier, translates a set of segments (e.g, {{lodspk.args.all|deurifier}}) and translate into a proper URI. A details example is available at Example: how to pass uris as arguments

###Visualization filters A special category of filters provides javascript-based visualizations

  • CirclePacking
    • {{D3CirclePacking|childNode,parentNode}}

Circle Packing

  • D3Dendrogram
    • {{D3Dendrogram|childNode,parentNode}}

D3Dendrogram

  • D3ForceGraph
    • {{D3ForceGraph|sourceNode,TargetNode}}

D3ForceGraph

  • D3ParallelCoordinates
    • {{D3ParallelCoordinates|label,value1,value2,...,valueN}}

D3ParallelCoordinates

  • D3WordCloud
    • {{D3WordCloud|variableWithFreeText}}
    • {{D3WordCloud|phraseVariable,sizeOfPhrase}}
    • {{D3WordCloud|phraseVariable,sizeOfPhrase,linkOnEachPhrase}}

D3WordCloud

  • D3RadarChart
    • {{D3RadarChart|value1,value2,value3,...,valueN}}

D3RadarChart

  • Timeknots
    • {{Timeknots|date,label[,image]}}

GoogleVizTable

  • GoogleMaps
    • {{GoogleMaps|latitude,longitude,label}}

GoogleMaps

  • GoogleVizBarChart
    • {{GoogleVizBarChart|valuesInAxisX,valuesInAxisY}}

GoogleMaps

  • GoogleVizColumnChart
    • {{GoogleVizColumnChart|valuesInAxisX,valuesInAxisY}}

GoogleVizColumnChart

  • GoogleVizLineChart
    • {{GoogleVizLineChart|valuesInAxisX,valuesInAxisY}}

GoogleVizLineChart

  • GoogleVizPieChart
    • {{GoogleVizPieChart|valuesInAxisX,valuesInAxisY}}

GoogleVizPieChart

  • GoogleVizScatterChart
    • {{GoogleVizScatterChart|valuesInAxisX,valuesInAxisY}}

GoogleVizPieChart

  • GoogleVizTable
    • {{GoogleVizTable|column1,column2,...,columnN}}

GoogleVizTable

Filter patterns

To get an abbreviated URL like https://raw.github.com...golfers.xls.zip from https://raw.github.com/timrdf/csv2rdf4lod-automation/master/doc/examples/source/lebot/golfers/version/original/manual/golfers.xls.zip, use either of the following:

  • http://{{row.resource.value|hostname}}...{{row.resource.value|explode:"/"|pop}}
  • if your URLs don't have a URI fragment: http://{{row.resource.value|hostname}}...{{row.resource.value|path|explode:"/"|pop}}

What's next?

Clone this wiki locally