a model transformation language based on logic programming
TRANSCRIPT
A Model Transformation Languagebased on Logic Programming
Jesus M. Almendros-Jimenez and Luis Iribarne
Universidad de Almerıa.{jalmen,liribarne}@ual.es
39th International Conference on Current Trends in Theoryand Practice of Computer Science January 26–31, 2013
Spindleruv Mlyn, Czech Republic
Table of contents
1 Motivation
2 Model Transformation
3 PTL: Prolog-based Transformation Language
4 Conclusions and Future Work
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
Motivation
Model Driven Software Engineering: MDA, UML, DSLsModel Transformation (M2M,M2T), Code Generation
Models, Meta-models and Meta-meta-modelsModel Transformation Languages: ATL, QVT, ...Prolog based languages: VIATRA, Tefkat, MoMaTProlog as transformation engine for ATL
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
Motivation
Model Driven Software Engineering: MDA, UML, DSLsModel Transformation (M2M,M2T), Code GenerationModels, Meta-models and Meta-meta-models
Model Transformation Languages: ATL, QVT, ...Prolog based languages: VIATRA, Tefkat, MoMaTProlog as transformation engine for ATL
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
Motivation
Model Driven Software Engineering: MDA, UML, DSLsModel Transformation (M2M,M2T), Code GenerationModels, Meta-models and Meta-meta-modelsModel Transformation Languages: ATL, QVT, ...
Prolog based languages: VIATRA, Tefkat, MoMaTProlog as transformation engine for ATL
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
Motivation
Model Driven Software Engineering: MDA, UML, DSLsModel Transformation (M2M,M2T), Code GenerationModels, Meta-models and Meta-meta-modelsModel Transformation Languages: ATL, QVT, ...Prolog based languages: VIATRA, Tefkat, MoMaT
Prolog as transformation engine for ATL
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
Motivation
Model Driven Software Engineering: MDA, UML, DSLsModel Transformation (M2M,M2T), Code GenerationModels, Meta-models and Meta-meta-modelsModel Transformation Languages: ATL, QVT, ...Prolog based languages: VIATRA, Tefkat, MoMaTProlog as transformation engine for ATL
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
Motivation
Model Driven Software Engineering: MDA, UML, DSLsModel Transformation (M2M,M2T), Code GenerationModels, Meta-models and Meta-meta-modelsModel Transformation Languages: ATL, QVT, ...Prolog based languages: VIATRA, Tefkat, MoMaTProlog as transformation engine for ATL
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
Source Model
model-A
id_course : int title : String credits : float
Course id_student : int name : String age : int
Student
DB_CoursesDB_Students
id_course : int id_student : int0..*
0..* register
is_registered
0..*
1
the_students0..*
1
the_courses
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
Target Model
Model-B
<<row>>Course
type : float
<<column>>credits
type : int
<<column>>id_course
type : int
<<column>>id_student
type : String
<<column>>name
type : int
<<column>>age
<<table>>register
<<row>>registerCourse
type : int
<<column>>registerCourseid_course
type : int
<<column>>registerCourseid_student
<<row>>Student
<<table>>the_courses
<<table>>the_students
type : String
<<column>>title
1
1col
1
0..*line
1
1col
1
1key
1
1 foreign
1
0..*line
1
0..*line
1
1 key
1
1 foreign
1
1col 1
1
col
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
Source Meta-Model
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
Target Meta-Model
metamodel B
-name : String
-type : String
col
-name : String
-type : String
foreign
-name : String
-type : String
key
-name : String
row
-name : String
table
is_col
has_col
is_foreign
has_foreign
is_key
has_key
table
has
*
1
1
1
*
1
*
1
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
PTL features
ATL style syntaxDeclarative Semantics
Encoding to Prolog rulesProlog library for handling meta-modelsMOF meta-metamodelXMI supportProlog helpersDebugging capabilitiesTracing capabilities
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
PTL features
ATL style syntaxDeclarative SemanticsEncoding to Prolog rules
Prolog library for handling meta-modelsMOF meta-metamodelXMI supportProlog helpersDebugging capabilitiesTracing capabilities
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
PTL features
ATL style syntaxDeclarative SemanticsEncoding to Prolog rulesProlog library for handling meta-models
MOF meta-metamodelXMI supportProlog helpersDebugging capabilitiesTracing capabilities
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
PTL features
ATL style syntaxDeclarative SemanticsEncoding to Prolog rulesProlog library for handling meta-modelsMOF meta-metamodel
XMI supportProlog helpersDebugging capabilitiesTracing capabilities
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
PTL features
ATL style syntaxDeclarative SemanticsEncoding to Prolog rulesProlog library for handling meta-modelsMOF meta-metamodelXMI support
Prolog helpersDebugging capabilitiesTracing capabilities
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
PTL features
ATL style syntaxDeclarative SemanticsEncoding to Prolog rulesProlog library for handling meta-modelsMOF meta-metamodelXMI supportProlog helpers
Debugging capabilitiesTracing capabilities
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
PTL features
ATL style syntaxDeclarative SemanticsEncoding to Prolog rulesProlog library for handling meta-modelsMOF meta-metamodelXMI supportProlog helpersDebugging capabilities
Tracing capabilities
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
PTL features
ATL style syntaxDeclarative SemanticsEncoding to Prolog rulesProlog library for handling meta-modelsMOF meta-metamodelXMI supportProlog helpersDebugging capabilitiesTracing capabilities
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
PTL features
ATL style syntaxDeclarative SemanticsEncoding to Prolog rulesProlog library for handling meta-modelsMOF meta-metamodelXMI supportProlog helpersDebugging capabilitiesTracing capabilities
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
Meta-model definitions in PTL
metamodel(er,[
class(data, [name,container]),class(store, [name]),class(attribute, [name,type,key]),class(relation, [name]),class(roles, [name,navigable,min,max]),class(qualifier, [name,type]),role(contains,store,data,"1","1"),role(contained_in,data,store,"1","1"),role(attr_of,data,attribute,"0","*"),role(is,attribute,data,"1","1"),role(has_role,roles,relation,"1","1"),role(is_role,relation,roles,"1","*"),role(has,qualifier,roles,"1","1"),role(is,roles,qualifier,"0","*"),role(is_data,roles,data,"1","1"),role(role_of,data,roles,"1","1")
]).
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
PTL rule syntax
rule := rule rule name from pointers [where condition ] to objectspointers := pointer | ‘(’ pointer,...,pointer ‘)’condition := bcondition | condition and conditionbcondition := access == access | access =\= accesspointer := pointer name : metamodel name ! class nameobjects := object,...,objectobject := pointer ‘(’ binding,...,binding ‘)’access := value | pointer name | pointer name@attribute name |
pointer name@role name@attribute name |helper name ‘(’ access,...,access ‘)’ |resolveTemp‘(’ ‘(’ access,...,access ‘)’, pointer name‘)’ |sequence‘(’‘[’access,...,access‘]’‘)’
binding := attribute name <− access | role name <− access
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
PTL rule example
rule table2_er2rl fromp:er!role where (p@navigable==true and p@max=="*") to
(t:rl!table(name <- p@name,has <- r ),
r:rl!row(name <- concat(p@name,p@is_data@name),table <-t,is_foreign <- sequence([resolveTemp((p@is,p),f1),
inverse_qualifier(p)]))).
rule foreign2_er2rl from(p:er!qualifier,q:er!role) where
(p@has == q and q@navigable==false) to(f2:rl!foreign(
name <-concat(concat(q@name,q@is_data@name),p@name),type <- p@type,has_foreign <- inverse_row(p))
).
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
PTL helpers
inverse_row(A, E) :-associationEnds(er, has, A, B),associationEnds(er, has_role, B, C),associationEnds(er, is_role, C, D),role_navigable(er, D, true),resolveTemp(D, r, E).
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
PTL Declarative Semantics (I)
Definition (Model)
A modelM is a quintupleM = (CM,AM,RM,HM,OM)(a) OM is a set of object names.(b) CM is an interpretation CM1 , . . . , CMn , of the class nameswhich are disjoint subsets of OM.(c) AM interprets attributes as a set of (partial) functionsatt<M,i>
j from OM to elements of D(d) RM interprets roles as a set of (partial) functionsrM1 , . . . , rMm from OM to a subset of OM.(e) HM interprets helpers as (partial) functionshMw : CMw1
. . . CMwt→ CMw(t+1)
wi ∈ {1, . . . , n}.
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
PTL Declarative Semantics (II)
(1) [| rule rn from ps where bc to obs |]M =∪{v∈CM,(pn,CM)=<<ps>>M,[|bc|]M
(pn,v)is true}[|obs|]M
(pn,v)
(2) << pn :mm!C >>M= (pn, CM) whenever CM ∈ C(3) << (ps1, ..., psn) >>M= << ps >>M
(4) [|expr1 and expr2 |]M(pn,v)
if [|expr1|]M(pn,v)
and [|expr2 |]M(pn,v)
then true else false
(5) [|expr1==expr2 |]M(pn,v)
if [|expr1|]M(pn,v)
= [|expr2 |]M(pn,v)
then true else false
(6) [|expr1= \ =expr2 |]M(pn,v)
if [|expr1|]M(p,v)
= [|expr2 |]M(pn,v)
then false else true
(7) [|qn:mm!C(bd1, ..., bdn)|]M(pn,v)
=M′ ∪1≤i≤n [|bdi |]<M,o>
(pn,v)
whereM′ = ({CM′}, {}, {}, {}, {o}), CM′= {o} and
o = gen id(v , qn), whenever CM ∈ C(8) [|o1, ..., on|]M
(pn,v)= ∪i=1,...,n[|oi |]M(pn,v)
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
PTL Declarative Semantics (III)
(9) [|v |]M(pn,v)
= v
(10) [|pni |]M(pn,v)= vi
(11) [|pni@att |]M(pn,v)
= attM(vi )
(12) [|pni@r@att |]M(pn,v)
= attM(rM(vi ))
(13) [|h(expr1, ..., exprn)|]M(pn,v)
= hM([|expr1|]M(pn,v)
, . . . , [|exprn|]M(pn,v)
)
(14) [|resolveTemp((expr1, ..., exprn), qn)|]M(pn,v)
= o
where ([|expr1|]M(pn,v)
, . . . , [|exprn|]M(pn,v)
)→Pqn o
(15) [|sequence([expr ])|]M(pn,v)
= [|expr |]M(pn,v)
(16) [|att<−expr |]<M,o>
(pn,v)=M′,
whereM′ = ({}, {attM′}, {}, {}, {}), attM
′(o) = [|expr |]M
(pn,v)
(17) [|r<−expr |]<M,o>
(pn,v)=M′,
whereM′ = ({}, {}, {rM′}, {}, {}), rM′(o) = [|expr |]M
(pn,v)
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
PTL Declarative Semantics (IV)
Theorem (Soundness and Completeness)Given a PTL program P, a modelM that interprets themeta-models of P, andM′ = ∪1≤i≤n[|ri |]M, whereRP ≡ r1, . . . , rn, then:o ∈ OM′ iff o is a logic consequence of the programenc(RP) ∪HP ∪ enc(M) ∪MMP .
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
Prolog library for meta-models
role_id(er, A) :-role(er, A, [name(_), navigable(_), min(_), max(_)]).
data_container(er, A, B) :-data(er, A, [name(_), container(B)]).
attribute_type(er, A, B) :-attribute(er, A, [name(_), type(B), key(_)]).
qualifier_has(er, A, B) :-associationEnds(er, has, A, B).
relation_is_role(er, A, B) :-associationEnds(er, is_role, A, B).
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
Encoding to Prolog
object(rl, foreign, L, (A, B), [name(K), type(C)], f2) :-foreign2_er2rl((A, B)),qualifier_type(er, A, C),qualifier_name(er, A, I),role_is_data(er, B, E),data_name(er, E, G),role_name(er, B, F),concat(F, G, H),concat(H, I, K),generate_ids((A, B), f2, L).
foreign2_er2rl((A, B)) :-qualifier_id(er, A),role_id(er, B),qualifier_has(er, A, B),role_navigable(er, B, false).
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
PTL interpreter
ptl(Program):-[Program],generate_metamodels,generate_rules,load_models,clean_transformation.
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
PTL interpreter
load_model(A) :-object(A, B, C, D, E, F),assert(objectM(A, B, C, D, E, F)),fail.
load_model(A) :-associationObjects(A, B, C, D),assert(associationObjectsM(A, B, C, D)),fail.
load_model(_).
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
Running a transformation
?- transform([’mm2er.ptl’,’er2rl.ptl’,’rl2mm.ptl’]).
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
Running a transformation
transform(Files):-clean_ptl,transform_files(Files).
transform_files([]):-!.transform_files([F|RF]):-ptl(F),
transform_files(RF).
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
Debugger
?- debugging([’mm2er.ptl’,’er2rl.ptl’,’rl2mm.ptl’]).Debugger: Rule Condition of: table2_er2rl cannot be satisfied.Found error in: role_name
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
Debugger
?- debugging([’mm2er.ptl’,’er2rl.ptl’,’rl2mm.ptl’]).Debugger: Objects of: table2_er2rl cannot be created.Found error in: resolveTemp
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
Tracer
?- tracing([’mm2er.ptl’,’er2rl.ptl’,’rl2mm.ptl’],’275284307q275325284r2f2c’).
Tracing the element: 275284307q275325284r2f2c
Rule: foreign1_rl2mmElement: foreignMetamodel: rl
Rule: foreign2_er2rlElement: qualifierMetamodel: er....Element: propertyMetamodel: mmxmi:id is wfP6O_iGCkzsbgVr
Element: propertyMetamodel: mmxmi:id is CrZGO_iGCkzsbhYY
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming
MotivationModel Transformation
PTL: Prolog-based Transformation LanguageConclusions and Future Work
Conclusions and Future Work
PTL: Prolog based Transformation LanguageDetails can be found at http://indalog.ual.es/mddDeclarative Semantics, Debugging, Tracing.Future: Model validation, rule validation, etcFuture: More about debugging and tracingFuture: Eclipse plugin for transformation
Jesus M. Almendros-Jimenez and Luis Iribarne A Model Transformation Language based on Logic Programming