Contact:
- rjasko (zavinac) dcs.fmph.uniba.sk
Databases practicum, winter 2023/2024
Michal Rjaško, rjasko at dcs.fmph.uniba.sk
Ján Mazák, M255, mazak at dcs.fmph.uniba.sk
Homeworks
There will be three homeworks published here. The first homework will be published after 4th lesson.
Lesson 3
Datalog
- Download the following files into one directory:
- queries_library.pl --- list of queries you need to create; you will edit this file
- query.pl --- auxiliary file containing the definition of the q(_) command for formatting query results
- Follow the instructions in the file queries_library.pl. Start by creating the database library.pl (use emp.pl from the previous exercise as a model).
Add rows to the database to allow you to test the correctness of your solutions for individual queries.
- You can also have multiple versions of the database --- the database used is specified in line
:- consult('library.pl').
- We recommend that you concentrate on solving tasks 1, 3, 6, 7, 8 already during the exercise and tasks 10, 11, 15, 16 during the exercise or at home.
Lesson 2
Datalog
- presentation
- Download the following files into the same directory:
- emp.pl --- EMP employee database
- queries.pl --- A file containing a list of exercises. Edit this file.
- query.pl --- utility file containing the definition of the q(_) command for formatting query results
- According to the instructions from the previous exercise (or "Working with datalog" in the presentation), solve the tasks in queries.pl.
Lesson 1
Prolog
- For the first attempts, we will use the online environment for SWI-Prolog.
- presentation (if you want, check also this light intro to prolog)
- Exercises:
- Define some facts about family relationships using predicates male/1, female/1, parent/2 (the number indicates arity).
- Write down the rules for predicates expressing father, sister, grandmother, cousin
- Create the predicate ancestor/2 for the relation "to be an ancestor".
- Create the predicate related/2 for the relation "being a blood relative".
Datalog on server cvika
- Login to cvika.dcs.fmph.uniba.sk using ssh (linux, windows (PuTTY)).
- Using wget download the following files:
- query.pl --- utility file containing the definition of the q(_) command for formatting query results
- emp.pl --- EMP employee database
- queries.pl --- A file containing a list of exercises. Edit this file.
-
- We will use SWI-prolog to interpret datalog queries: run
swipl -s queries.pl
- In another window, edit the file queries.pl; we recommend the editors vim (for console environment) or kwrite (graphical mode if you work on a local computer).
- We recommend having the database (the emp.pl file with the list of facts) open in the next window to check the query results.
- After each modification of the queries.pl file (don't forget to save the changes), run the
make.
command in the running SWI-prolog (even with a dot at the end, we write the commands after a question mark). Check the compiler results for errors.
- We start the calculation of the query (in this example for the predicate job) as follows:
q(job(J)).
The name of the variables does not matter, in place of J can be used also _, but arity (number of arguments) must be present. The q() predicate is used for "nice" formatting of the output and elimination of apparent duplicates.
- Practical tips for SWI-prolog:
- Strings starting with an uppercase letter are considered variables by the system. Constants start with lowercase letters. If you mess it up, it will give strangely bad results.
- The is operator is used to evaluate arithmetic expressions, i.e. X is 2+3, not X = 2+3 (in the latter case the symbol = will be interpreted as the unification of terms and no arithmetic operation will occur).
- The following operators are used to compare numbers <, =<, >, >=.
Evaluation
For each of the 3 homework assignments, there is a max. 30 points.
Additional points are obtained for solving exersises from lessons: 0 or 1 point for each of the 12 lessons. From the points awarded for lesson exercises, it is necessary to obtain at least 9 to successfully complete the course.
Within 3 days after each lesson, solutions must be sent by e-mail to the address rjasko (at) dcs.fmph.uniba.sk.
Subsequently, the solutions will be briefly evaluated: in case of sufficiency, 1 point will be awarded, in case of insufficiency, the student will be asked to supplement the solution (if he submitted at least something meaningful), for which he has another 3 days, and then he will receive a final evaluation.
Not all exercises need to be solved; it is neccessary to have solved (at least somehow correctly) about 40% of the exercises from each topic. If the set of exercises is more extensive, they are usually at least approximately in order of
difficulty; if you want to solve a minimum of exercises, choose some more demanding ones from the second half. The recommended procedure is to go in order and skip exercises where it is clear that
you already know how to solve them (eg they are similar to already solved exercises and you can see what the difference is and how to deal with it).
- A --- 92 and more points
- B --- 84 - 91 points
- C --- 76 - 83 points
- D --- 68 - 75 points
- E --- 60 - 67 points
- Fx --- less than 60 points