A Model Transformation Language based on Logic Programming
Transcription
A Model Transformation Language based on Logic Programming
A Model Transformation Language based on Logic Programming Jesús M. Almendros-Jiménez and Luis Iribarne Universidad de Almerı́a. {jalmen,liribarne}@ual.es 39th International Conference on Current Trends in Theory and 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 Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work Motivation Model Driven Software Engineering: MDA, UML, DSLs Model Transformation (M2M,M2T), Code Generation Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work Motivation Model Driven Software Engineering: MDA, UML, DSLs Model Transformation (M2M,M2T), Code Generation Models, Meta-models and Meta-meta-models Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work Motivation Model Driven Software Engineering: MDA, UML, DSLs Model Transformation (M2M,M2T), Code Generation Models, Meta-models and Meta-meta-models Model Transformation Languages: ATL, QVT, ... Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work Motivation Model Driven Software Engineering: MDA, UML, DSLs Model Transformation (M2M,M2T), Code Generation Models, Meta-models and Meta-meta-models Model Transformation Languages: ATL, QVT, ... Prolog based languages: VIATRA, Tefkat, MoMaT Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work Motivation Model Driven Software Engineering: MDA, UML, DSLs Model Transformation (M2M,M2T), Code Generation Models, Meta-models and Meta-meta-models Model Transformation Languages: ATL, QVT, ... Prolog based languages: VIATRA, Tefkat, MoMaT Prolog as transformation engine for ATL Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work Motivation Model Driven Software Engineering: MDA, UML, DSLs Model Transformation (M2M,M2T), Code Generation Models, Meta-models and Meta-meta-models Model Transformation Languages: ATL, QVT, ... Prolog based languages: VIATRA, Tefkat, MoMaT Prolog as transformation engine for ATL Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work Source Model model-A DB_Students DB_Courses 1 1 0..* the_students the_courses Student id_student : int name : String age : int 0..* Course id_student : int is_registered 0..* Jesús M. Almendros-Jiménez and Luis Iribarne id_course : int id_course : int title : String register credits : float 0..* A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work Target Model Model-B <<table>> the_students <<table>> register 1 line 1 1 0..* <<row>> Student line 1 1 1 col 1 <<column>> age type : int col 1 <<table>> the_courses key 1 1 <<column>> name <<column>> id_student type : String type : int 1 line 0..* <<row>> registerCourse foreign <<column>> registerCourseid_student type : int Jesús M. Almendros-Jiménez and Luis Iribarne 1 1 1 1 1 foreign <<column>> registerCourseid_course type : int 0..* <<row>> Course 1 key col 1 col 1 <<column>> id_course <<column>> title <<column>> credits type : int type : String type : float A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work Source Meta-Model Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work Target Meta-Model metamodel B table -name : String table 1 1 has_key 1 is_key * key -name : String -type : String has row -name : String has_foreign is_foreign 1 * foreign -name : String -type : String Jesús M. Almendros-Jiménez and Luis Iribarne has_col 1 is_col * col -name : String -type : String A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work PTL features ATL style syntax Declarative Semantics Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work PTL features ATL style syntax Declarative Semantics Encoding to Prolog rules Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work PTL features ATL style syntax Declarative Semantics Encoding to Prolog rules Prolog library for handling meta-models Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work PTL features ATL style syntax Declarative Semantics Encoding to Prolog rules Prolog library for handling meta-models MOF meta-metamodel Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work PTL features ATL style syntax Declarative Semantics Encoding to Prolog rules Prolog library for handling meta-models MOF meta-metamodel XMI support Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work PTL features ATL style syntax Declarative Semantics Encoding to Prolog rules Prolog library for handling meta-models MOF meta-metamodel XMI support Prolog helpers Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work PTL features ATL style syntax Declarative Semantics Encoding to Prolog rules Prolog library for handling meta-models MOF meta-metamodel XMI support Prolog helpers Debugging capabilities Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work PTL features ATL style syntax Declarative Semantics Encoding to Prolog rules Prolog library for handling meta-models MOF meta-metamodel XMI support Prolog helpers Debugging capabilities Tracing capabilities Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work PTL features ATL style syntax Declarative Semantics Encoding to Prolog rules Prolog library for handling meta-models MOF meta-metamodel XMI support Prolog helpers Debugging capabilities Tracing capabilities Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions 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") ] ). Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work PTL rule syntax rule pointers condition bcondition pointer objects object access binding := rule rule name from pointers [where condition ] to objects := pointer | ‘(’ pointer,...,pointer ‘)’ := bcondition | condition and condition := access == access | access =\= access := pointer name : metamodel name ! class name := object,...,object := pointer ‘(’ binding,...,binding ‘)’ := 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‘]’‘)’ := attribute name <− access | role name <− access Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work PTL rule example rule table2_er2rl from p: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)) ). Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions 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). Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work PTL Declarative Semantics (I) Definition (Model) A model M is a quintuple M = (C M , AM , RM , HM , OM ) (a) OM is a set of object names. (b) C M is an interpretation C1M , . . . , CnM , of the class names which are disjoint subsets of OM . (c) AM interprets attributes as a set of (partial) functions attj<M,i> from OM to elements of D (d) RM interprets roles as a set of (partial) functions r1M , . . . , rmM from OM to a subset of OM . (e) HM interprets helpers as (partial) functions M : CM . . . CM → CM hw w1 wt w(t+1) wi ∈ {1, . . . , n}. Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work PTL Declarative Semantics (II) (1) [| rule rn from ps where bc to obs |]M = ∪{v ∈C M ,(pn,C M )=<<ps>>M ,[|bc|]M is (pn,v ) true} [|obs|]M (pn,v ) (2) << pn :mm!C >>M = (pn, C M ) whenever C M ∈ C (3) << (ps1 , ..., psn ) >>M = << ps >>M (4) [|expr1 and expr2 |]M if [|expr1 |]M and [|expr2 |]M (pn,v ) (5) [|expr1 ==expr2 |]M (pn,v ) (6) [|expr1 = \ =expr2 |]M (pn,v ) if [|expr1 |]M (pn,v ) (pn,v ) if [|expr1 |]M (7) [|qn:mm!C(bd1 , ..., bdn )|]M 0 (pn,v ) = = [|expr2 |]M (p,v ) M0 ∪ (pn,v ) (pn,v ) = [|expr2 |]M (pn,v ) 1≤i≤n 0 then true else false then true else false then false else true [|bdi |]<M,o> (pn,v ) where M0 = ({C M }, {}, {}, {}, {o}), C M = {o} and o = gen id(v , qn), whenever C M ∈ C (8) [|o1 , ..., on |]M = ∪i=1,...,n [|oi |]M (pn,v ) (pn,v ) Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work PTL Declarative Semantics (III) (9) [|v |]M (pn,v ) (10) [|pni |]M =v (pn,v ) = vi (11) [|pni @att|]M (12) = att M (vi ) (pn,v ) [|pni @r @att|]M (pn,v ) = att M (r M (vi )) (13) [|h(expr1 , ..., exprn )|]M (pn,v ) = hM ([|expr1 |]M , . . . , [|exprn |]M (pn,v ) (14) [|resolveTemp((expr1 , ..., exprn ), qn)|]M = (pn,v ) where ([|expr1 |]M , . . . , [|exprn |]M ) →P qn o (pn,v ) (pn,v ) (pn,v ) ) o (15) [|sequence([expr ])|]M = [|expr |]M (pn,v ) (pn,v ) <M,o> (16) [|att<−expr |] = M0 , (pn,v ) 0 0 where M0 = ({}, {att M }, {}, {}, {}), att M (o) (17) [|r <−expr |]<M,o> = M0 , (pn,v ) 0 0 where M0 = ({}, {}, {r M }, {}, {}), r M (o) Jesús M. Almendros-Jiménez and Luis Iribarne = [|expr |]M (pn,v ) = [|expr |]M (pn,v ) A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work PTL Declarative Semantics (IV) Theorem (Soundness and Completeness) Given a PTL program P, a model M that interprets the meta-models of P, and M0 = ∪1≤i≤n [|ri |]M , where RP ≡ r1 , . . . , rn , then: 0 o ∈ OM iff o is a logic consequence of the program enc(RP ) ∪ HP ∪ enc(M) ∪ MMP . Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions 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). Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions 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). Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work PTL interpreter ptl(Program):-[Program], generate_metamodels, generate_rules, load_models, clean_transformation. Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work PTL interpreter load_model(A) :-object(A, B, C, D, E, assert(objectM(A, B, C, D, E, fail. load_model(A) :-associationObjects(A, assert(associationObjectsM(A, fail. load_model(_). Jesús M. Almendros-Jiménez and Luis Iribarne F), F)), B, C, D), B, C, D)), A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work Running a transformation ?- transform([’mm2er.ptl’,’er2rl.ptl’,’rl2mm.ptl’]). Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work Running a transformation transform(Files):-clean_ptl, transform_files(Files). transform_files([]):-!. transform_files([F|RF]):-ptl(F), transform_files(RF). Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions 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 Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work Debugger ?- debugging([’mm2er.ptl’,’er2rl.ptl’,’rl2mm.ptl’]). Debugger: Objects of: table2_er2rl cannot be created. Found error in: resolveTemp Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work Tracer ?- tracing([’mm2er.ptl’,’er2rl.ptl’,’rl2mm.ptl’],’275284307 q275325284r2f2c’). Tracing the element: 275284307q275325284r2f2c Rule: foreign1_rl2mm Element: foreign Metamodel: rl Rule: foreign2_er2rl Element: qualifier Metamodel: er .... Element: property Metamodel: mm xmi:id is wfP6O_iGCkzsbgVr Element: property Metamodel: mm xmi:id is CrZGO_iGCkzsbhYY Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm Motivation Model Transformation PTL: Prolog-based Transformation Language Conclusions and Future Work Conclusions and Future Work PTL: Prolog based Transformation Language Details can be found at http://indalog.ual.es/mdd Declarative Semantics, Debugging, Tracing. Future: Model validation, rule validation, etc Future: More about debugging and tracing Future: Eclipse plugin for transformation Jesús M. Almendros-Jiménez and Luis Iribarne A Model Transformation Language based on Logic Programm