In this lecture, we will look at the two systems Lore and TripleLore. Lore introduces reasoning over relational databases via a Datalog-like language. TripleLore is a triplestore using Lore as a backend.
Exercise 1: Finding the Scroll (Revisited) – Lore and TripleLore
In this exercise we will redo exercise 2 in the exercises for Saturation, but use Lore instead of KiWi.
Download this modified Makefile. This Makefile downloads the same files as the one used in the original exercise, except that it downloads the Lore and TripleLore programs in place of Toko.
To get you started, download this Lore-script that defines all the relations you need and save it to
This file also imports some convenient libraries. The libraries imported are as follows:
common_prefixes.lore: Contains (via its own
prefix-relations and the
qn-function for making QNames, and in addition adds some commonly used prefixes to the
sparqlify.lore: Contains the
sparqlify_propertiesrelations used for making your relations queryable with SPARQL via TripleLore.
mappings.lore: Contains the function
map.urifor making URIs from keys.
If you open up the URL in your favorite browser, you can see the content of each import as well as comments describing each element.
Now, extend the Lore-script you downloaded with implications that defines all the relations. Remember that in Lore, you can also use complex expressions to e.g. extract the street number and name or use comparisons on street number with
You can execute
Remember to execute
between each run.
sparqlify_properties statements mapping you classes and properties, write the SPARQL-query
queries/find_address.sparql and execute it with
to see where the scroll was hidden!
Note: As SQL is case-insensitive for names of schema elements (tables, views, etc.) all properties and classes will be written in all lower-case. Thus, in place of
ex:nortOf you will have to write
Also note that both the reasoning and the SPARQL-query might take a few seconds. This is because we have not added any indecies. If you want to speed up the reasoning you can add an index to each column of you relations. In the future, it is planned to add another keyword to Lore, namely
INDEXED one can use when creating relations in order to automate the index creation.
Exercise 2: TripleLore
In this exercise we will also revisit exercises from a previous week, namely exercises 1. and 2. from the week on Semantics and Reasoning. However, we will again now solve them using Lore and TripleLore.
The exercise texts are quite similar, but with some small changes to accomodate the new technologies. If you have done these exercises earlier, you are of course free to only change your solution according to these changes. The point of these exercises is to apply Lore and TripleLore. Changes are made in italics. Note that prefixes cannot contain the letter
-, so e.g.
ex-o is changed to
Download this RDF dataset about astronomical bodies.
We will make an RDFS ontology encoding information the classes and properties used, and we will use the prefix
exo to denote
<http://example.org/ont/>, and use this as prefix for all new resources (e.g.
exo:orbitsStar, etc.). Remember that all properties must be typed with either
owl:DatatypeProperty, and that all
owl:DatatypeProperties needs an
- Introduce classes for solar systems, planets, stars and moons, and state that these are all astronomical objects.
- State that
exo:orbitsStarhas domain astronomical object and range star (use the classes introduced above).
- State that
exo:orbitsPlanethas domain moon and range planet.
- Make a new property
exo:orbits, and that both
exo:orbitsPlanetare subproperties of
ex:orbits, and that
exo:orbitsrelates astronomical objects
rdfs:rangefor all properties used in the data (i.e.
Finally use TripleLore and Lore to load the file into your database. Note that you first need to use TripleLore to transform the RDF-file into a
.lore-file, and then use Lore to translate that into an SQL-script that you can execute in your database (e.g. with
psql). When using TripleLore you should list both RDF-files in the command, e.g.:
java -jar triplelore.jar -o astronomy.lore astronomy_data.ttl astonomy_ont.ttl
- Use TripleLore and SPARQL to find all
- Use TripleLore and SPARQL to find all planets.
The solution to the exercises can be found here.