Lecture 13: Lore and TripleLore

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.

Slides

Relevant Wiki-pages

Exercises

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 semantics/urb.lore with

wget http://leifhka.org/in5800/lectures/lore/urb.lore

This file also imports some convenient libraries. The libraries imported are as follows:

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 semantics/urb.lore with

make urb_relations

Remember to execute

make clean_dbs

between each run.

Finally, make sparqlify_class and sparqlify_properties statements mapping you classes and properties, write the SPARQL-query queries/find_address.sparql and execute it with

make find_address

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 ex:northof.

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 exo.

2.1 RDFS

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:Planet, exo:orbitsStar, etc.). Remember that all properties must be typed with either owl:ObjectProperty or owl:DatatypeProperty, and that all owl:DatatypeProperties needs an rdfs:range.

  1. Introduce classes for solar systems, planets, stars and moons, and state that these are all astronomical objects.
  2. State that exo:orbitsStar has domain astronomical object and range star (use the classes introduced above).
  3. State that exo:orbitsPlanet has domain moon and range planet.
  4. Make a new property exo:orbits, and that both exo:orbitStar and exo:orbitsPlanet are subproperties of ex:orbits, and that exo:orbits relates astronomical objects
  5. Add rdf:type, rdfs:domain and rdfs:range for all properties used in the data (i.e. rdfs:label, exo:density and exo:discovered)

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

2.2. SPARQL

  1. Use TripleLore and SPARQL to find all exo:orbits-relationships
  2. Use TripleLore and SPARQL to find all planets.

Solution

The solution to the exercises can be found here.