An Automatic Method for Industrial Software Code Generation Based on Data and Behavioral Models
Patent Information
- Application Number
- CN202210859360.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-21
- Publication Date
- 2026-09-01
- Estimated Expiration
- 2042-07-21
AI Technical Summary
但是Velocity仅适用于JAVA语言,工业软件大多采用C或C++开发,目前还没有相关的工具工业软件领域
[0017] Industrial software is a crucial tool for improving quality, reducing costs, and increasing efficiency in industrial development. It involves numerous data models and complex data processing. Currently, my country largely relies on imports for industrial software, while developing it independently requires significant human and material resources to realize massive data processing systems. Therefore, automation is urgently needed to assist in independent development. This invention, based on MBSE model systems engineering theory, performs multi-perspective top-level requirements modeling and architecture design for the requirements, design, analysis, verification, and validation of complex data processing systems in industrial software. It extracts data and behavioral characteristics of the system based on domain-driven learning to achieve model construction of complex data processing systems. Combining relational database theory and compiler technology, it designs an automatic code generation tool specifically for complex data processing. Using this tool, the code framework of complex data processing systems can be realized, effectively reducing the error rate of manually written code, ensuring the security and reliability of data processing code development, improving development efficiency, and reducing development costs.
Smart Images

Figure CN117492723B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of industrial software, specifically a method for automatically generating industrial software code based on data and behavioral models. Background Technology
[0002] Industrial software is a crucial tool for improving quality, reducing costs, and increasing efficiency in industrial development. It involves numerous data models and complex data processing. Currently, my country relies heavily on imports for industrial software, while developing it independently requires significant human and material resources to realize massive data processing systems. Complex data processing systems involve multiple different data models and processing mechanisms. Developing such systems dramatically increases the complexity of the R&D process and the organizational structure of the development team. Some data models are similar, and developers sometimes spend a large amount of time on repetitive development tasks, necessitating an automated code generation tool to improve work efficiency.
[0003] Currently, there are four methods for automatic code generation: (1) Object-relational code generation This approach is suitable for projects using relational database frameworks. Currently, large-scale internet systems use this technology to implement framework code, such as IBM's WebSphere service framework, Hibernate architecture, Spring architecture, and Microsoft's .NET framework. It interprets the relational database model, encapsulates database read and write functionalities, generates the framework structure, and provides external access interfaces. However, this method is only suitable for systems with pre-existing relational data models and can only generate database-related code; it cannot meet the code generation requirements for functionality and behavior control.
[0004] (2) Contract-based code generation Building upon object-oriented principles, this extends to aspect-oriented programming (AOP), which reduces the coupling of business logic through business separation. A representative tool is Spring's AOP approach, which employs a horizontal extraction mechanism to replace the repetitive code in traditional vertical inheritance hierarchies (performance monitoring, transaction management, security checks, caching). It extracts common behaviors, and each common behavior (cross-cutting concern) can be configured as an "advice." Using dynamic proxies, the "advice" can be executed where needed; the point of execution is called the "pointcut." The advice and pointcut constitute an "aspect." This method of "horizontally cutting" vertically encapsulated objects and then "weaving" advice into them improves program reusability and reliability. This generation method has slightly lower performance, is only applicable to method calls, and must be implemented within the Spring container. Additionally, Microsoft's VS extension tool, CodeContracts for .NET, is more suitable for unit testing scenarios. Currently, there are no suitable tools for industrial software code generation.
[0005] (3) Model-based code generation Model-based code generation first abstracts the software into a model, then converts the model into code based on the mapping relationship between the model and code. Representative tools include AndroMDA and Trufun. AndroMDA can generate deployable applications and other components based on UML models, such as directly generating systems with a Struts+Spring+Hibernate architecture. Currently, it supports BPM4Struts, JBPM, JSF, EJB, Hibernate, JavaMeta, Spring, and WebService. Trufun provides implementations of generation languages based on a general MDA code generation framework: currently supporting Java, C#, Ansi C++, Delphi, Perl, Php5, Python, Database, Ruby, and Hibernate. Model-based code generation is efficient and has broad applicability; however, established mature frameworks are mostly more suitable for building database processing, MVC, and web systems, and are widely used in the internet field. Currently, there are no mature framework tools for the industrial control field.
[0006] (4) Template-based code generation Template-based code generation includes two types. The first is front-end code generation, which is the most basic, simplest, and currently the most widely used code generation method. The most well-known front-end code generation tools are vue-cli and create-react-app, which generate code for one-click project initialization based on the Vue and React frameworks, respectively. While the development model is simple, the code repetition rate is high, and its applicability is limited to web frameworks, not industrial software.
[0007] The second approach is generic programming in C++ and Java. This combines programmable data models with template engines, integrating variable and invariant components to ultimately generate the target code. A representative tool, Velocity, offers user-defined template functionality, allowing users to generate various types of source code from key information. However, Velocity is only compatible with Java; most industrial software is developed in C or C++, and there are currently no dedicated tools for this in the industrial software field.
[0008] This invention aims to model the data and behavior of industrial software based on Model Systems Engineering (MBSE), and proposes an automatic code generation method for industrial software based on data and behavior models, thereby improving the code development efficiency of industrial software in the field of industrial control. Summary of the Invention
[0009] This invention provides an automatic industrial software code generation method based on data and behavioral models to solve the problems mentioned in the background art.
[0010] To achieve the above objectives, the present invention provides the following technical solution: An automatic code generation method for industrial software based on data and behavioral models includes the following steps: Step 1: Multi-perspective top-level requirement modeling based on Model Systems Engineering (MBSE): Based on Model Systems Engineering (MBSE), multi-perspective top-level requirement modeling is performed on the data and behavior of complex data processing systems in industrial software to realize data, operation and logic analysis models; Step 2: Extract feature definitions for data and behavior: Use a domain-driven model to extract feature definitions for data and behavior, enabling modeling of data, dynamics, behavior, regional functions, and interactions; Step 3: Construct an industrial software data behavior processing model: Design data storage, activity management, and task execution mechanisms, and construct an industrial software data behavior processing model; Step 4: Establish a feature relationship rule engine: Construct a platform-independent data processing structure using JSON format to establish a feature relationship rule engine; Step 5: Generate information templates and code templates: Convert the JSON format to a relational data model to generate information templates and code templates; Step 6: Establish a configuration strategy for multiple target languages based on object-oriented languages; Step 7: Establish code mapping rules: Establish code mapping rules for entities, data, activities, data flows, tasks, scenarios, and structured intermediate models; Step 8: Build an automatic code generation engine: Combine structured data behavior models and code mapping rules to build an automatic code generation engine to generate target code.
[0011] Step 1 specifically includes the following sub-steps: Step 11: Use a requirements diagram derived from a modeling language to model the requirements of the complex data processing system; Step 12: Through three-level decomposition—data analysis, operational analysis, and logical analysis—extract the data processing set of entities, activities, tasks, data flows, scenarios, and interfaces in the system; Step 13: Build models for data, dynamics, behavior, features, functions, and interactions; Step 14: Form a set of requirement use cases, which can be used to extract features that can be processed uniformly and personalized feature sets in the future.
[0012] Step 2, which extracts data and defines behavioral features, specifically includes the following sub-steps: Step 21: Based on the established demand model, the business relationships of complex data processing, and the domain knowledge of industrial software, construct a feature relationship model; Step 22: Based on the demand model, extract the application characteristics of the data, design corresponding data processing strategies, and realize a hierarchical data storage structure; Step 23: Implement activity management and task operation mechanisms based on the data processing structure, match the hierarchical data storage structure, and combine it with scenarios and interfaces to realize resource-based data service management. Design data storage strategies through classification models. Step 24: Use data flow graphs to design access interfaces for different categories of data, and provide indexes and query methods for data access.
[0013] Step 3 specifically includes the following sub-steps: Step 31: Design the data processing management model, feature dictionary, and access model based on the scene set and feature set; Step 32: Based on the scenario set, perform segmentation and domain processing for complex processing business, and construct scenarios for single-function tasks exceeding 1000. Step 33: By dividing data into different scenarios and tasks, the data from multiple activities is divided into data streams according to the activities, and stored data elements are formed. Step 34: From the perspective of scenarios, construct an independent access mode for single-scenario data; from the perspective of tasks, construct a resource service management structure based on task-based management. Step 35: Use a relational database to access and store data, and combine the database sharding and table partitioning model of the relational database to establish a data processing management and access model.
[0014] Step 4 specifically includes the following sub-steps: Step 41: Transform unstructured requirements into structured definitions. Transform the description of unstructured data in the requirement model into structured data that can be understood by computers. Use JSON format to define the structured data, and then convert it into structured data that can be defined in the database. Step 42: Construct a unified feature model through the feature dictionary set, which can realize data processing strategies such as mapping, association, and range.
[0015] Step 6 includes the following sub-steps: Step 61: Based on the three object-oriented languages C++, Java, and C#, establish configuration templates for the programming languages, including development environment, basic syntax (including objects and classes, basic data types, variable types, modifiers, operators, loop structures, conditional statements, etc.), private definitions (arrays, date and time, methods, file operations, exception handling, etc.), object-oriented (inheritance, polymorphism, abstract classes, encapsulation, interfaces, enumerations, packages, etc.), and advanced structures (collections, containers, generics, serialization, network programming, multithreading, comments, etc.) and other strategy configurations. Step 62: By mapping the above strategies to a fixed code framework, it is easier to generate code for the corresponding target platform in the future.
[0016] Step 8 specifically includes the following sub-steps: Step 81: Parse the rules and models by reading the code mapping rules and the models defined in the relational database; Step 82: Traverse the model using a combination of bottom-up and top-down methods, following the hierarchy of data -> activity -> task -> scenario. Step 83: First, analyze the scenario and build the scenario framework code. Then, analyze the tasks and interfaces in the scenario to generate a task model. Continue to delve into the information of activities in the tasks, establish multi-activity class framework code, and finally generate data classes to obtain the framework code of the entire system. Step 84: Using a bottom-up approach, start by filling in the details of the data and data flow relationships, then fill in the details of the activity's operations and interactions, then fill in the details of the tasks and interfaces, and finally fill in the details of the scene's code.
[0017] Industrial software is a crucial tool for improving quality, reducing costs, and increasing efficiency in industrial development. It involves numerous data models and complex data processing. Currently, my country largely relies on imports for industrial software, while developing it independently requires significant human and material resources to realize massive data processing systems. Therefore, automation is urgently needed to assist in independent development. This invention, based on MBSE model systems engineering theory, performs multi-perspective top-level requirements modeling and architecture design for the requirements, design, analysis, verification, and validation of complex data processing systems in industrial software. It extracts data and behavioral characteristics of the system based on domain-driven learning to achieve model construction of complex data processing systems. Combining relational database theory and compiler technology, it designs an automatic code generation tool specifically for complex data processing. Using this tool, the code framework of complex data processing systems can be realized, effectively reducing the error rate of manually written code, ensuring the security and reliability of data processing code development, improving development efficiency, and reducing development costs. Attached Figure Description
[0018] Figure 1 Automatic code generation tool processing flow.
[0019] Figure 2 Requirements analysis modeling based on MBSE.
[0020] Figure 3 Feature-relationship model analysis.
[0021] Figure 4 Structured data based on JSON definitions.
[0022] Figure 5 Platform-independent complex number processing models.
[0023] Figure 6 Automatic code generation mechanism. Detailed Implementation
[0024] To achieve the above objectives, the present invention implements the following technical solution: like Figures 1-6 As shown, the specific implementation scheme of the industrial software code automatic generation method based on data and behavior models of the present invention is as follows: Work process as follows Figure 1 As shown, requirements analysis is conducted based on Model Systems Engineering (MBSE), feature definitions of data and behavior are extracted, an industrial software data behavior processing model is constructed, a feature relationship rule engine is established, and a structured data behavior model is generated. The configuration strategy of multi-target language is analyzed, code mapping rules are established, and combined with the structured data behavior model, an automatic code generation engine is constructed to generate target code.
[0025] 1. Requirements Model Construction Based on the MBSE model, a requirements analysis is conducted on data processing in complex systems, and a system requirements model is constructed. The characteristics of complex data processing are uniformly summarized, such as... Figure 2 As shown, through three-level decomposition of data analysis, operation analysis, and logic analysis, the data processing set of entities, activities, tasks, data flows, scenarios, and interfaces in the system is extracted. Models of data, dynamics, behavior, features, functions, and interactions are constructed to form a set of requirement use cases, which can be used to extract features that can be processed uniformly and personalized feature sets in the future.
[0026] 2. Model Definition (1) Definition according to Figure 2 Define the elements to be analyzed: data entity (dx), activity (act), task (task), data flow (df), scene (scene), and interface (inf).
[0027] ① Data Definition For complex system data, data is the core of the system. Data modeling requirements mainly include basic characteristics such as data source, type, attributes, and scope, as well as data objectives transformed based on activities, tasks, etc. Assuming a single data entity is dx, then dx is represented by a quintuple: For each dx, define name to represent the name of the data, source to represent the data source, type to represent the data type, attribute to represent the data attribute, and range to represent the data range.
[0028] Then all the data sets in the system are defined as: .
[0029] ② Activity Definition An activity (act) is represented by a triple: ; Define a name for each activity, and specify the input data for that activity. Output data And the task to which the activity belongs.
[0030] The set of all activities in the system is defined as follows: .
[0031] ③Task Definition A task is a set of activities that perform multiple actions to complete a specific function; therefore, a task is represented by a triple: ; Define a name for each task, and define the set of activities (acts) for that task as follows: The data set dx is .
[0032] but , .
[0033] The set of all tasks in the system is then defined as: .
[0034] ④ Data Flow Definition Data stream df is represented by triples: ; Define a name for each data stream, and specify the entry activity for that data stream. t and export activities .
[0035] The set of all data streams in the system is defined as follows: .
[0036] ⑤Scene Definition A scene is a combination of tasks that implement specific system functions. Tasks interact directly with each other through an interface.
[0037] Then scene is represented by a triple: ; Define a name for each task, and define the set of tasks in this scenario as follows: The interface inf collection is .
[0038] but , .
[0039] The set of all scenarios in the system is defined as follows: .
[0040] ⑥ Interface Definition The interface inf is represented by a triple: ; Define a name (inf) for each interface, and specify the task that the interface provides. The task that calls this interface And the scene to which this interface belongs.
[0041] The system's entire interface set is defined as follows: .
[0042] (2) Data Analysis In complex data processing systems, the dataset is diverse, and due to the wide variety of data types and changing characteristics, the dataset is a complex collection.
[0043] For data The following transformations exist: ; For data transformation activities, where data changes are designed based on activity breakdowns, a large set of activities will result. The next section will further analyze how to extract features from this set of activities.
[0044] Data flow is the transfer of data between two activities; it is a dynamic concept.
[0045] For data streams The following transformations exist: ; (3) Operational analysis In complex data processing systems, an activity is the smallest computational unit triggered by an action or event. Its actual execution depends on the specific functions of the business system, thus making it a behavioral concept.
[0046] For the activity The following transformations exist: ; A scenario is a combination of one or more activities in a complex processing system. Scenarios are defined according to the functional partitions of the business system, and therefore a scenario is a regional concept.
[0047] For the scenario The following relationship exists: (4) Logical analysis Tasks and interfaces are modeling objects obtained by decomposing system requirements from a logical level. A task is a collection of activities and a functional concept.
[0048] For the task The following relationship exists: ; An interface is an object for interaction between tasks; it is a concept of interactive behavior.
[0049] For the interface The following relationship exists: .
[0050] (5) Feature Relationship Extraction Based on the established demand model, the business relationships involved in complex data processing, and the domain knowledge of industrial software, a feature relationship model is constructed, such as... Figure 3 As shown, by combining the demand model, the application characteristics of the data are extracted, corresponding data processing strategies are designed, and a hierarchical data storage structure is realized. Based on the data processing structure, activity management and task operation mechanisms are implemented, matching the hierarchical nature of the data storage structure, and combining it with scenarios and interfaces to realize resource-based data service management. Data storage strategies are designed through a classification model. Access interfaces for different categories of data are designed using data flow diagrams, providing indexes and query methods for data access.
[0051] 3. Rule Engine (1) Transforming unstructured requirements into structured definitions The process transforms unstructured data descriptions of demand models into structured data that can be understood by computers. This is achieved using JSON format to define the structured data, which is then converted into structured data that can be defined in a database. Figure 4 As shown.
[0052] (2) Platform-independent complex data processing model Based on the structured data model defined in JSON, a platform-independent data processing model is constructed. For example... Figure 5 As shown, a data processing management model, feature dictionary, and access model are designed based on scenario sets and feature sets. The scenario set is used to segment and domain complex processing tasks; for single-function tasks exceeding 1000, scenarios are constructed by partitioning them. By dividing data into scenarios and tasks, multi-activity data is divided into data and data streams according to activities, forming stored data elements. From a scenario perspective, data in a single scenario has an independent access model; from a task perspective, task-based data processing is beneficial for the analysis and processing of complex data. A relational database is used for data access, and the data processing management and access model is established using the relational database's sharding and partitioning model. Simultaneously, a unified feature model is constructed with the feature dictionary set, enabling data processing mapping, association, and range-based processing strategies, facilitating subsequent automated code generation.
[0053] 4. Model-based automatic code generation mechanism Platform-independent data processing models are software structures that combine templates and hierarchical structures, requiring more detailed descriptions. For example... Figure 6 As shown, the first challenge is how to achieve the mapping between the model and the generated code. Therefore, it is necessary to design a code mapping rule to represent the mapping relationship between the model and the code template, serving as the basis for code generation. Secondly, it is necessary to establish configuration strategies for different languages. This research focuses on object-oriented programming languages, specifically C++, Java, and C#. It uses general object-oriented definitions to generate language configuration strategies and designs an automatic code generation engine to generate the corresponding target code.
[0054] (1) Code mapping rules This article briefly introduces the code mapping rules for some content.
[0055] ①Entity: Directly map the data structure and objects in the template to generate classes, and directly parse the definitions in the JSON structured template to generate the corresponding classes.
[0056] ② Data: Data is also a type of entity with a defined structure. The data in the template can be directly defined as a class.
[0057] ③ Activities: Activities are data transformations. Activities need to be based on entities. Therefore, in the entity model, simple activity operations are transferred to classes, and new data objects may be generated based on the operation.
[0058] ④ Data flow: Each data flow must be unidirectional; otherwise, errors may be introduced.
[0059] A data flow is a local operation between two activities, involving only a small number of methods or classes at a time, and each change to a data flow needs to be isolated from changes to other data flows.
[0060] ⑤ Task: A task contains a series of activities, data, data flows, and interfaces with other tasks. We can redefine elements such as resources, components, interfaces, operations, and subtasks within a task to describe the task's objectives.
[0061] ⑥ Scenarios: Each scenario represents an independent business process. Scenarios can interact directly with each other, or they can run individually or concurrently as modules. Tasks across multiple scenarios can run concurrently. Each scenario is mapped to a separate folder.
[0062] ⑦ Relational Database: Define the model as a structured JSON format description. The JSON data serves only as an intermediate model. By adding interaction relationships and connection links, access management between various models is formed into template data, which is then uniformly generated into the relational database. Define the mapping relationship between programmable information templates and code templates in the relational database, and determine the definitions of data types, interfaces, parameters, views, and regions.
[0063] (2) Programming language configuration strategy This paper studies code generation for object-oriented languages. Based on three object-oriented languages—C++, Java, and C#—it establishes configuration templates for programming languages, including development environment, basic syntax (including objects and classes, basic data types, variable types, modifiers, operators, loop structures, conditional statements, etc.), private definitions (arrays, date and time, methods, file operations, exception handling, etc.), object-oriented features (inheritance, polymorphism, abstract classes, encapsulation, interfaces, enumerations, packages, etc.), and advanced structures (collections, containers, generics, serialization, network programming, multithreading, comments, etc.). By mapping these strategies to a fixed code framework, it is easier to generate code for the corresponding target platform later.
[0064] (3) Automatic code generation engine The automatic code generation engine reads code mapping rules and models defined in a relational database, parses the rules and models, and generates specific code according to the rules based on the models described in the relational database using specific generation algorithms.
[0065] Considering the hierarchical structure of data -> activity -> task -> scenario, a combination of bottom-up and top-down approaches is used to generate code. First, the scenario is analyzed to build the scenario framework code. Then, tasks and interfaces within the scenario are analyzed to generate task models. Further, information about activities within the tasks is extracted to build a multi-activity class framework code. Finally, data classes are generated, resulting in the overall system framework code. Since the top-down approach only generates the framework code, a bottom-up approach is used again, starting with the data to complete the details of data and data flow relationships. Next, the operation and interaction processing of activities are completed, followed by the details of tasks and interfaces, and finally, the detailed code within the scenario is completed.
[0066] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the present invention should be covered within the scope of protection of the claims of the present invention.
Claims
1. A method for automatically generating industrial software code based on data and behavioral models, characterized in that, Includes the following steps: Step 1: Multi-perspective top-level requirement modeling based on Model Systems Engineering (MBSE): Based on Model Systems Engineering (MBSE), multi-perspective top-level requirement modeling is performed on the data and behavior of complex data processing systems in industrial software to realize data, operation and logic analysis models; Step 2: Extract feature definitions for data and behavior: Use a domain-driven model to extract feature definitions for data and behavior, enabling modeling of data, dynamics, behavior, regional functions, and interactions; Step 3: Construct an industrial software data behavior processing model: Design data storage, activity management, and task execution mechanisms, and construct an industrial software data behavior processing model; Step 4: Establish a feature relationship rule engine: Construct a platform-independent data processing structure using JSON format to establish a feature relationship rule engine; Step 5: Generate information templates and code templates: Convert the JSON format to a relational data model to generate information templates and code templates; Step 6: Establish a configuration strategy for multiple target languages based on object-oriented languages; Step 7: Establish code mapping rules: Establish code mapping rules for entities, data, activities, data flows, tasks, scenarios, and structured intermediate models; Step 8: Build an automatic code generation engine: Combine structured data behavior models and code mapping rules to build an automatic code generation engine to generate target code.
2. The method for automatically generating industrial software code based on data and behavioral models according to claim 1, characterized in that, Step 1 includes the following sub-steps: Step 11: Use a requirements diagram derived from a modeling language to model the requirements of the complex data processing system; Step 12: Through three-level decomposition—data analysis, operational analysis, and logical analysis—extract the data processing set of entities, activities, tasks, data flows, scenarios, and interfaces in the system; Step 13: Build models for data, dynamics, behavior, features, functions, and interactions; Step 14: Form a set of requirement use cases, which can be used to extract features that can be processed uniformly and personalized feature sets in the future.
3. The method for automatically generating industrial software code based on data and behavioral models according to claim 1, characterized in that, Step 2 includes the following sub-steps: Step 21: Based on the established demand model, the business relationships of complex data processing, and the domain knowledge of industrial software, construct a feature relationship model; Step 22: Based on the demand model, extract the application characteristics of the data, design corresponding data processing strategies, and realize a hierarchical data storage structure; Step 23: Implement activity management and task operation mechanisms based on the data processing structure, match the hierarchical data storage structure, and combine it with scenarios and interfaces to realize resource-based data service management. Design data storage strategies through classification models. Step 24: Use data flow graphs to design access interfaces for different categories of data, and provide indexes and query methods for data access.
4. The method for automatically generating industrial software code based on data and behavioral models according to claim 1, characterized in that, Step 8 includes the following sub-steps: Step 81: Parse the rules and models by reading the code mapping rules and the models defined in the relational database; Step 82: Traverse the model using a combination of bottom-up and top-down methods, following the hierarchy of Data 1 > Activity 1 > Task 1 > Scenario. Step 83: First, analyze the scenario and build the scenario framework code. Then, analyze the tasks and interfaces in the scenario to generate a task model. Continue to delve into the information of activities in the tasks, establish multi-activity class framework code, and finally generate data classes to obtain the framework code of the entire system. Step 84: Using a bottom-up approach, start by filling in the details of the data and data flow relationships, then fill in the details of the activity's operations and interactions, then fill in the details of the tasks and interfaces, and finally fill in the details of the scene's code.
Citation Information
Patent Citations
Industrial software design and application platform
CN111752552A
Method for integrating FMU file, solver operation environment and industrial software
CN112363694A