• No results found

Syntax parsing into instances of syntax metamodel.

The RDB2OWL grammar (see Appendix A.7) parser implementation in javacc [75] processes all RDB2OWL annotations attached to the target OWL ontology and creates instances of RDB2OWL full syntax metamodel shown in Figure 55. For example, class map expressions attached to OWL classes transformed to instances of ClassMap with links to corresponding instances of OWLClass and TableExpression and References classes. Javacc code sample fragment (action code in italic):

PARSER_BEGIN(Rdb2Owl)

import lv.lu.mii.repository.KPRepositoryPlus;

public class Rdb2Owl {

private KPRepositoryPlus rep=null;

TOKEN : {< CDecoration : "?" | "?Out" | "?In" | "!NoMap" | "!SubClean" >} … long classMap() : { String name; Token t; long classMapId; long uriPatternId; long tableExprId; } { {classMapId=mappingProcessor.createClassMap(owlClassName);} ( LOOKAHEAD(2) name=defName() "=" {mappingProcessor.createReference(classMapId, name ); } )? tableExprId=tableExpr() {rep.associateObjects( "tableExpression", classMapId, tableExprId) ; } ( uriPatternId=uriPattern() {rep.associateObjects(

"URIPattern", classMapId, uriPatternId); }

)? (

t=<CDecoration>

{ rep.setObjectAttribute(

classMapId, "instruction", t.image); }

)*

{return classMapId; } }

120 long tableExpr(): { long id=rep.createObject("TableExpression"); … { { … }

linkObjectPropertyMapsToClassMaps.lua (Appendix [A.8.3])

Links src and trg are created (used for class map reference marks <s> and <t>) from ObjectPropertyMap to ClassMap in following way. For each OWLObjectProperty instance p, find the corresponding domain and range classes, and then the sole class map attached to each. These are the targets of src and trg links from p. Similarly, script linkDataPropertyMapsToClassMaps.lua (Appendix [A.8.4]) creates src links.

splitNamedRef2SubClasses.lua (Appendix [A.8.5])

NamedRef instance is split into instances of one of its subclass DefVarRef or ClassRef by analyzing if refName attribute value is found as name of defined variable or class name: as equal to OWLClass.localName or Reference.varName. For example, annotated mini-University ontology (Figure 34) has class map:

T=Teacher {uri=(‘Person_Id’,IDCode)}

and an object property map:

[[Teacher]][teacher_id]->[[T]]

In this case, the syntax parser at first would transform both the [[Teacher]] and [[T]] into instance of the NamedRef class. Then the first goes to ClassRef and the second to DefVarRef instance because there is class named Teacher and defined variable named T.

linkColPrefix2NavigItem.lua (Appendix A.8.6)

Links ref are created from ColPrefix to corresponding NavigItem instance. This linking is required to associate column prefixes used in value expressions (e.g., filter expressions in table expressions) with corresponding navigation or reference item. For example, for table expression

Teacher t, Course c; t.teacher_id=c.course.id

t from t.teacher_id is parsed into ColPrefix instance and Teacher t is parser into TableRefExpr (a subclass of NavigItem) with alias=’Teacher’. These two instances of ColPrefix and TableRefExpr are linked.

changeEmptyItemsToClassMapRefs.lua (Appendix A.8.7)

Changes empty ClassMapRef instances (mark=”empty”) to non empty ClassMapRef instances (mark=”<s>” or mark=”<t>”). If the first NavigItem in the list (as RefItem{ordered}NavigItem} mark it “<s>” and the last empty NavigItem change to ClassMapRef with mark=”<t>”. For example, the transformation means table expression

=>Registration->

change to

121 linkClassMapRef2ClassMap.lua (Appendix A.8.8)

The ref links are created from ClassMapRef to ClassMap determined as follows. The ClassMapRef with mark=”<s>” or “<t>” as NavigItem is part of RefItem and that of TableExpression which is assigned to some property map instance pm (of ObjectPropertyMap or DataPropertyMap). ClassMap instances linked to pm by src or trg links are the ones used for ref link.

linkXSDRef2XSDDatatype.lua (Appendix A.8.9)

Creates ref links from XSDRef to XSDDatatype based on typeName attribute value. splitColNameRef2Subclasses.lua (Appendix A.8.10)

Splits each ColNameRef class instance into instance of one of its subclasses: DefColName or TableColName. Decision which subclass is taken is resolved by finding if colName property value is found as ColDef.colName property value attached to instance of TableExpression from the context of the value expression (is exprContext link target). If ColDef is founf then ColNameRef is split into instance of DefColName otherwise of TableColName. As an example, let us take two equivalent data property map expressions:

- (TEACHER t).( t.level_code || ‘ ‘ || t.name)

- (TEACHER t; fullName=t.level_code || ‘ ‘ || t.name).fullName

In the firsts example level_code (in bold) is parsed first into ColNameRef and then split into TableColName. In the second expression, the last (bold) fullName is finally split into DefColName.

fillExpliciteNavigationColumns.lua (Appendix A.8.11)

Fills explicit column expressions into navigation links they are omitted. For example, object property map expression for teaches property

TEACHER=>COURSE

is transformed into

TEACHER[teacher_id]=>[teacher_id]COURSE

The transformation considers the source database schema structure information (primary/foreign key columns) that is stored in metamodel (RDB MM (extended) part of Figure 56). Link arrow =>means Primary-to-Foreign key link and

-> denotes foreign-to-primary key link. The transformation creates instances of ValueList for rightC and leftC link ends.

linkObjectPropertyMapsToClassMapsByNamedRefs.lua (Appendix A.8.12)

The src and trg links are created from ObjectPropertyMap to ClassMap instances when they are not created by default algorithm: (unique class map of domain/range class of the property). The src class map of object property map is determined as follows:

1) let x be the first NavigItem instance of the first RefItem instance; 2) if x is of type NamedRef then src class map is referencedClassMap(x) The trg class map of object property map is determined as follows:

1) let x be the last NavigItem instance of the last RefItem instance, 2) if x is of type NamedRef then trg class map is referencedClassMap(x); The referencedClassMap(x) is determined as follows:

122

then return the only class map that is ascribed to class c; 2) if x of of type DefVarRef then return class map linked to x:

x -->(def) --> ClassMap.

For example, this script creates src and trg links for two object property maps for the property PersonID (mini university example):

2 class maps of PersonID class:

classMap1: S=Student {uri=('PersonID', IDCode)}

classMap2: T=Teacher {uri=('PersonID', IDCode)}

2 property maps of the personID object property: propMap1: [[Student]][student_id]->[[S]]

propMap2: [[Teacher]][teacher_id]->[[T]]

In this example src and trg links created are:

propMap1 -->(src) The only class map of Student class propMap1 -->(trg) classMap1

propMap2 -->(src) The only class map of Teacher class propMap1 -->(trg) classMap2

Similarly, DataPropertyMaps are linked to ClassMaps by named refs (see linkDataPropertyMapsToClassMapsByNamedRefs.lua in Appendix A.8.13)

create_refLinks2TableAndColumn.lua (Appendix A.8.15)

The ref links are created from TableRef to Table classes. The target Table instance is determined from database alias and table name stored as tName and dbAlias attribute values. For example, in table expression

PERSON p, A.ADDRESS adr; p.addr_code=adr.code

the reference item person p is parsed by grammar into TableRefExpr and linked TableRef instance with tName=”PERSON” and dbAlias=null. The Table instance with such a name is found for default database (DBRef.isDefault=true). The reference item A.ADDRESS adr is parsed into TableRef instance with tName=”ADDRESS” and dbAlias=”A”. The Table instance is found for the specified different database. insertDefaultURIPatterns.lua (Appendix A.8.16)

If Uri pattern is not explicitly specified as part of class map then it is inserted following with the default pattern: the name of the main table (for the first navigation item for the first reference item) concatenated with values of all primary key columns. For example, the simple table expression for MandatoryCourse class

COURSE; required=1

is supplemented with default URI pattern

COURSE; required=1 {uri=(’COURSE’, course_id)}

This transformation creates URIPattern and list of URIItem with ValueExpression for each part (of type Constant with cValue=”COURSE”and TableColName for course_id column).

Related documents