Skip to content

Theatre configuration

architolk edited this page Nov 2, 2016 · 2 revisions

You configure the Linked Data Theatre by creating Linked Data! The example below is a very simple configuration (turtle syntax) that will show every property of the city of Amersfoort as it appears in the DBPedia triplestore:

stage:Amersfoort a elmo:Representation;
	elmo:url-pattern "/query/amersfoort";
	elmo:endpoint <http://dbpedia.org/sparql>;
	elmo:query '''
		CONSTRUCT {
			<http://dbpedia.org/resource/Amersfoort> ?p ?o
		}
		WHERE {
			<http://dbpedia.org/resource/Amersfoort> ?p ?o
		}
	'''
.

To enable the LDT to use this configuration, you should upload the configuration to a special named graph in you triplestore. The named graph resembles the site at which your LDT is located.

For example: if your LDT is located at http://localhost:8080, the named graph will be: http://localhost:8080/stage.

Let's say that you've named your configuration myfirstconfig.ttl and you use a Virtuoso triplestore that runs on its default port. You could upload this configuration to your triplestore with the following command:

curl.exe -X PUT -T myfirstconfig.ttl http://localhost:8890/sparql-graph-crud?graph-uri=http://localhost:8080/stage  

Instead of using curl upload, you could also edit or upload your configuration files using the LDT management interface. The management interface for the LDT is located at /backstage (as would be appropriate for a theate!). The backstage only works for a correctly configured LDT in combination with Virtuoso.

Basic structure of a configuration

Every type of page or resource you want to show to your audience is represented in your configuration as an elmo:Representation. The basic structure of a representation contains the following items:

  1. The type of the representation (e.g.: elmo:Representation);
  2. A statement in what situation the representation should be used:
  • elmo:url-pattern: for a particular URL pattern;
  • elmo:uri-pattern: for a particular URI pattern (of the resource);
  • elmo:applies-to: for a partical type of resource.
  1. Declaration of the elmo:Appearance that should be used;
  2. The SPARQL query that is executed or the some set of literal data.

This wiki contains a separate page for every appearance that can be used with the theatre (please look at the sidebar). But let us first look at some easey examples.

Examples to start with

All examples use the following prefixes:

PREFIX elmo: <http://bp4mc2.org/elmo/def#>
PREFIX html: <http://www.w3.org/1999/xhtml/vocab#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX stage: <http://localhost:8080/stage#> 

Hello world example

Your first LDT example might look like this:

<helloWorld> a elmo:Representation;
	elmo:url-pattern "/query/helloWorld$";
	elmo:appearance elmo:HtmlAppearance;
	elmo:data [
		rdfs:label "Hello World";
		elmo:html '''
			<h3>Hello World!</h3>
			<p>This is the first of the Linked Data Theatre examples.</p>
		''';
	]
.

Let's look at this example:

  • The first line states that <helloWorld> is a Representation.
  • The next line states that this representation should be used whenever the URL conforms to the regex pattern /query/helloWorld$.
  • The third line states that this represenation should appear as an html-appearance. This means that the data is interpreted as plain html.
  • The last lines state that this representation contains some (static) data: the html that should be presented to the user.

First SPARQL example

The hello-world example didn't actually uses a triple store to fetch any data. The next example will fetch all graphs from the triple store.

<showGraphs> a elmo:Representation;
	elmo:url-pattern "/query/showGraphs$";
	elmo:query '''
		SELECT DISTINCT ?graph (count(?x) as ?tripleCount)
		WHERE {
			GRAPH ?graph {
				?x?y?z
			}
		}
	''';
.

Instead of the elmo:data triple, an elmo:query triple is included. This query contains the sparql query that is executed against the triple store. You might notice that this example doesn't contain an elmo:appearance. The LDT will use the default appearance for a SELECT query: elmo:TableAppearance.

Changing the header of a table

The Linked Data Theatre uses the names of the variables to display the table headers. You might change this, or even include multiple languages.

<showGraphs2> a elmo:Representation;
	elmo:url-pattern "/query/showGraphs2$";
	elmo:fragment [
		elmo:applies-to "graph";
		rdfs:label "RDF Graaf"@nl;
		rdfs:label "RDF Graph"@en
	];
	elmo:fragment [
		elmo:applies-to "tripleCount";
		rdfs:label "Aantal triples"@nl;
		rdfs:label "Triple count"@en
	];
	elmo:query '''
		SELECT DISTINCT ?graph (count(?x) as ?tripleCount)
		WHERE {
			GRAPH ?graph {
				?x?y?z
			}
		}
	''';
.

You'll notice the inclusion of two elmo:fragment statements. These statements are pretty self-explaining: the first line states to which variable the fragment should apply, the next two lines state the label for the header, in English and in Dutch.

Using a different SPARQL endpoint

The Linked Data Theatre is capable of accessing any available SPARQL endpoint (if the server has the appropriate connection). The remaining of our examples will use the data of the DBPedia endpoint.

<dbpedia> a elmo:Representation;
	elmo:url-pattern "/query/dbpedia$";
	elmo:endpoint <http://dbpedia.org/sparql>;
	elmo:query '''
		SELECT DISTINCT ?type
		WHERE {
			?s rdf:type ?type.
		}
		LIMIT 100
	''';
.

The elmo:endpoint statement is used to indicate the remote SPARQL endpoint.

Representing data of one resource

It is quite common to only show data of one resource. You can use a CONSTRUCT query for such situations. You can also use special URI-parameters to include in you statement. @SUBJECT@ will always contain the URI of the subject resource, and @LANGUAGE@ the current language of the user (as configured in the user's browser). Other parameters are accessible by simple using the pattern @<parameter name in capitals>@. The following example returns all available triples about the city of Amersfoort in DBPedia.

<amersfoort> a elmo:Representation;
	elmo:url-pattern "/query/amersfoort";
	elmo:endpoint <http://dbpedia.org/sparql>;
	elmo:query '''
		CONSTRUCT {
			<http://dbpedia.org/resource/Amersfoort> ?p ?o
		}
		WHERE {
			<http://dbpedia.org/resource/Amersfoort> ?p ?o
		}
	'''
.
Clone this wiki locally