An example

The following example defines a Jelly View which gives information about siblings. Data about parents are given as extensional knowledge in the form of relation in the database. They are held by a relational schema: Parent(child_name,parent_name). Its state is given in Table 8.3.


Table 8.3: State of Parent(child_name,parent_name).
Parent:
child_name parent_name
john james
mary james
ann mary
simon mary
michael ann
alice john


The Jelly View is generated by the following Prolog program:

  sibling(X,Y) :- parent(X,Z), parent(Y,Z), X \== Y.
This program can be presented, in a decomposed form, as a set of relations given in Table 8.4. The External Matching is given in Table 8.5. The Internal Matching is given in Table 8.6.


Table 8.4: Decomposed Prolog Program.
clause
id name order preconditioned symbol
1 sibling NULL NULL 1
2 parent 1 1 2
3 parent 2 1 2
4 $\backslash$== 3 1 4
argument
name position clause
X 1 1
Y 2 1
X 1 2
Z 2 2
Y 1 3
Z 2 3
X 1 4
Y 2 4
logical operator
id symbol
1 :-
2 ,
3 ;
4 .




Table 8.5: External Matching.
table-predicate
id predicate table
1 sibling sibling
tp-argument
name type table-predicate position
name1 varchar 1 1
name2 varchar 1 2




Table 8.6: Internal Matching.
predicate-table  
id predicate arity table
1 parent 2 Parent




Table 8.7: Auxiliary Relations.
tp-clause
program clause order
1 1 10
tp-pt
table-predicate predicate-table
1 1



The auxiliary relations are given in Figure 8.7. The relation tp-pt is used to establish a many-to-many relationship between table-predicate and predicate-table, which is denoted as has in Figure 8.3, while the relation tp-clause establishes many-to-many relationships between table-predicate and clause and it is denoted as consists_of in Figure 8.3. Description of the attributes for the Matchings and auxiliary relations is given in Table 8.8. Description for the program is analogous as the description for Table 8.1.


Table 8.8: Attributes of the Matchings and auxiliary relations.
attribute description
table-predicate.id primary key
table-predicate.predicate goal name
table-predicate.table Jelly View name
tp-argument.name Jelly View argument name
tp-argument.type Jelly View argument type in terms of RDBMS
tp-argument.table-predicate foreign key referring to table-predicate.id
tp-argument.position position of the argument, an arbitrary integer
predicate-table.id primary key
predicate-table.predicate predicate name
predicate-table.arity predicate arity
predicate-table.table relation name
tp-clause.program foreign key referring to table-predicate.id
tp-clause.clause foreign key referring to clause.id
tp-clause.order clause order in the program
tp-pt.table-predicate foreign key referring to table-predicate.id
tp-pt.predicate-table foreign key referring to predicate-table.id


Then, the query:

  SELECT * FROM sibling('simon',NULL);

will give the following reply:

name1 name2
simon ann


where name1 and name2 are column names defined by External Matching, and more precisely by tp-argument relation. The reply states that ann is simon's sibling.

Igor Wojnicki 2005-11-07