# 模型转换

模型转换是一种软件工程技术，它根据转换描述从一个或多个源模型自动生成一个或多个目标模型。<sup>[1](https://staffwww.dcs.shef.ac.uk/people/A.Simons/remodel/papers/BiehlModelTransformations.pdf)</sup> M2M转换以模型为输入、以模型为输出，而M2T转换以模型为输入、以文本为输出；两种情况下，输入模型都是符合某个元模型（定义其他模型的结构/规则的模型）的元素，该元模型通常定义了某种建模记法的抽象语法。转换分为两类。模型到模型（M2M）转换将其目标创建为目标元模型的实例，而模型到文本（M2T）转换产生字符串，例如Java源代码。<sup>[2](https://gsd.uwaterloo.ca/sites/default/files/ibm06.pdf)</sup> M2M转换完全在模型驱动工程的技术空间内运作，而M2T则将该空间与语法和文本所在的语法件空间连接起来。<sup>[3](https://wiki.eclipse.org/images/c/ce/OMCW_chapter10_Modelplex-WP6-Training_ComparingM2TandM2M.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 输入与输出 | 一个或多个符合源元模型的源模型；一个或多个目标模型（M2M）或文本（M2T）<sup>[2](https://gsd.uwaterloo.ca/sites/default/files/ibm06.pdf)</sup> |
| 转换即模型 | 转换定义本身就是一个模型，它符合某个转换元模型，而该元模型又符合诸如MOF或Ecore之类的元元模型<sup>[4](https://help.eclipse.org/latest/topic/org.eclipse.m2m.atl.doc/guide/concepts/Model-Transformation.html)</sup> |
| 标准化 | OMG于2002年4月发布QVT征求建议书；最终采纳的规范于2005年11月出台<sup>[2](https://gsd.uwaterloo.ca/sites/default/files/ibm06.pdf)</sup> |
| QVT语言 | QVT定义了三种相关语言：Relations、Operational Mappings和Core<sup>[5](https://www.omg.org/spec/QVT)</sup> |
| ATL执行 | 两个阶段：匹配所有规则模式并创建目标元素和追踪链接，然后执行所有绑定；在没有惰性规则或被调用规则的情况下是确定性的且可终止的<sup>[6](https://staffwww.dcs.shef.ac.uk/people/A.Simons/remodel/papers/JouaultKurtevATL.pdf)</sup> |
| 可扩展性限制 | 基于图的执行涉及NP完全的子图同构问题，因此运行时间随模型和规则集规模显著增长<sup>[7](https://ceur-ws.org/Vol-1652/paper3.pdf)</sup> |
| 近期趋势 | ATL、ETL、QVT和Henshin等专用转换语言在学术会议、期刊和开源代码库中的热度已经衰退<sup>[8](https://link.springer.com/article/10.1007/s10270-026-01360-2)</sup> |

## 工作原理

源模型和目标模型都符合各自的元模型，转换是相对于这些元模型定义的；转换引擎在具体模型上执行该定义。<sup>[2](https://gsd.uwaterloo.ca/sites/default/files/ibm06.pdf)</sup> 由于该定义本身就是一个符合转换元模型的模型，再加上源元模型、目标元模型以及诸如MOF或Ecore之类的共享元元模型，整个配置可以用与其他任何模型相同的工具来操作和检查。<sup>[4](https://help.eclipse.org/latest/topic/org.eclipse.m2m.atl.doc/guide/concepts/Model-Transformation.html)</sup>

规则和模式匹配驱动执行。在ATL——一种混合了声明式和命令式构造的混合语言——中，对匹配项执行规则会创建一个可追溯性链接，关联三个组成部分：规则、匹配的源元素和新创建的目标元素。<sup>[6](https://staffwww.dcs.shef.ac.uk/people/A.Simons/remodel/papers/JouaultKurtevATL.pdf)</sup> 在QVT Relations中，关系由两个或多个域定义，并可包含可选的when和where子句；域带有checkonly或enforced模式，形成先检查后强制满足关系的语义：对checkonly域检查是否存在有效匹配，当执行朝向某个enforced域推进而检查失败时，则修改目标模型以满足该关系。<sup>[5](https://www.omg.org/spec/QVT)</sup>

正确性有分级的概念。最简单的是语法正确性，保证从良构的源得到良构的目标；语义正确性则复杂得多。期望的性质还包括双向性、带变更传播的可追溯性以及高阶转换。<sup>[9](https://drops.dagstuhl.de/storage/16dagstuhl-seminar-proceedings/dsp-vol04101/DagSemProc.04101.2/DagSemProc.04101.2.pdf)</sup>

## 如何实施

实践者首先确定源元模型和目标元模型，然后针对它们编写规则。在ATL中，单元有三种：用于模型到模型转换的模块、从源模型计算字符串或整数等原始值的查询，以及用于提取和复用公共代码的库。<sup>[10](https://help.eclipse.org/latest/topic/org.eclipse.m2m.atl.doc/guide/user/Overview-of-the-Atlas-Transformation-Language.html)</sup> 规则有三种，对应两种编程模式：匹配规则（声明式）、惰性规则（仅在调用时应用）和被调用规则（命令式，显式调用并接受参数）。<sup>[10](https://help.eclipse.org/latest/topic/org.eclipse.m2m.atl.doc/guide/user/Overview-of-the-Atlas-Transformation-Language.html)</sup>

ATL模块的执行依次经过三个阶段：模块初始化、源模型元素匹配和目标模型元素初始化。<sup>[10](https://help.eclipse.org/latest/topic/org.eclipse.m2m.atl.doc/guide/user/Overview-of-the-Atlas-Transformation-Language.html)</sup> 在规则求值的更细粒度上，第一阶段匹配所有规则模式并创建目标元素和可追溯性链接，第二阶段执行所有绑定；在没有惰性规则或被调用规则的情况下，执行是确定性的且可终止的。<sup>[6](https://staffwww.dcs.shef.ac.uk/people/A.Simons/remodel/papers/JouaultKurtevATL.pdf)</sup>

实现要么使用诸如ATL、MOFScript或Epsilon之类的转换领域特定语言，要么使用Java或C#之类的通用语言；将M2M和M2T步骤组合起来可提供模块化、可扩展性、可重用性、同质性和抽象性。<sup>[3](https://wiki.eclipse.org/images/c/ce/OMCW_chapter10_Modelplex-WP6-Training_ComparingM2TandM2M.pdf)</sup>

## 起源

标准化之路经由对象管理组的模型驱动架构。QVT（Query/Views/Transformations，查询/视图/转换）标准化过程旨在为将平台无关模型转换为平台特定模型奠定基础。<sup>[11](https://ipa.win.tue.nl/archive/springdays2005/czarnecki.pdf)</sup> 该征求建议书促成了最终采纳的规范，即OMG文档ptc/05-11-01。<sup>[12](https://wiki.eclipse.org/images/1/1e/OMCW_chapter10_IntroductionToMOFQVT.INRIA.pdf)</sup> 1.0版于2008年4月正式采纳，随后是2011年1月的1.1版、2015年2月的1.2版和2016年6月的1.3版。<sup>[5](https://www.omg.org/spec/QVT)</sup> 另有一份针对MOF 2.0模型到文本语言的独立征求建议书，因此M2T与M2M是分开标准化的。<sup>[2](https://gsd.uwaterloo.ca/sites/default/files/ibm06.pdf)</sup>

围绕该标准，研究文献逐渐增多：K. Czarnecki和S. Helsen于2006年在《IBM系统杂志》上发表的基于特征的综述按转换特征组织了该领域，<sup>[2](https://gsd.uwaterloo.ca/sites/default/files/ibm06.pdf)</sup> Frédéric Jouault和Ivan Kurtev于2006年提出了ATL语言及其语义。<sup>[6](https://staffwww.dcs.shef.ac.uk/people/A.Simons/remodel/papers/JouaultKurtevATL.pdf)</sup>

## 变体

范式空间沿若干轴线描述。内生转换在同一语言的模型之间运作（改写：重构、优化、规范化），而外生转换跨语言进行（翻译：合成与代码生成、逆向工程、迁移）；外生转换总是外置的。<sup>[8](https://link.springer.com/article/10.1007/s10270-026-01360-2)</sup> 声明式方法关注什么被转换为什么，并提供具有隐式规则排序的双向性；操作式方法关注转换如何执行，对应用顺序有更好的控制。<sup>[9](https://drops.dagstuhl.de/storage/16dagstuhl-seminar-proceedings/dsp-vol04101/DagSemProc.04101.2/DagSemProc.04101.2.pdf)</sup> 高阶转换（HOT）是一种以转换模型为源或目标的转换描述。<sup>[1](https://staffwww.dcs.shef.ac.uk/people/A.Simons/remodel/papers/BiehlModelTransformations.pdf)</sup>

具名语言在这些轴线上各有不同。QVT Relations是声明式的，支持双向转换、一致性检查、强制满足关系、同步和就地转换，具有隐式追踪模型；QVT Operational用OCL的命令式扩展中的映射来规定单向转换，可与C等过程式语言相比。<sup>[1](https://staffwww.dcs.shef.ac.uk/people/A.Simons/remodel/papers/BiehlModelTransformations.pdf)</sup><sup> • </sup><sup>[13](https://research.cs.queensu.ca/home/cordy/Papers/KBCDV_SoSyM18_MTSurvey.pdf)</sup> 普通ATL转换通常是单向的，使用独立的源模型和目标模型，因此目标中的手动更改不会被自动保留，但ATL也提供了一种用于就地转换的精化模式。<sup>[2](https://gsd.uwaterloo.ca/sites/default/files/ibm06.pdf)</sup><sup> • </sup><sup>[1](https://staffwww.dcs.shef.ac.uk/people/A.Simons/remodel/papers/BiehlModelTransformations.pdf)</sup> ETL是一种混合的、基于规则的M2M语言，构建在Epsilon平台内的EOL之上，能够将多个输入模型转换为多个输出模型，并查询、导航和修改源模型与目标模型。<sup>[14](https://itea4.org/project/workpackage/document/download/2305/D3.1.1.%20ModelWriter%20-%20Review%20of%20Model-to-Model%20Transformation%20Approaches%20and%20Technologies.pdf)</sup> Henshin由Thorsten Arendt及其同事于2010年在模型驱动工程语言与系统会议上提出，是一套用于EMF模型就地转换的语言和工具集，在具有良定义操作语义的嵌套转换单元中使用基于模式的规则，基于代数图变换；其合并单元提供了用于并行模式替换的forall算子。<sup>[15](https://cadp.inria.fr/ftp/publications/others/Arendt-Biermann-Jurack-Krause-Taentzer-10.pdf)</sup> 基于TGG的工具维护对应图，其中保存输入和输出元素之间的N对N追踪信息。<sup>[13](https://research.cs.queensu.ca/home/cordy/Papers/KBCDV_SoSyM18_MTSurvey.pdf)</sup> M2T语言包括Acceleo、EGL、MOFScript和Xtend，基于模板的方法比基于访问器的方法受欢迎得多。<sup>[16](https://javiertroyauma.github.io/publications/ACM_CSUR22-Accepted.pdf)</sup><sup> • </sup><sup>[13](https://research.cs.queensu.ca/home/cordy/Papers/KBCDV_SoSyM18_MTSurvey.pdf)</sup>

## 应用

大多数MDA工具支持基于模板的模型到文本生成，工具包括openArchitectureWare、JET、AndroMDA、ArcStyler、MetaEdit+和OptimalJ。<sup>[2](https://gsd.uwaterloo.ca/sites/default/files/ibm06.pdf)</sup> 基于MDD的系统已在泰雷兹、空客、波音和爱立信等大公司广泛使用。<sup>[13](https://research.cs.queensu.ca/home/cordy/Papers/KBCDV_SoSyM18_MTSurvey.pdf)</sup> Eclipse ATL转换动物园收集了一百多个示例转换。<sup>[3](https://wiki.eclipse.org/images/c/ce/OMCW_chapter10_Modelplex-WP6-Training_ComparingM2TandM2M.pdf)</sup>

## 局限与替代方案

失败模式源于范式本身。基于图变换的方法如VIATRA、ATOM3、GreAT、UMLX和BOTL功能强大且是声明式的，但最为复杂，原因在于调度中的非确定性以及对终止性和合流性的担忧。<sup>[11](https://ipa.win.tue.nl/archive/springdays2005/czarnecki.pdf)</sup> 在标准化方面，一项系统性文献综述发现，对于转换开发的建模语言没有共识，而OMG作为标准提出的QVT实际上并未被广泛采用。<sup>[17](https://www.scitepress.org/Papers/2020/93801/93801.pdf)</sup> 与程序转换相比，模型转换分类学将模型转换定位为涵盖程序转换，其中内生改写对应于重构和优化。<sup>[9](https://drops.dagstuhl.de/storage/16dagstuhl-seminar-proceedings/dsp-vol04101/DagSemProc.04101.2/DagSemProc.04101.2.pdf)</sup>

对于双向转换（bx），如果转换产生一致的相关模型对，则它是正确的；如果它不改变已经相互一致的模型，则它是希波克拉底式的；已测试的法则还包括最小变更、最小惊讶、往返法则、终止性和完备性。<sup>[18](https://josh-hs-ko.github.io/manuscripts/SoSyM20.pdf)</sup> 对于任意拓扑的双向转换网络，不存在保证结果模型一致的通用执行策略，只有当策略是不完备的——即允许在某些变更下即使存在成功的执行顺序也无法恢复一致性——时才能保证终止。<sup>[19](https://dl.acm.org/doi/10.1145/3543845)</sup>

可扩展性是一个经过实测的关切。基于图的执行涉及NP完全的子图同构问题，有一例报告称引擎无法执行具有250条规则的转换系统。<sup>[7](https://ceur-ws.org/Vol-1652/paper3.pdf)</sup> 验证技术按转换、所关注的性质和技术进行编目；例子包括Dániel Varró及其同事于2006年提出的通过Petri网进行图变换系统终止性分析的方法，以及OCL契约和QVT转换的形式验证。<sup>[20](https://www.sciencedirect.com/science/article/pii/S1571066113000042)</sup>

自2023年以来，LLM辅助转换已成为一个活跃的研究方向，并有实测局限。一项提示ChatGPT-4将99个UML类图XMI模型转换为Java的实验达到了94%的累计成功率，对于具有大量关联的复杂模型则降至17%；所有生成的目标都符合目标元模型，作者得出结论：对于高精度、可重复的转换，DSL仍然是更可取的选择。<sup>[21](https://ceur-ws.org/Vol-4122/paper15.pdf)</sup>

## References

1. [State of the Art in Model Transformation Technology (Biehl, 2010)](https://staffwww.dcs.shef.ac.uk/people/A.Simons/remodel/papers/BiehlModelTransformations.pdf)
2. [Feature-Based Survey of Model Transformation Approaches (Czarnecki & Helsen, IBM Systems Journal 2006)](https://gsd.uwaterloo.ca/sites/default/files/ibm06.pdf)
3. [Comparing M2T & M2M Complementary Approaches (MODELPLEX training, INRIA/York/SINTEF)](https://wiki.eclipse.org/images/c/ce/OMCW_chapter10_Modelplex-WP6-Training_ComparingM2TandM2M.pdf)
4. [ATL Concepts - Model Transformation (Eclipse documentation)](https://help.eclipse.org/latest/topic/org.eclipse.m2m.atl.doc/guide/concepts/Model-Transformation.html)
5. [About the MOF Query/View/Transformation Specification Version 1.3](https://www.omg.org/spec/QVT)
6. [Transforming Models with ATL (Jouault & Kurtev, LNCS 3844)](https://staffwww.dcs.shef.ac.uk/people/A.Simons/remodel/papers/JouaultKurtevATL.pdf)
7. [Scalability of Model Transformations: Position Paper and Benchmark Set (BigMDE)](https://ceur-ws.org/Vol-1652/paper3.pdf)
8. [Have model transformation languages failed? (Software and Systems Modeling)](https://link.springer.com/article/10.1007/s10270-026-01360-2)
9. [A Taxonomy of Model Transformations (Mens, Van Gorp et al., Dagstuhl Seminar 04101)](https://drops.dagstuhl.de/storage/16dagstuhl-seminar-proceedings/dsp-vol04101/DagSemProc.04101.2/DagSemProc.04101.2.pdf)
10. [ATL User Guide - Overview of the Atlas Transformation Language (Eclipse documentation)](https://help.eclipse.org/latest/topic/org.eclipse.m2m.atl.doc/guide/user/Overview-of-the-Atlas-Transformation-Language.html)
11. [Classification of Model Transformation Approaches (Czarnecki & Helsen, 2005)](https://ipa.win.tue.nl/archive/springdays2005/czarnecki.pdf)
12. [An introduction to the MOF 2.0 QVT standard with focus on the Operational Mappings (INRIA lecture)](https://wiki.eclipse.org/images/1/1e/OMCW_chapter10_IntroductionToMOFQVT.INRIA.pdf)
13. [Survey and Classification of Model Transformation Tools (Kähkönen et al., Software & Systems Modeling, 2018)](https://research.cs.queensu.ca/home/cordy/Papers/KBCDV_SoSyM18_MTSurvey.pdf)
14. [D3.1.1 Review of Model-to-Model Transformation Approaches and Technologies (ITEA ModelWriter)](https://itea4.org/project/workpackage/document/download/2305/D3.1.1.%20ModelWriter%20-%20Review%20of%20Model-to-Model%20Transformation%20Approaches%20and%20Technologies.pdf)
15. [Henshin: In-Place EMF Model Transformations (Arendt, Biermann, Jurack, Krause, Taentzer)](https://cadp.inria.fr/ftp/publications/others/Arendt-Biermann-Jurack-Krause-Taentzer-10.pdf)
16. [Model Transformation Testing and Debugging: A Survey (ACM Computing Surveys)](https://javiertroyauma.github.io/publications/ACM_CSUR22-Accepted.pdf)
17. [Developing Model Transformations: A Systematic Literature Review (SCITEPRESS)](https://www.scitepress.org/Papers/2020/93801/93801.pdf)
18. [Benchmarking bidirectional transformations: theory, implementation, application, and assessment (Benchmarx, SoSyM)](https://josh-hs-ko.github.io/manuscripts/SoSyM20.pdf)
19. [Termination and Expressiveness of Execution Strategies for Networks of Bidirectional Model Transformations](https://dl.acm.org/doi/10.1145/3543845)
20. [Verification of Model Transformations: A Survey of the State-of-the-Art](https://www.sciencedirect.com/science/article/pii/S1571066113000042)
21. [Model transformations using LLMs out-of-the-box: can accidental complexity be reduced? (Kazai, Osei, Bucaioni, Cicchetti)](https://ceur-ws.org/Vol-4122/paper15.pdf)

---
*Initially written Sep 29, 2026 · Edited: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Software engineering and development process › Software design and architecture › Titles 4 to Mo

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/model-transformation

English original: https://www.edgepedia.org/model-transformation
