Skip links
Main content

Mapping to a relational database

zondag 06 januari 2013 21:17

Up until now I had always looked at the mapping of a semantic sentence representation to the tables of a database as something that required some hacking. But now I found a proper way to deal with it.

Given a logical representation of a sentence, say

In what year did Mary Shelley write Frankenstein?

write(e, a, b)
name(a, "Mary Shelley")
name(b, "Frankenstein")
time(e, t)

you want to use a database to find out the answer (t).

In this article I want to share a key concept and work it out with some examples.

The key concept is:

Create an explicit, declarative mapping of logical relations to database relations.

The predications I named before serve the purpose of relations, as they describe true relations of given objects. Relational databases also contain relations (yes, really :) ). But these relations are not the same. So, in order to access the database, there needs to be some form of transformation of the predications to the query language of the database. Many ways are thinkable, but I know of only one elegant method. It is described in [TEAM-1987]. In this paper Grosz et al describe a proof-of-concept system that does exactly that what we need. I am only going to name the parts of the 80-page article that are needed to make my point. The system itself is much more complex, of course.

The query is done, essentially, in three phases:

  1. Rewrite the logical relations to database relations
  2. Transform the database relations to a database query
  3. Execute the query

To me, the most important step is the first. It requires the system developer to create transformation rules that map the logical relations and their arguments to corresponding database relations and arguments. This step needs to be performed once for each new database for which a natural language interface is needed.

Step 2 transforms and accumulates the database relations into a database query (for example SQL, or SPARQL; the paper itself uses SODA). This transformation needs to be programmed out for each database query language.


Given our example predications, let's look at some sample database structure and the way the relations map. This is also a good excercise for myself, since I have had no experience with this at all ;)

Database 1

Author Book Year
5 18 1818
6 22 1866

 ID Name
 5 Mary Shelley
 6 Fyodor Mikhailovich Dostoyevsky

 ID Name
18 Frankenstein
22 Crime and Punishment

This is the mapping:

  1. write(e, a, b) => publications(author = a, book = b)
  2. write(e, a, b), name(a, c) => authors(id = a, name = c)
  3. write(e, a, b), name(b, d) => books(id = b, name = d)
  4. time(e, t), write(e, a, b) => publications(author = a, book = b, year = t)

Let's examine this mapping:

  • The first mapping is 1-to-1. A single relation is mapped to a single relation.
  • The second and third mappings show that this is not always the case. These are n-to-1 mappings.
  • And, as to prove that 1-to-n mappings are also needed, mapping 4 provides one.
  • While possible, it is probably wise not to use n-to-m mappings. They look complicated and are less flexible than the 1-to-n / n-to-1 mappings
  • Notice too, that while the logical form uses events, these have no explicit representation in the database. I thought this would be a major issue, but apparently it can be overcome.

Now, let's try a completely different database:

Database 2

Author Publication
5 101
6 104

 ID Book Year
101 Frankenstein 1818
104 Crime and Punishm 1866

 ID Name
 5 Mary Shelley
 6 Fyodor Mikhailovich Dostoyevsky

This is the mapping:

  1. write(e, a, b) => authorpublications(author = a, publication = e)
  2. write(e, a, b), name(a, c) => authors(id = a, name = c)
  3. write(e, a, b), name(b, d) => publication(id = e, book = d)
  4. time(e, t), write(e, a, b) => publication(id = e, year = t)


  • Note that the event variable e is used in this example. That is because a publication is treated as an event here.
  • Make sure that all relations and all arguments of the logical form are represented in the relational form. Otherwise some constraints will be missing and you will get too many results from your query.

Building the query

It is probably a good idea to give at least an example of what a query would look like that is generated from a set of database relations. So I will have a go.

Using the relations for the second database I came up with this SQL query. It is just to give you an idea of how such a thing may be done:

SELECT p2.year AS t
FROM authorpublications ap
INNER JOIN authors a
INNER JOIN publication p1
INNER JOIN publication p2
WHERE = AND = "Mary Shelley" = ap.publication AND = "Frankenstein" = ap.publication


When the logical query is executed, variables are used for the arguments. These variables determine the join constraints. For example, when the same variable is used for authorpublications.publication as it is for, the constraint authorpublications.publication = is added.


[TEAM-1987] TEAM: An Experiment in the Design of Transportable Natural-Language Interfaces - Barbara J. Grosz, Douglas E. Appelt, Paul Martin, Fernando Pereira


« Terug

Reacties op 'Mapping to a relational database'

Geplaatst op: 26-06-2013 15:41 Quote
I visited many sites but the audio feature for audio songs existing at this site is actually superb.| louboutin
toms shoes
Geplaatst op: 02-07-2013 06:32 Quote
I've been surfing online more than 3 hours today, yet I never found any interesting article like yours. It's pretty worth enough for me. In my view, if all site owners and bloggers made good content as you did, the internet will be much more useful than ever before.<a href="">louboutin pas cher</a>| toms shoes
louboutin pas cher
Geplaatst op: 02-07-2013 12:44 Quote
Hi there, just was alert to your blog thru Google, and found that it's really informative. I am going to watch out for brussels. I will be grateful if you continue this in future. A lot of other folks might be benefited from your writing. Cheers!<a href="">cheap oakley sunglasses</a>| louboutin pas cher
michael kors outlet
Geplaatst op: 10-07-2013 08:54 Quote
Hello, of course this article is really fastidious and I have learned lot of things from it about blogging. thanks.| michael kors outlet
Cheap Air Jordan Shoes
Geplaatst op: 24-09-2013 12:47 Quote
Th <a href="">Louboutin Sale</a> most that and was too conscious of the pricey to <a href="">Basketball Shoes For Men</a> the light the group at the lighted , <a href="">Lululemon Yoga Pants</a> that christ is covered relief for he had had enoug.
ugg boots outlet uk
Geplaatst op: 24-09-2013 20:26 Quote
999 Or it could imply bankrupting the crew future for any shot in the playoffs this 12 months.. Rapid Drive requires benefit of an SSD for more rapidly boot speed.
ugg boots outlet uk
texans jerseys cheap
Geplaatst op: 07-10-2013 19:54 Quote
5555 He was also wanting ahead to gorging himself greater than the holiday.. Jones originally was billed with felony coercion for his function within the Minxx melee.
texans jerseys cheap
wholesale nfl jerseys
Geplaatst op: 17-10-2013 15:24 Quote
333 Put the price of a $100 check out as much as $150 and visitors will flip away. While you are it genuine which the easy to understand gladness of the
wholesale nfl jerseys
personalized college football jerseys
Geplaatst op: 26-10-2013 14:29 Quote
999 See additional footage and skim additional for the Day to day Truffle.. Longer distance mobile phone calls are improving for you personally do not only hear your have a passion for ..
personalized college football jerseys
louis vuitton online shopping
Geplaatst op: 28-10-2013 17:36 Quote
3333 Marc has famously battled drug addiction with the earlier and it has traditional treatment sessions. That is why in spite of the shaky economic local weather, Zara's prepare for environment domination is not faltering.
louis vuitton online shopping
??? ???? ?? ???
Geplaatst op: 12-11-2013 00:47 Quote
Hand Bag Envy with the of several sites for designer handbag rental. Get a fabulous "it" handbag for an event, special occasion, actually everyday.carry it and then return this can. They are made of top quality fabric provides.
[url=]??? ???? ?? ???[/url]
cheap uggs
Geplaatst op: 22-11-2013 05:32 Quote
999 It is a cologne constructed for guys relating to the ages of 35 and fifty three, and will be worn all through the daytime. I would continue to invest as long as feasible chopping it up accompanied by a fellow geek, most of the though not advertising anything at all.
<a href="" >cheap uggs</a>
cheap uggs
cyber monday louboutin
Geplaatst op: 22-11-2013 05:48 Quote
999 It is just a cologne produced for guys relating to the ages of 35 and 53, and should be worn through the daytime. I might commence to invest so long as practical chopping it up which has a fellow geek, the as not providing anything at all.
<a href="" >cyber monday louboutin</a>
cyber monday louboutin
Nieuw bericht