Warning:
This wiki has been archived and is now read-only.
Default Mapping to RDFS/OWL
The default mapping also consist of transforming the relational database schema into a RDF(S) or OWL ontology.
Representing relational schemas
The following predicate symbols are used to represent the schema and the instances of a relational database. These predicates can be automatically computed, and they are necessary for the database-instances-and-schema mapping, as this language takes into consideration both the instances and the schema of a relational database.
RDB-schema predicates
Rel(r) = r is a relation Attr(x, r, t) = x is an attribute in relation r of type t PK(x, r) = attribute x is the primary key of relation r FK(x, r, y, s) = attribute x is a foreign key in relation r that references attribute y in relation s
Continuing our running example, the following RDB-schema predicates are used to represent the schema of the database:
Rel(student) Rel(course) Rel(enrolled) Rel(department) Attr(s_id, student, int) Attr(name, student, string) Attr(c_id, course int) Attr(title, course, string) Attr(d_id, course, int) Attr(s_id, enrolled, int) Attr(c_id, enrolled, int) Attr(d_id, department, int) Attr(title, department, string) PK(s_id, student) PK(c_id, course) PK(d_id, department) FK(d_id, course, d_id, department) FK(s_id, enrolled, s_id, student) FK(c_id, enrolled, c_id, course)
Formal definition of the language
A database-instances-and-schema mapping is a Datalog program over { Rel, Att, PK, FK } with built-in predicates { generateURI }.
In what follows, we show how to translate relational schema into RDFS/OWL ontology through database-schema-only mapping.
Representing ontologies (RDFS/OWL)
In the database-instances-only mapping language, the user can define any number of additional predicates by writing Datalog programs over the RDB-schema. In this section, we show some predicates that can be generated in this way. The predicates and the rules defining them are useful when mapping relational schema into RDFS/OWL, and they could be generated automatically as they are generic.
Auxiliary rules: Are useful when defining the ontology predicates
ExistsFK(x, r) ← FK(x, r, _, _) NonFK(x, r) ← Att(x, r, _), not ExistsFK(x, r)
Notice that ExistsFK(x, r) holds if attribute x is a foreign key in relation r, while NonFK(x, r) holds if x is an attribute of relation r that is not a foreign key in r.
Rule 1: Identify Binary Relations
BinRel(r, s, t) ← Rel(r), FK(p, r, _, s), FK(q, r, _, t), p ≠ q, not ExistThreeFK(r), not ExistsNonFKAtt(r) ExistThreeFK(r) ← FK(p1, r, _, _), FK(p2, r, _, _), FK(p3, r, _, _), p1 ≠ p2, p1 ≠ p3, p2 ≠ p3 ExistsNonFKAtt(r) ← NonFK(x, r)
Notice that ExistThreeFK(r) holds if relation r has at least three distinct foreign keys, and ExistsNonFKAtt(r) holds if relation r has at least one attribute that is not a foreign key of r.
Rule 2: Identify Ontology Classes (relations that are not binary relations)
Class(r) ← Rel(r), not IsBinRel(r) IsBinRel(r) ← BinRel(r, _, _)
Notice that Class(r) holds if relation r represents a class, and IsBinRel(r) holds if relation r is a binary relation.
Rule 3: Identify Object Properties through binary relations
ObjP(r, s, t) ← BinRel(r, s, t), not IsBinRel(s), not IsBinRel(t)
Notice that ObjP(r, s, t) holds if relation r represents an object property with domain s and range t
Rule 4: Identify Object Properties through a foreign key relationship
ObjP(x, s, t) ← FK(x, s, y, t), not IsBinRel(s), not IsBinRel(t)
Rule 5: Identify Datatype Properties
DTP(x, r, t) ← NonFK(x, r), Att(x, r, t)
Notice that DTP(x, r, t) holds if attribute x represents a data type property with domain r and range t.
The following is the result of applying the previous rules to our running example:
Auxiliary rules:
ExistsFK(d_id, course) ExistsFK(s_id, enrolled) ExistsFK(c_id, enrolled) NonFK(s_id, student) NonFK(name, student) NonFK(c_id, course) NonFK(title, course) NonFK(d_id, department) NonFK(title, department)
Rule 1:
BinRel(enrolled, student, course) ExistsNonFKAtt(student) ExistsNonFKAtt(course) ExistsNonFKAtt(department)
Rule 2:
Class(student) Class(course) Class(department) IsBinRel(enrolled).
Rule 3:
ObjP(enrolled, student, course)
Rule 4:
ObjP(d_id, course, department)
Rule 5:
DTP(name, student, string) DTP(title, course, string) DTP(title, department, string)