• Keine Ergebnisse gefunden

hears

S P O

uni:s1 uni:hears uni:c1 uni:s2 uni:hears uni:c2

Table 39: View containing all triples with the predicateuni:hears. hears

S O

uni:s1 uni:c1 uni:s2 uni:c2

Table 40: Optimized view with only two columns.

table depicts the view that holds all triples, which have the property uni:hears as predicate. Therefore, the value of the P column is uni:hears in each row of the view. In the optimized view theP column is omitted and thus, the property view has only two attributes, namelyS andO. In table 40 the optimized property view for the property uni:hearsis depicted.

Since the optimized class views and the optimized property views have different sets of attributes the allTriplesView cannot be generated by simply creating the union of all views. For class views the P and O column have to be added and for property views the P column has to be added. Therefore, the allTriplesView is created as defined in the following definition.

Definition 67 (Creation of allTriplesView)

Let O be an ontology. Let c1, c2, ..., cn be the classes in O. Let p1, p2, ..., pn be the properties in O. Then the allTriplesView is created by the following SQL query.

C R E A T E VIEW a l l T r i p l e s V i e w AS

S E L E C T S , ’ type ’ AS P , ’ c1 ’ AS O FROM view ( c1 ) U N I O N

S E L E C T S , ’ type ’ AS P , ’ c2 ’ AS O FROM view ( c2 ) ...

S E L E C T S , ’ type ’ AS P , ’ cn ’ AS O FROM view ( cn ) U N I O N

S E L E C T S , ’ p1 ’ AS P , O FROM view ( p1 ) U N I O N

S E L E C T S , ’ p2 ’ AS P , O FROM view ( p2 ) ...

S E L E C T S , ’ pn ’ AS P , O FROM view ( pn )

Example 53

Consider the optimized uni:BachelorStudent view and the optimized uni:hears view depicted in table 38 and 40 respectively. The allTriplesView created from these two views would be generated by the SQL query:

C R E A T E VIEW a l l T r i p l e s V i e w AS S E L E C T S , ’ type ’ AS P ,

’ http :// www . uni . com / B a c h e l o r S t u d e n t ’ AS O FROM b a c h e l o r s t u d e n t

U N I O N

S E L E C T S , ’ http :// www . uni . com / hears ’ , O FROM h e a r s

Despite data being omitted in the optimized views, the translation of SPARQL queries to SQL queries as described in section 4.3 does not have to be changed. Since only the translations of triple patterns address views directly, the translation of other SPARQL constructs, such as join, optional and union are not affected by optimizing the views. When looking at the translation of triple patterns, several cases have to be considered:

1. The predicate is a variable.

When the predicate of a triple pattern is a variable, the triple pattern maps to theallTriplesView. Since theallTriplesViewhas the three columns S,P andOit can answer any triple pattern, regardless if the subject and object of a triple pattern are variables, IRIs or literals.

2. The predicate is type.

If the predicate is type 4 different combinations of variablesv, v1, v2 and IRIs iri, iri1, iri2 are possible:

(a)v1 typev2

If the subject and the object of a triple pattern are variable and the predicate istype, then the class view cannot be determined and thus, the triple pattern is mapped onto theallTriplesView, which can answer the triple pattern.

(b)v typeiri

If the subject of a triple pattern with the predicatetypeis a variable and the ob-ject is an IRI, then the triple pattern can be mapped ontoview(iri). Since only the subject of the triple pattern is a variable, the respective view has enough information to answer the translation of the triple pattern. Take for instance the triple pattern ?student type <http://www.uni.com/BachelorStudent>.

This triple patten with one variable is translated to the relational algebra ex-pression%S↝studentS(bachelorstudent)). Since only theScolumn is projected, theuni:BachelorStudentview depicted in table 38 can answer this triple pat-tern.

(c)iritype v

Similar to case 2a a class view cannot be determined, since the object of the

triple pattern is a variable. Subsequently, this triple pattern is mapped onto theallTriplesView, which can answer the translation of the triple pattern.

(d)iri1 typeiri2

If subject and object of a triple pattern with type as predicate are IRIs, the triple pattern is mapped ontoview(iri2). All rows with the value ofiri1 stored in theS column are selected and then the empty set in projected. Consider the triple pattern uni:s1 type <http://www.uni.com/BachelorStudent>. This triple pattern would be translated to (πS=uni∶s1(bachelorstudent)). Once again this relational algebra expression can be answered by the view shown in table 38.

3. The predicate is an IRI and not type.

If the predicate p of a triple pattern is an IRI different from type, then 4 different combinations of variablesv, v1, v2 and IRIsiri, iri1, iri2 are possible.

(a)v1p v2

If subject and object are variables, the triple pattern is mapped onto view(p) and theS andO columns of the view are projected. Consider the triple pattern

?student uni:hears course. The respective relational algebra expression to this triple pattern is %S↝student(%O↝courseS,O(hears))). This expression can be answered by the optimizeduni:hearsview shown in table 40.

(b)v p iri

If only the subject of the triple pattern is a variable, then the triple pattern is mapped onto view(p) and the rows with iri as the value of O are selected from the view. Then the values of the column S are projected. Consider the triple pattern?student uni:hears uni:c1. The triple pattern is translated to the relational algebra expression %S↝studentSO=uni∶c1(hears))). Since only the columns S and O are addressed, the relational algebra expression can be answered by the uni:hearsview.

(c)iri p v

This case is analogue to case 3b with the difference that in this case the object is a variable and the subject is an IRI. Therefore, it can also be answered by the optimized views.

(d)iri1 p iri2

Finally, the last case is a triple pattern with two IRIs. Once again this triple pattern is mapped onto view(p). All rows where the value stored in the S column corresponds toiri1and the value storedOcolumn corresponds toiri2are selected and then the empty set is projected. Consider the triple patternuni:s1 uni:hears uni:c1. This triple pattern is translated to the relational algebra expression πS=uni∶s1O=uni∶c1(hears))). This relational algebra expression can be answered by the optimized uni:hearsview shown in table 40.

In summary, the P and O columns in the original class views are never addressed and therefore, they can be omitted in the optimized views. Likewise, thePcolumn in the original property views is never selected and subsequently the P column can be

omitted in the optimized property views. Since the omitted columns are not selected in the original views, the triple pattern translation does not have to be altered for the optimized views.

5.2. Support of Exclusive Superclass Instances

To this point a view for a superclass was created by creating the union of all views of subclasses of the superclass. Take for instance the classesuni:BachelorStudentand uni:MasterStudent, which are subclasses of the classuni:Student. Theuni:Student view is created as the union of theuni:BachelorStudentand theuni:MasterStudent view. In the reimplemented system each instance ofuni:Studentis also an instance of uni:BachelorStudentor uni:MasterStudent. However, in an RDF graph instances of uni:studentcan exists that are neither instances of uni:BachelorStudentnor of uni:MasterStudent. Consider the IRI <http://www.uni.com/studentPhd1> that denotes a PhD student. Since a PhD student is neither a bachelor student, nor a master student, the PhD student <http://www.uni.com/studentPhd1> is only of the typeuni:Student.

Due to the fact that theuni:Student view is the union of its subclass views such exclusive superclass instances could not be represented by the original uni:Student view. In order to also support exclusive superclass instances, a materialized view ex-clusiveStudent is created that contains all instances that are of the typeuni:Student and not of the type uni:BachelorStudent or uni:MasterStudent. After that the uni:student view is defined as the union of the uni:BachelorStudent view, the uni:MasterStudentview and theexclusiveStudentview. The set of mapping rules that define such an exclusive view is defined as following:

Definition 68 (Mapping Rules for Exclusive Superclasses)

Let c be a superclass and let SC be the set of subclasses of c. Let M be a mapping.

The set of mapping rules to create the exclusive view for the superclass c is defined as:

Mc= {m∣m ∈M∶m =ϕ↝ (θ, type, c) and /

∃m∈M∶m=ϕ↝ (θ, type, sc) where sc∈SC}

Note that the system currently only checks for the syntactic equivalence ofϕ and not for the semantic equivalence.

Example 54

Letuni:BachelorStudentbe a subclass ofuni:Student. For simplicity consider that uni:Studentdoes not have the subclassuni:MasterStudent. Furthermore, consider the following mapping rules:

m1=ST U DEN T ↝ (http∶ //www.uni.com/student/{ID}, type,

http∶ //www.uni.com/BachelorStudent) m2=ST U DEN T ↝ (http∶ //www.uni.com/student/{ID},

type,

http∶ //www.uni.com/Student) m3=P HDST U DEN T ↝ (http∶ //www.uni.com/student/{ID},

type,

http∶ //www.uni.com/Student)

The mapping rulem1 is not included inMStudentsince the object of triples created by this rule is uni:BachelorStudentand not uni:Student. However, the instances of the class uni:BachelorStudent that are defined by this mapping rule are later included in the uni:Student view because uni:BachelorStudent is a subclass of uni:Student. Mapping rulesm1 andm2 have the same relational algebra expression, namely STUDENT, the same mapping template http://www.uni.com/student/{ID}

for subjects andtypeas predicate IRI. Thereby, the evaluation of the mapping rules returns the same triples, with the difference that all objects of triples created by m1

areuni:BachelorStudentand all objects of triples created bym2 areuni:Student. Since, the instances created by evaluatingm1are later unioned into theuni:Student view, mapping rulem2 can be ignored inMStudent. Finally,MStudent= {m3} because the instances created bym3 are not included in any subclass view of uni:Student.

The materialized view for exclusive instances of the uni:student class is created by the following SQL query:

C R E A T E M A T E R I A L I Z E D VIEW e x c l u s i v e S t u d e n t AS S E L E C T

C O N C A T ( ’ http :// www . uni . com / s t u d e n t / ’ , ID ) AS S , FROM P H D S T U D E N T

Finally, theuni:student view would be created by the following SQL query.

C R E A T E VIEW s t u d e n t AS

S E L E C T * FROM e x c l u s i v e S t u d e n t U N I O N

S E L E C T * FROM b a c h e l o r S t u d e n t