Code generation method and device based on data model, equipment and storage medium
Patent Information
- Application Number
- CN202010213245.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-03-24
- Publication Date
- 2026-10-09
- Estimated Expiration
- 2040-03-24
AI Technical Summary
[0003]目前通常是人工编写数据模型对应的数据处理代码,但是编写数据处理代码的过程耗费人力和时间,生成效率低
[0023] The methods, apparatus, devices, and storage media provided in this application embodiment acquire a data model. The data model includes multiple graphs, which indicate descriptive information of multiple data tables and the relationships between them. This data model, comprising multiple graphs, is a visual data model; users can obtain descriptive information of the data tables and the relationships between them by viewing the connections between the graphs. By converting multiple graphs into corresponding first code elements, and combining these first code elements with template code, data processing code corresponding to the data model is generated. This achieves automatic code generation from the data model, eliminating the need for manual coding of the corresponding code, saving manpower and time, and improving code generation efficiency. Furthermore, the automatically generated data processing code corresponds to the data model, avoiding situations where the data processing code does not match the data model.
Smart Images

Figure CN113448956B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a code generation method, apparatus, device, and storage medium based on a data model. Background Technology
[0002] With the development of computer technology, more and more applications are using data models for data management. A data model is an abstract description of the static characteristics of data, which can include data type, data content, and the correspondence between data. However, data cannot be processed based solely on its static characteristics; data processing requires both the static characteristics and the data processing logic. Therefore, data processing code, which includes the data processing logic, can be written based on the data model, and the data can be processed by running this code.
[0003] Currently, data processing code corresponding to the data model is usually written manually. However, the process of writing data processing code is labor-intensive and time-consuming, resulting in low efficiency. Furthermore, manually written data processing code is often disconnected from the data model, which can easily lead to inconsistencies between the two. Summary of the Invention
[0004] This application provides a code generation method, apparatus, device, and storage medium based on a data model, which can improve code generation efficiency. The technical solution is as follows: On the one hand, a code generation method based on a data model is provided, the method comprising: Obtain a data model, which includes multiple graphs that indicate descriptive information of multiple data tables and the relationships between the multiple data tables; The multiple graphics are converted into corresponding first code elements to obtain multiple first code elements; The data processing code corresponding to the data model is generated by combining and processing the multiple first code elements and template code.
[0005] Optionally, after converting the plurality of graphics into corresponding first code elements to obtain a plurality of first code elements, the method further includes: The plurality of first code elements are stored in the database.
[0006] Optionally, after storing the plurality of first code elements in the database, the method further includes: Obtain the plurality of first code elements stored in the database; The data model corresponding to the plurality of first code elements is obtained by drawing the plurality of first code elements using a drawing tool.
[0007] On the other hand, a code generation apparatus based on a data model is provided, the apparatus comprising: The model acquisition module is used to acquire a data model, which includes multiple graphs that indicate the descriptive information of multiple data tables and the relationships between the multiple data tables. A conversion module is used to convert the plurality of graphics into corresponding first code elements to obtain a plurality of first code elements; The combination module is used to combine the multiple first code elements and template code to generate data processing code corresponding to the data model.
[0008] Optionally, the plurality of graphs includes a plurality of data table graphs and a relational graph, wherein the relational graph is connected to the plurality of data table graphs, each data table graph indicates the descriptive information of a data table, and the relational graph indicates the relational relationship among the plurality of data table graphs; The conversion module includes: The conversion unit is used to convert the plurality of data table graphs into a plurality of first data table code elements and to convert the association graphs into first association code elements.
[0009] Optionally, the relationship graph includes an operation type graph and directed lines. The operation type graph indicates the operation type, and the directed lines indicate the operation direction. Each data table graph is connected to an operation type graph through a directed line, and at least one directed line in the relationship graph carries an operation direction identifier. The conversion unit is also used for: The directed line connecting the operation type graphics carrying the operation direction identifier is converted into operation type code elements; The operation direction identifier is combined with the operation type code element to obtain the first association code element.
[0010] Optionally, the conversion unit is further configured to: Based on the sorting of the multiple data table graphs, the multiple data table graphs are converted into multiple first data table code elements arranged in sequence; The relationship diagram is converted into a first relationship code element.
[0011] Optionally, the plurality of data table graphs includes a plurality of original data table graphs and a target data table graph, the association being the generation of the target data table based on the plurality of original data tables, and the conversion unit is further configured to: Based on the sorting of the multiple original data table graphics, the multiple original data table graphics are converted into multiple original data table code elements arranged in order, and the target data table graphics are converted into target data table code elements. The ordered original data table code elements are arranged to form an original data table code element set; or, the target data table code element is arranged after the original data table code elements, and the original data table code elements and the target data table code element are combined to form a data table code element set.
[0012] Optionally, the relationship graph includes an operation type graph and a directed line, wherein the operation type graph indicates the operation type, the directed line indicates the operation direction, and each data table graph is connected to an operation type graph by a directed line; The conversion unit is also used for: Based on the direction of operation indicated by the directed lines connecting the multiple data table graphs, the multiple data table graphs are converted into multiple first data table code elements arranged in sequence.
[0013] Optionally, the plurality of graphs includes a plurality of data table graphs and a plurality of relationship graphs, each relationship graph being connected to the plurality of data table graphs, and at least one directed line in each relationship graph carrying an operation direction identifier; The conversion unit is also used for: Based on the direction of operation indicated by the directed lines connecting the multiple data table graphs, and the operation type graphs connected by the directed lines, the multiple operation type graphs are converted into multiple operation type code elements arranged in sequence. Based on the sorting of the multiple operation type code elements, each operation type code element is combined with the operation direction identifier carried by the connected directed line to obtain multiple first association code elements arranged in sequence.
[0014] Optionally, the model acquisition module includes: The graphics creation unit is used to create multiple data table graphics, at least one operation type graphics, and directed lines connecting any data table graphics and any operation type graphics based on the data model generation interface. The information adding unit is used to add descriptive information to each data table graph, add operation type to each operation type graph, and add operation direction identifier to at least one directed line based on the editing operation detected by the data model generation interface, thereby obtaining the data model.
[0015] Optionally, the combined module includes: A code acquisition unit is used to acquire the template code; The code parsing unit is used to parse the template code and obtain multiple second code elements in the template code; The code replacement unit is used to replace the plurality of second code elements with the plurality of first code elements respectively to obtain the data processing code.
[0016] Optionally, the plurality of first code elements includes first data table code elements arranged in sequence and first association code elements arranged in sequence, and the code replacement unit is further configured to: According to the sorting of the code elements in the first data table, each of the second data table code elements arranged in order in the second code elements is replaced with the corresponding first data table code element; According to the sorting of the first association code elements, the second association code element in the second code element is replaced with the first association code element.
[0017] Optionally, the plurality of data tables includes at least one original data table and a target data table, the association being that the target data table is generated based on the at least one original data table, and the apparatus further includes: The instruction receiving module is used to receive the execution instructions for the data processing code; The code execution module is used to generate the target data table based on the multiple original data tables by running the data processing code.
[0018] Optionally, the conversion module includes: The graphics parsing unit is used to parse the plurality of graphics through a parser to obtain the plurality of first code elements.
[0019] Optionally, the device further includes: A storage module is used to store the plurality of first code elements in a database.
[0020] Optionally, the device further includes: A code element acquisition module is used to acquire the plurality of first code elements stored in the database; The code element drawing module is used to draw the plurality of first code elements using a drawer to obtain the data model corresponding to the plurality of first code elements.
[0021] On the other hand, a computer device is provided, the computer device including a processor and a memory, the memory storing at least one instruction, the at least one instruction being loaded and executed by the processor to perform the operations performed as described in the data model-based code generation method.
[0022] In another aspect, a computer-readable storage medium is provided, wherein at least one instruction is stored therein, the at least one instruction being loaded and executed by a processor to perform the operations performed as described in the data model-based code generation method.
[0023] The methods, apparatus, devices, and storage media provided in this application embodiment acquire a data model. The data model includes multiple graphs, which indicate descriptive information of multiple data tables and the relationships between them. This data model, comprising multiple graphs, is a visual data model; users can obtain descriptive information of the data tables and the relationships between them by viewing the connections between the graphs. By converting multiple graphs into corresponding first code elements, and combining these first code elements with template code, data processing code corresponding to the data model is generated. This achieves automatic code generation from the data model, eliminating the need for manual coding of the corresponding code, saving manpower and time, and improving code generation efficiency. Furthermore, the automatically generated data processing code corresponds to the data model, avoiding situations where the data processing code does not match the data model.
[0024] Furthermore, the parser can convert the data model into corresponding first code elements, and the renderer can convert the first code elements back into the corresponding data model. These first code elements are then used to generate the data processing code corresponding to the data model. Therefore, through the automatic conversion between the data model and the first code elements, there is no need for manual inspection and maintenance of the data model and its corresponding code, effectively protecting the consistency between the code and the data model.
[0025] Furthermore, the data model creation interface enables visualization of the model creation process, making data model creation simpler and more convenient. Attached Figure Description
[0026] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0027] Figure 1 This is a flowchart of a code generation method based on a data model provided in an embodiment of this application.
[0028] Figure 2 This is a schematic diagram of a data model provided in an embodiment of this application.
[0029] Figure 3 This is a schematic diagram illustrating the correspondence between data table information and graphics provided in an embodiment of this application.
[0030] Figure 4 This is a schematic diagram of another data model provided in an embodiment of this application.
[0031] Figure 5 This is a schematic diagram illustrating the creation of a data model according to an embodiment of this application.
[0032] Figure 6 This is a schematic diagram of another data model provided in an embodiment of this application.
[0033] Figure 7 This is a schematic diagram of another data model provided in an embodiment of this application.
[0034] Figure 8 This is a flowchart of obtaining code elements provided in an embodiment of this application.
[0035] Figure 9 This is another flowchart for obtaining code elements provided in the embodiments of this application.
[0036] Figure 10 This is a schematic diagram of the structure of a code generation device based on a data model provided in an embodiment of this application.
[0037] Figure 11 This is a schematic diagram of another data model-based code generation device provided in an embodiment of this application.
[0038] Figure 12 This is a schematic diagram of the structure of a terminal provided in an embodiment of this application.
[0039] Figure 13 This is a schematic diagram of the structure of a server provided in an embodiment of this application. Detailed Implementation
[0040] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the implementation methods of this application will be further described in detail below with reference to the accompanying drawings.
[0041] It is understood that the terms "first," "second," etc., used in this application may be used to describe various concepts herein, but unless otherwise stated, these concepts are not limited by these terms. These terms are only used to distinguish one concept from another. For example, without departing from the scope of this application, a first code element may be referred to as a second code element, and similarly, a second code element may be referred to as a first code element.
[0042] "At least one" refers to one or more. For example, at least one directed line can be any integer number of directed lines greater than or equal to one, such as one directed line, two directed lines, three directed lines, etc. "Multiple" refers to two or more. For example, multiple data table graphs can be any integer number of data table graphs greater than or equal to two, such as two data table graphs, three data table graphs, etc. "Each" refers to each of the at least one data table graphs. For example, each data table graph refers to each data table graph in the multiple data table graphs. If the multiple data table graphs consist of three data table graphs, then each data table graph refers to each of the three data table graphs.
[0043] Figure 1 This is a flowchart illustrating a code generation method based on a data model provided in an embodiment of this application. The execution subject of this embodiment is a computer device, which can be any terminal such as a mobile phone, desktop computer, or tablet computer, or it can be a server. This embodiment does not limit the type of computer device. See also... Figure 1 The method includes: 101. Obtain the data model.
[0044] A data model is an abstract description of data characteristics. The content described by a data model consists of three parts: data structure, data operations, and data constraints. It can describe the static characteristics, dynamic behavior, and constraints of data at an abstract level, providing a structured framework for data description and data operations in the database.
[0045] Data structures describe the static characteristics of data in a database, including data type, content, properties, and relationships between data. Data operations describe the set of allowed operations on data in the database, including operations and their rules. Data constraints describe the constraints, dependencies, and rules governing data changes to ensure data accuracy and validity.
[0046] Data models are categorized into three types based on hierarchy: conceptual data models, logical data models, and physical data models. A conceptual data model is a user-oriented model focused on the objective world, used to describe the conceptual structure of the world. A logical data model is a database management system-oriented model used for the implementation of the database management system; it is the data model supported by the database management system, such as network data models and hierarchical data models. A physical data model is a model oriented towards the physical representation of computer devices, describing the organization of data on the storage medium. The data model in this embodiment is a physical data model that enhances the description of relationships.
[0047] In this embodiment of the application, the data model includes multiple graphs, which indicate the descriptive information of multiple data tables and the relationships between the multiple data tables.
[0048] The data model is a visual data model, which can be a data model pre-stored by computer equipment, a data model obtained by converting code elements, or a data model drawn by the user through computer equipment. This application does not limit the scope of the data model.
[0049] These multiple graphics can be boxes, directed lines, rounded rectangles, circles, etc., and different types of graphics can indicate different types of information. For example, boxes indicate descriptive information of data tables, while directed lines and rounded rectangles indicate relationships between data tables.
[0050] The description information of a data table refers to its metadata, which may include the table's identifier, the names of the data in the table, the data types, and the constraints on the data. The relationships between data tables refer to the operational logic within the tables. These relationships may include join (horizontal union) and union (vertical union), where join creates a new data table by combining the identical parts of two data tables, and union merges two data tables to obtain a new data table. The metadata of a data table is shown in Table 1. Metadata includes the data's name, type, description, constraints, and other remarks. The data name can be the English name of the field, such as Device_SN (device number); the data type indicates the physical type of the data, and can be Bigint (a data type), String, etc. The data description refers to the information represented by the data, which can be a Chinese description, such as device number; the data constraints can be enumeration ranges, numerical ranges, regular expressions, etc., such as [az], [AZ], [0-9]; other remarks are descriptive information about the data for user viewing.
[0051] Table 1
[0052] In one possible implementation, the plurality of graphs includes a plurality of data table graphs and an association graph. The association graph is connected to the plurality of data table graphs. The association graph includes an operation type graph and a directed line. Each data table graph is connected to an operation type graph through a directed line. At least one directed line in the association graph carries an operation direction identifier.
[0053] Each data table graph indicates the description information of a single data table, each relationship graph indicates the relationship between multiple data table graphs, the operation type graph in the relationship graph indicates the operation type, and the directed line indicates the operation direction. Operation type refers to the type of logical operation performed between at least two data tables, and operation direction refers to the direction of the logical operation performed between at least two data tables.
[0054] A directed line can consist of line segments and arrows. Line segments represent the relationships between two data tables, and the arrows indicate the direction of operations on the data tables. Operation direction identifiers are used to indicate the direction of operations, such as indicating that the currently connected data table is the base table during the operation. These identifiers can be names, numbers, etc., representing the operation direction. Each data table graph is connected to an operation type graph by a directed line. When the starting point of a directed line connects to a data table graph and the ending point connects to an operation type graph, it indicates that the logical operation corresponding to that operation type graph is performed on the data table corresponding to that data table graph. When the starting point of a directed line connects to an operation type graph and the ending point connects to a data table graph, it indicates that the logical operation corresponding to that operation type graph is performed on one or more data tables, resulting in the data table corresponding to that data table graph.
[0055] Figure 2 This is a schematic diagram of a data model provided in an embodiment of this application. The data table is represented by a box, the operation type by a rounded rectangle, and directed lines are formed by line segments and arrows. Box 201 indicates the description information of data table 1 in database 1, box 202 indicates the description information of data table 2 in database 1, rounded rectangle 203 indicates the operation type as join (horizontal union), and box 204 indicates the description information of data table 3 in database 1. The directed line connecting box 201 and rounded rectangle 203 carries the operation direction identifier "left," indicating that when data table 1 and data table 2 are joined, the data table 1 corresponding to box 201 connected to the starting point of the directed line is the base table. That is, data table 1 and data table 2 are left-joined. A left-join means that a new data table is generated based on data table 1 and data table 2. This new data table contains all the data in data table 1 (the base table). If a certain data item in data table 2 has no matching data in data table 1, then that data item in the new data table will be null. See also... Figure 2 Based on the multiple graphs in the data model, the relationship between the data tables shown in the data model is as follows: Data table 1 and data table 2 are left joined to obtain data table 3.
[0056] In one possible implementation, the computer device creates multiple data table graphs, at least one operation type graph, and directed lines connecting any data table graph and any operation type graph based on a data model generation interface. Based on editing operations detected by the data model generation interface, the computer device adds descriptive information to each data table graph, adds operation types to each operation type graph, and adds operation direction identifiers to the at least one directed line, thus obtaining the data model.
[0057] The data model generation interface is used to generate data models, on which users can draw data models. Optionally, this data model generation interface can be an interface provided by a target application. The target application can be an application specifically for generating data models, or it can be an application for managing databases. This application embodiment does not limit the target application. For example, the data model generation interface can be the interface provided by a UML (Unified Modeling Language) modeling tool.
[0058] Users can generate multiple data table graphs, at least one operation type graph, and directed lines connecting any data table graph and any operation type graph based on the data model generation interface. When the computer device detects the user's drawing operation based on the data model generation interface, it creates the data table graph, operation type graph, and directed lines in the data model generation interface. Optionally, the data model generation interface includes a graph area and a drawing area. The graph area includes graphs such as data table graphs, operation type graphs, and directed lines. Users can drag graphs from the graph area to the drawing area. When the computer device detects this drag operation, it creates the data table graph, operation type graph, and directed lines in the drawing area.
[0059] After creating data table graphs, operation type graphs, and directed lines using the data model generation interface, users can perform editing operations within the interface. Based on the detected editing operations, the computer device adds descriptive information to each data table graph, adds operation types to each operation type graph, and adds operation direction identifiers to at least one directed line, thus obtaining the data model. Optionally, users can trigger operations on the graphs created by the data model generation interface, such as single-click, double-click, or long-press operations. When the computer device detects a trigger operation on a graph, it displays the corresponding edit box. Users can enter information corresponding to that graph in the edit box, such as entering the data table description in the edit box for the data table graph, the operation type in the edit box for the operation type graph, and the operation direction identifier in the edit box for the directed line. When the computer device receives the content entered in the edit box, it adds the corresponding information to the corresponding graph.
[0060] The process of creating a data model can be divided into the following three steps.
[0061] First, identify the focus of creating the data model. This includes determining the location of the data tables, identifying which data tables have relationships, defining the relationships between the data tables, and identifying the fields in the metadata of each data table.
[0062] Second, determine the visual elements of the design model. For example... Figure 3 As shown, data table location 301 is represented by the database name and table name, indicated by a visual box. Association method 302 generates a target data table based on multiple data tables, indicated by a visual arrow. Inter-table relationships 303 can be expressed using SQL (Structured Query Language), including join and union, indicated by a visual rounded rectangle. Table structure 304 represents the metadata of the data tables.
[0063] Third, create the model. For example... Figure 4 As shown, the location, association methods, and relationships between tables are all represented by visual graphics, forming a relationship diagram between the tables. Based on this diagram and the table metadata, a visual data model 401 can be obtained. Data model 401 represents: using table 1 in database 1 as the base table, performing a left join between table 1 and table 2 in database 1 yields the target data table.
[0064] Figure 5 This is a schematic diagram illustrating the creation of a data model according to an embodiment of this application. First, the location of the data tables, the relationships between the data tables, the relationships between the data tables, and the fields in the metadata of the data tables are determined. Then, the visualizations corresponding to the data table locations, inter-table relationships, and relationship methods, as well as the metadata describing the table structure, are determined. Based on the relationship diagram indicating the data table locations, inter-table relationships, and relationship methods, and the metadata, a visualized data model 501 can be obtained. This data model 501 is related to the above... Figure 4 The data model in 401 is similar.
[0065] Figure 6 This is a schematic diagram of a data model provided in an embodiment of this application, such as... Figure 6As shown, the boxes represent data table graphs, indicating the table type, name, location, remarks, and other descriptive information. Directed lines and rounded rectangles represent relational graphs; the directed lines indicate the direction of operations, and the rounded rectangles indicate the type of operations. Specifically, the facial recognition device information table 601 and 602 are vertically joined to obtain the IoT device information table 604. The facial recognition device heartbeat table 603 and the IoT device information table 604 are then fully horizontally joined. The result is then fully horizontally joined with the full device information table 608. Finally, the result is joined with the device and camera relationship table 605, the camera information table 606, and the device source table 607 to obtain the updated full device information table 608. A full horizontal join means returning all rows from both data tables to generate a new data table.
[0066] 102. Convert multiple graphics into corresponding first code elements to obtain multiple first code elements.
[0067] The data model includes multiple graphs that describe the data tables and the relationships between them. However, computer devices cannot directly process the data tables indicated by the data model. Therefore, it is necessary to convert the data model into corresponding code, and then process the data tables by running the code. The computer device first processes the multiple graphs in the data model, converting them into corresponding first code elements, resulting in multiple first code elements. These first code elements are elements within runnable code and possess structured information; that is, they can indicate the descriptions of the multiple data tables and the relationships between them. This achieves the conversion of multiple graphs into multiple first code elements while preserving the descriptions of the data tables and the relationships between them. Optionally, the first code element can be a JSON (JavaScript Object Notation, a lightweight data interchange format) code element, or it can be other types of code elements.
[0068] In one possible implementation, the multiple graphs include multiple data table graphs and relationship graphs, with the relationship graphs connected to the multiple data table graphs. Each data table graph indicates descriptive information of a data table, and the relationship graphs indicate the relationships between the multiple data table graphs.
[0069] The computer device then converts multiple data table graphics from multiple graphs into multiple first data table code elements, and converts the graphs showing relationships into first relationship code elements. These first data table code elements and first relationship code elements constitute a first code element. The first data table code element indicates the descriptive information of the data table, and the first relationship code element indicates the relationship between the data tables.
[0070] by Figure 7 Taking the data model in the example, Figure 7 The data model includes data table graph 701, data table graph 702, relationship graph 703, and data table graph 704. Multiple data table graphs and relationship graphs are transformed to obtain multiple first data table code elements and first relationship code elements, which are then further transformed.
[0071] The multiple first data table code elements are: ['Library1::Table1','Library1::Table2','Library1::Table3']; The first association code element is: ['library1::table1left joinlibrary1::table2'].
[0072] Optionally, see Figure 8 The process of obtaining the first data table code element and the first association code element includes the following steps: 801. Based on the sorting of multiple data table graphs, convert the multiple data table graphs into multiple first data table code elements arranged in sequence.
[0073] In a data model, multiple data table graphs are arranged sequentially. The computer device performs transformation processing on each of the graphs to obtain a first data table code element corresponding to each graph. Based on the order of the graphs, the computer device sorts these first data table code elements to obtain a sequence of first data table code elements. Alternatively, the computer device can perform transformation processing on each graph according to its order to obtain a sequence of first data table code elements.
[0074] Optionally, the multiple data table graphs include multiple original data table graphs and one target data table graph, with the relationship being that the target data table is generated from the multiple original data tables. Each original data table graph indicates the descriptive information of the original data table, and the target data table graph indicates the descriptive information of the target data table. The original data table graphs and the target data table graphs can be the same; for example, both the original data table graph and the target data table graph are rectangles. In this case, the original data table graphs and the target data table graphs are distinguished by their order. For example, in multiple data table graphs arranged in sequence, the last data table graph is the target data table graph, and the rest are original data table graphs. Alternatively, the original data table graphs and the target data table graphs can also be different; for example, the original data table graph is a rectangle, and the target data table graph is a circle. In this case, the original data table graphs and the target data table graphs can be distinguished by their graph type.
[0075] In cases where multiple data table diagrams include multiple original data table diagrams and one target data table diagram, converting multiple data table diagrams into multiple first data table code elements can include the following two methods.
[0076] The first method involves converting multiple original data table graphs into sequentially arranged original data table code elements based on their order, converting the target data table graph into target data table code elements, and then combining the sequentially arranged original data table code elements into a set of original data table code elements.
[0077] The original data table code element set contains only the original data table code elements and does not include the target data table code elements. The target data table code elements and the original data table code element set are independent of each other, which allows us to distinguish between the target data table code elements and the original data table code elements.
[0078] The second method is to convert the multiple original data table graphs into multiple original data table code elements arranged in order, convert the target data table graph into target data table code elements, arrange the target data table code elements after the multiple original data table code elements, and combine the multiple original data table code elements and the target data table code elements into a set of data table code elements.
[0079] The set of data table code elements includes multiple original data table code elements and target data table code elements arranged in order, with the target data table code elements following the original data table code elements. This allows us to distinguish between the target data table code elements and the original data table code elements. When it is necessary to obtain the target data table code element, the last data table code element obtained from the set of data table code elements is the target data table code element.
[0080] 802. Convert the association graph into the first association code element.
[0081] When a computer device obtains a data model, it converts the graph of relationships in the data model into a first relationship code element, wherein the first relationship code element indicates the relationships between data tables.
[0082] Optionally, the association graph includes an operation type graph and directed lines. The operation type graph indicates the operation type, and the directed lines indicate the operation direction. Each data table graph is connected to an operation type graph by a directed line, and at least one directed line in the association graph carries an operation direction identifier. The computer device then converts the operation type graphs connected by the directed lines carrying operation direction identifiers into operation type code elements, and combines the operation direction identifiers with the operation type code elements to obtain the first association code element.
[0083] The computer device acquires the operation direction identifier carried by the directed line, determines the operation type graphic connected to the directed line, converts the operation type graphic into an operation type code element, and combines the obtained operation direction identifier with the operation type code element to obtain the first association code element corresponding to the association relationship. For example, as follows... Figure 2 In the data model shown, one of the directed lines includes the operation direction identifier "left". The operation type graphic connected by the directed line indicates the operation type as join. Therefore, the first association code element corresponding to the association relationship graphic formed by the directed line and the operation type graphic is "left join".
[0084] In another possible implementation, the multiple graphs include multiple data table graphs and multiple relationship graphs. Each relationship graph is connected to multiple data table graphs. Each relationship graph includes an operation type graph and a directed line. The operation type graph indicates the operation type, and the directed line indicates the operation direction. Each data table graph is connected to an operation type graph via a directed line. At least one directed line in the relationship graph carries an operation direction identifier. The process of converting the multiple data table graphs into multiple first data table code elements and the process of converting the relationship graphs into first relationship code elements can be found in [reference needed]. Figure 9 This includes the following steps: 901. Based on the direction of operation indicated by the directed lines connecting multiple data table graphs, convert the multiple data table graphs into multiple first data table code elements arranged in sequence.
[0085] In the data model, multiple data table graphs are connected by directed lines. The computer device determines the data table graph connected to the starting point of the directed line, converts the data table graph into the corresponding first data table code element, and places the first data table code element first. The computer device then processes the next data table graph according to the operation direction indicated by the directed line to obtain the corresponding first data table code element, and places it after the first first data table code element. This process continues until the data table graph connected to the ending point of the directed line is processed, and the first data table code element corresponding to the data table graph connected to the ending point of the directed line is placed last. This results in multiple first data table code elements arranged in sequence. Alternatively, the computer device determines the data table graph connected to the endpoint of the directed line, converts the data table graph into the corresponding first data table code element, and places the first data table code element first. The computer device then performs the conversion process on the next data table graph in the opposite direction to the operation direction indicated by the directed line to obtain the corresponding first data table code element, and places it after the first first data table code element, and so on, until the data table graph connected to the starting point of the directed line is converted and the obtained first data table code element is placed last, thus obtaining multiple first data table code elements arranged in sequence.
[0086] 902. Based on the direction of operation indicated by the directed lines connecting multiple data table graphs, and the graphs of operation types connected by the directed lines, convert the multiple operation type graphs into multiple operation type code elements arranged in order. Based on the order of the multiple operation type code elements, combine each operation type code element with the operation direction identifier carried by the connected directed lines to obtain multiple first association code elements arranged in order.
[0087] Directed lines are connected to the data table graph and the operation type graph, respectively. Therefore, the computer device can convert multiple operation type graphs into multiple operation type code elements arranged in sequence according to the operation direction indicated by the directed lines. The process of converting multiple operation type graphs into multiple operation type code elements arranged in sequence is similar to the process of converting multiple data table graphs into multiple first data table code elements arranged in sequence in step 901 above, and will not be described again here.
[0088] In this context, at least one directed line in the association graph carries an operation direction identifier. The computer device determines the operation direction identifier carried by the directed line connecting the corresponding operation type graphs according to the order of the multiple operation type code elements, and combines the operation direction identifier with the corresponding operation type code element to obtain multiple first association code elements arranged in sequence.
[0089] Through steps 901-902 above, multiple first data table code elements and multiple first association code elements arranged in sequence can be obtained. Since the order of the multiple first data table code elements is determined by the direction of operation indicated by the directed lines connecting the multiple data table graphs, and the order of the multiple first association code elements is also determined by the direction of operation indicated by the directed lines connecting the multiple data table graphs, and each data table graph is connected to an operation type graph by a directed line, the multiple first data table code elements and the multiple first association code elements arranged in sequence correspond to each other. Each first association code element corresponds to two first data table code elements. By inserting the multiple first association code elements sequentially between every two first data table code elements, the resulting code element indicates the association relationship between the multiple data tables.
[0090] For example, multiple first data table code elements arranged in sequence are: [x, y, z, m, n], where code elements x, y, z, and m indicate original data table A, original data table B, original data table C, and original data table D, respectively, and code element n indicates target data table E. Multiple first join relationship code elements arranged in sequence are: [left join, right join, inner join]. Then the relationship between the original data table and the target data table is: x left join y right join z inner join m=n, meaning that the result of a left join between original data table A and original data table B is joined right with original data table C, and the result of the right join is joined inner with original data table D to obtain the target data table E.
[0091] In another possible implementation, a parser processes multiple graphics to obtain multiple first code elements. The computer device pre-stores a parser used to convert the data model into code elements. Therefore, by using the parser to process multiple graphics in the data model, the computer device can obtain multiple first code elements corresponding to those graphics.
[0092] It should be noted that the embodiments in this application only illustrate the process of converting a data model into multiple corresponding first code elements. In another embodiment, the computer device also stores a renderer, which is used to convert code elements into a data model. After obtaining the multiple first code elements corresponding to the data model, the computer device stores the multiple first code elements in a database. When it is necessary to generate a data model based on the code elements, the computer device obtains the multiple first code elements stored in the database, and uses the renderer to draw the multiple first code elements to obtain the data model corresponding to the multiple first code elements.
[0093] Optionally, after the computer device stores the multiple first code elements in the database, the user can also manually modify the code to meet the current business needs.
[0094] 103. Obtain the template code, parse the template code, and obtain multiple second code elements in the template code.
[0095] The template code is the code for processing data tables and can be used to generate data processing code corresponding to any data model. The template code includes multiple second code elements, which are the code elements to be replaced within the template code. It also includes fixed code elements. For example, the code elements representing instructions are fixed code elements, while the code elements representing descriptions of data tables or relationships between data tables are the code elements to be replaced, i.e., the second code elements. This template code can be in SQL language, which is a structured query language separated by keywords.
[0096] For example, the template code is: SELECT {query content} FROM {data source} WHERE {condition}. Here, the keywords SELECT, FROM, and WHERE are fixed code elements in the template. The content within the curly braces {} represents the code elements to be replaced. New code can be generated by replacing the code elements within the curly braces with code elements from the actual business logic.
[0097] The computer device acquires the template code, which can be code pre-stored in the computer device, code obtained by the computer device from other devices, or code uploaded to the computer device by researchers. The computer device parses the template code to obtain multiple second code elements within it.
[0098] 104. Replace multiple second code elements with multiple first code elements to obtain the data processing code.
[0099] When the computer device obtains multiple first code elements corresponding to the data model and multiple second code elements in the template code, it replaces the multiple second code elements with the multiple first code elements respectively to obtain the data processing code.
[0100] In one possible implementation, the multiple first code elements include sequentially arranged first data table code elements and sequentially arranged first association code elements. The computer device then replaces each sequentially arranged second data table code element in the second code elements with its corresponding first data table code element according to the order of the first data table code elements, and replaces the sequentially arranged second association code elements in the second code elements with their first association code elements according to the order of the first association code elements.
[0101] The second code element includes sequentially arranged second data table code elements and sequentially arranged second association code elements. The computer device, following the order of the first and second data table code elements, sequentially replaces each second data table code element with its corresponding first data table code element. Similarly, the computer device, following the order of the first and second association code elements, sequentially replaces each second association code element with its corresponding first association code element, thus obtaining the data processing code corresponding to the data model. Since each association corresponds to only two data tables, and the data processing code corresponds to multiple associations, this data processing code represents the associations between three or more data tables.
[0102] In another possible implementation, the multiple first code elements include two first data table code elements arranged in sequence and a first association code element. The computer device then, according to the order of the first data table code elements, replaces the two sequentially arranged second data table code elements in the second code elements with their corresponding first data table code elements, and replaces the second association code element in the second code elements with the first association code element.
[0103] The second code element includes two sequentially arranged second data table code elements and one second association code element. The computer device, following the order of the two first and two second data table code elements, replaces the two second data table code elements with their corresponding first data table code elements, and replaces the second association code element within the second code element with a first association code element, thus obtaining the data processing code corresponding to the data model. Since each association corresponds to only two data tables, and the data processing code corresponds to only one association, this data processing code represents the association between the two data tables.
[0104] For example, the template code is: SELECT FROM {left table} A {relationship} {right table} B ON A.{left table index}=B.{right table index}, where "left table", "right table", "left table index", and "right table index" are second data table code elements, and "left table" and "left table index" are description information of the same data table, "right table" and "right table index" are description information of another data table, and "relationship" is the second relationship code element.
[0105] The first code element includes: {left table} = library1::table1; {relationship} = left join; {Right table} = Library1::Table2; {left table index} = pk a; {Right table index} = pk b.
[0106] Among them, “database1::table1”, “database1::table2”, “pk a”, and “pk b” are the first data table code elements, and “leftjoin” is the first association code element.
[0107] Then, by replacing the second code element in the template code with the first code element, the data processing code becomes: SELECT FROM library1::table1 A LEFT JOIN library1::table2 B ON A.pk a = B.pk b.
[0108] Steps 103-104 above only describe the process of replacing multiple second code elements in the template code with multiple first code elements to obtain data processing code. In another embodiment, other methods can also be used to combine and process multiple first code elements and template code to generate data processing code corresponding to the data model.
[0109] 105. Receive the execution instructions for the data processing code, and generate the target data table based on multiple original data tables by running the data processing code.
[0110] The data model includes multiple data tables represented by various graphical indicators, including at least one original data table and one target data table. The relationships between the multiple graphical indicators in the data model are relationships that generate the target data table based on the at least one original data table. The data processing code corresponding to this data model is responsible for generating the target data table based on the at least one original data table. The original data table is a data table already stored in the database of the computer device, while the target data table is the data table to be generated and does not exist in the database.
[0111] Once the computer device receives the data processing code, it can generate the target data table based on multiple original data tables by running the code when it receives the instruction to run the code.
[0112] The method provided in this application provides a data model that includes multiple graphs indicating descriptive information of multiple data tables and the relationships between them. This data model, comprising multiple graphs, is a visual data model, allowing users to obtain descriptive information and relationships between data tables by viewing the connections between the graphs. By converting multiple graphs into corresponding first code elements, and combining these first code elements with template code, data processing code corresponding to the data model is generated. This achieves automatic code generation from the data model, eliminating the need for manual coding of the corresponding data model, saving manpower and time, and improving code generation efficiency. Furthermore, the automatically generated data processing code corresponds to the data model, avoiding situations where the data processing code does not match the data model.
[0113] Furthermore, the parser can convert the data model into corresponding first code elements, and the renderer can convert the first code elements back into the corresponding data model. These first code elements are then used to generate the data processing code corresponding to the data model. Therefore, through the automatic conversion between the data model and the first code elements, there is no need for manual inspection and maintenance of the data model and its corresponding code, effectively protecting the consistency between the code and the data model.
[0114] Furthermore, the data model creation interface enables visualization of the model creation process, making data model creation simpler and more convenient.
[0115] Figure 10 This is a schematic diagram of the structure of a code generation device based on a data model provided in an embodiment of this application. See also... Figure 10 The device includes: The model acquisition module 1001 is used to acquire the data model, which includes multiple graphs that indicate the descriptive information of multiple data tables and the relationships between the multiple data tables. The conversion module 1002 is used to convert multiple graphics into corresponding first code elements to obtain multiple first code elements; The combination module 1003 is used to combine multiple first code elements and template code to generate data processing code corresponding to the data model.
[0116] The apparatus provided in this application acquires a data model, which includes multiple graphs indicating descriptive information of multiple data tables and the relationships between them. This data model, comprising multiple graphs, is a visual data model; users can obtain the descriptive information of the data tables and the relationships between them by viewing the connections between the graphs. By converting the multiple graphs into corresponding first code elements, and combining these first code elements with template code, data processing code corresponding to the data model is generated. This achieves automatic code generation from the data model, eliminating the need for manual coding of the corresponding code, saving manpower and time, and improving code generation efficiency. Furthermore, the automatically generated data processing code corresponds to the data model, avoiding situations where the data processing code does not match the data model.
[0117] Optionally, see Figure 11 Multiple graphs include multiple data table graphs and relationship graphs. The relationship graphs are connected to the multiple data table graphs. Each data table graph indicates the descriptive information of a data table, and the relationship graphs indicate the relationships between the multiple data table graphs. Conversion module 1002 includes: The conversion unit 1012 is used to convert multiple data table graphs into multiple first data table code elements and to convert association graphs into first association code elements.
[0118] Optionally, see Figure 11 The relationship graph includes operation type graphs and directed lines. The operation type graphs indicate the operation type, and the directed lines indicate the operation direction. Each data table graph is connected to an operation type graph by a directed line, and at least one directed line in the relationship graph carries an operation direction identifier. The conversion unit 1012 is also used for: Convert the directed lines carrying operation direction identifiers into operation type code elements; The operation direction identifier is combined with the operation type code element to obtain the first association code element.
[0119] Optionally, see Figure 11 The conversion unit 1012 is also used for: Based on the sorting of multiple data table graphs, the multiple data table graphs are converted into multiple first data table code elements arranged in sequence; Convert the relationship graph into the first relationship code element.
[0120] Optionally, see Figure 11The multiple data table graphs include multiple original data table graphs and one target data table graph. The relationship is that the target data table is generated based on multiple original data tables. The conversion unit 1012 is also used for: Based on the sorting of multiple original data table graphs, the multiple original data table graphs are converted into multiple original data table code elements arranged in sequence, and the target data table graph is converted into target data table code elements. Multiple original data table code elements arranged in sequence are combined into a set of original data table code elements; or, the target data table code elements are arranged after multiple original data table code elements, and the multiple original data table code elements and the target data table code elements are combined into a set of data table code elements.
[0121] Optionally, see Figure 11 The relationship graph includes operation type graphs and directed lines. The operation type graph indicates the operation type, and the directed lines indicate the operation direction. Each data table graph is connected to an operation type graph by a directed line. The conversion unit 1012 is also used for: Based on the direction of operation indicated by the directed lines connecting multiple data table graphs, the multiple data table graphs are converted into multiple first data table code elements arranged in sequence.
[0122] Optionally, see Figure 11 The multiple graphs include multiple data table graphs and multiple relationship graphs. Each relationship graph is connected to multiple data table graphs, and at least one directed line in each relationship graph carries an operation direction identifier. The conversion unit 1012 is also used for: Based on the direction of operation indicated by the directed lines connecting multiple data table graphs, and the operation type graphs connected by the directed lines, the multiple operation type graphs are converted into multiple operation type code elements arranged in sequence. Based on the sorting of multiple operation type code elements, each operation type code element is combined with the operation direction identifier carried by the connected directed line to obtain multiple first association code elements arranged in sequence.
[0123] Optionally, see Figure 11 The model acquisition module 1001 includes: The graphics creation unit 1011 is used to create multiple data table graphics, at least one operation type graphics, and directed lines connecting any data table graphics and any operation type graphics based on the data model generation interface. The information adding unit 1021 is used to add descriptive information to each data table graph based on the editing operations detected by the data model generation interface, add operation type to each operation type graph, and add operation direction identifier to at least one directed line to obtain the data model.
[0124] Optionally, see Figure 11 The combined module 1003 includes: Code acquisition unit 1013 is used to acquire template code; Code parsing unit 1023 is used to parse the template code and obtain multiple second code elements in the template code; The code replacement unit 1033 is used to replace multiple second code elements with multiple first code elements respectively to obtain data processing code.
[0125] Optionally, see Figure 11 The multiple first code elements include sequentially arranged first data table code elements and sequentially arranged first association code elements. The code replacement unit 1033 is also used for: According to the sorting of the code elements in the first data table, replace each of the second data table code elements arranged in order in the second code elements with the corresponding first data table code element; According to the order of the first association code elements, replace the second association code elements in the second code elements with the first association code elements.
[0126] Optionally, see Figure 11 The apparatus includes multiple data tables, including at least one original data table and one target data table, with the relationship being that the target data table is generated based on at least one original data table. The apparatus also includes: The instruction receiving module 1004 is used to receive execution instructions for data processing code; Code execution module 1005 is used to generate a target data table from multiple raw data tables by running data processing code.
[0127] Optionally, see Figure 11 The conversion module 1002 includes: The graphics parsing unit 1022 is used to parse and process multiple graphics to obtain multiple first code elements.
[0128] Optionally, see Figure 11 The device also includes: Storage module 1006 is used to store multiple first code elements in a database.
[0129] Optionally, see Figure 11 The device also includes: The code element acquisition module 1007 is used to acquire multiple first code elements stored in the database; The code element drawing module 1008 is used to draw multiple first code elements through a drawer to obtain the data model corresponding to the multiple first code elements.
[0130] It should be noted that the code generation device based on the data model provided in the above embodiments is only illustrated by the division of the above functional modules when generating code based on the data model. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the computer device can be divided into different functional modules to complete all or part of the functions described above. In addition, the code generation device based on the data model provided in the above embodiments and the code generation method embodiments based on the data model belong to the same concept, and the specific implementation process can be found in the method embodiments, which will not be repeated here.
[0131] Figure 12 A schematic diagram of the structure of a terminal 1200 provided in an exemplary embodiment of this application is shown. The terminal 1200 can execute the steps performed by the computer device in the above-described method embodiment for code generation based on a data model.
[0132] Typically, terminal 1200 includes a processor 1201 and a memory 1202.
[0133] Processor 1201 may include one or more processing cores, such as a quad-core processor, an octa-core processor, etc. Processor 1201 may be implemented using at least one hardware form selected from DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). Processor 1201 may also include a main processor and a coprocessor. The main processor, also known as a CPU (Central Processing Unit), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, processor 1201 may integrate a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the screen. In some embodiments, processor 1201 may also include an AI (Artificial Intelligence) processor, which is used to handle computational operations related to machine learning.
[0134] The memory 1202 may include one or more computer-readable storage media, which may be non-transitory. The memory 1202 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash memory devices. In some embodiments, the non-transitory computer-readable storage media in the memory 1202 are used to store at least one instruction, which is used by the processor 1201 to implement the data model-based code generation method provided in the method embodiments of this application.
[0135] In some embodiments, device 1200 may also optionally include: a peripheral device interface 1203 and at least one peripheral device. The processor 1201, memory 1202, and peripheral device interface 1203 can be connected via a bus or signal line. Each peripheral device can be connected to peripheral device interface 1203 via a bus, signal line, or circuit board. Specifically, the peripheral device includes at least one of: radio frequency circuitry 1204, touch display screen 1205, camera 1206, audio circuitry 1207, positioning component 1208, and power supply 1209.
[0136] Peripheral device interface 1203 can be used to connect at least one I / O (Input / Output) related peripheral device to processor 1201 and memory 1202. In some embodiments, processor 1201, memory 1202 and peripheral device interface 1203 are integrated on the same chip or circuit board; in some other embodiments, any one or two of processor 1201, memory 1202 and peripheral device interface 1203 can be implemented on separate chips or circuit boards, which is not limited in this embodiment.
[0137] The radio frequency (RF) circuit 1204 is used to receive and transmit RF (Radio Frequency) signals, also known as electromagnetic signals. The RF circuit 1204 communicates with communication networks and other communication devices via electromagnetic signals. The RF circuit 1204 converts electrical signals into electromagnetic signals for transmission, or converts received electromagnetic signals into electrical signals. Optionally, the RF circuit 1204 includes: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a user identity module card, etc. The RF circuit 1204 can communicate with other devices through at least one wireless communication protocol. This wireless communication protocol includes, but is not limited to: metropolitan area networks (MANs), various generations of mobile communication networks (2G, 3G, 4G, and 5G), wireless local area networks (WLANs), and / or WiFi (Wireless Fidelity) networks. In some embodiments, the RF circuit 1204 may also include circuitry related to NFC (Near Field Communication), which is not limited in this application.
[0138] Display screen 1205 is used to display a UI (User Interface). This UI may include graphics, text, icons, videos, and any combination thereof. When display screen 1205 is a touch display screen, it also has the ability to collect touch signals on or above its surface. These touch signals can be input as control signals to processor 1201 for processing. In this case, display screen 1205 can also be used to provide virtual buttons and / or a virtual keyboard, also known as soft buttons and / or a soft keyboard. In some embodiments, there may be one display screen 1205, which serves as the front panel of terminal 1200; in other embodiments, there may be at least two display screens, respectively disposed on different surfaces of terminal 1200 or in a folded design; in some embodiments, display screen 1205 may be a flexible display screen, disposed on a curved or folded surface of terminal 1200. Furthermore, display screen 1205 may be configured as a non-rectangular irregular shape, i.e., a non-rectangular screen. Display screen 1205 may be made of materials such as LCD (Liquid Crystal Display) or OLED (Organic Light-Emitting Diode).
[0139] The camera assembly 1206 is used to acquire images or videos. Optionally, the camera assembly 1206 includes a front-facing camera and a rear-facing camera. Typically, the front-facing camera is located on the front panel of the terminal 1200, and the rear-facing camera is located on the back of the terminal 1200. In some embodiments, there are at least two rear-facing cameras, which are any one of a main camera, a depth-sensing camera, a wide-angle camera, and a telephoto camera, to achieve background blurring by fusion of the main camera and the depth-sensing camera, panoramic shooting by fusion of the main camera and the wide-angle camera, VR (Virtual Reality) shooting, or other fusion shooting functions. In some embodiments, the camera assembly 1206 may also include a flash. The flash can be a single-color temperature flash or a dual-color temperature flash. A dual-color temperature flash refers to a combination of a warm light flash and a cool light flash, which can be used for light compensation at different color temperatures.
[0140] The positioning component 1208 is used to locate the current geographical location of the terminal 1200 in order to enable navigation or LBS (Location Based Service).
[0141] The audio circuit 1207 may include a microphone and a speaker. The microphone is used to collect sound waves from the user and the environment, converting the sound waves into electrical signals that are input to the processor 1201 for processing, or input to the radio frequency circuit 1204 for voice communication. For stereo sound acquisition or noise reduction purposes, multiple microphones may be used, each positioned at a different location on the terminal 1200. The microphone may also be an array microphone or an omnidirectional microphone. The speaker is used to convert electrical signals from the processor 1201 or the radio frequency circuit 1204 into sound waves. The speaker may be a conventional diaphragm speaker or a piezoelectric ceramic speaker. When the speaker is a piezoelectric ceramic speaker, it can convert electrical signals not only into audible sound waves but also into inaudible sound waves for purposes such as distance measurement. In some embodiments, the audio circuit 1207 may also include a headphone jack.
[0142] Power supply 1209 is used to power the various components in terminal 1200. Power supply 1209 can be AC power, DC power, a disposable battery, or a rechargeable battery. When power supply 1209 includes a rechargeable battery, the rechargeable battery can support wired charging or wireless charging. The rechargeable battery can also be used to support fast charging technology.
[0143] In some embodiments, the terminal 1200 further includes one or more sensors 1210. The one or more sensors 1210 include, but are not limited to: an accelerometer 1211, a gyroscope 1212, a pressure sensor 1213, a fingerprint sensor 1214, an optical sensor 1215, and a proximity sensor 1216.
[0144] Accelerometer 1211 can detect the magnitude of acceleration along the three coordinate axes of a coordinate system established with terminal 1200. For example, accelerometer 1211 can be used to detect the components of gravitational acceleration along the three coordinate axes. Processor 1201 can control touchscreen 1205 to display the user interface in landscape or portrait view based on the gravitational acceleration signal acquired by accelerometer 1211. Accelerometer 1211 can also be used for games or for acquiring user motion data.
[0145] The gyroscope sensor 1212 can detect the orientation and rotation angle of the terminal 1200. The gyroscope sensor 1212 can work in conjunction with the accelerometer sensor 1211 to collect the user's 3D movements on the terminal 1200. Based on the data collected by the gyroscope sensor 1212, the processor 1201 can perform the following functions: motion sensing (e.g., changing the UI based on the user's tilt), image stabilization during shooting, game control, and inertial navigation.
[0146] The pressure sensor 1213 can be disposed on the side bezel of the terminal 1200 and / or on the lower layer of the touch display screen 1205. When the pressure sensor 1213 is disposed on the side bezel of the terminal 1200, it can detect the user's grip signal on the terminal 1200, and the processor 1201 can perform left / right hand recognition or quick operation based on the grip signal collected by the pressure sensor 1213. When the pressure sensor 1213 is disposed on the lower layer of the touch display screen 1205, the processor 1201 can control the operable controls on the UI interface based on the user's pressure operation on the touch display screen 1205. The operable controls include at least one of button controls, scroll bar controls, icon controls, and menu controls.
[0147] The fingerprint sensor 1214 is used to collect the user's fingerprint. The processor 1201 identifies the user's identity based on the fingerprint collected by the fingerprint sensor 1214, or the fingerprint sensor 1214 identifies the user's identity based on the collected fingerprint. When the user's identity is identified as trusted, the processor 1201 authorizes the user to perform relevant sensitive operations, including unlocking the screen, viewing encrypted information, downloading software, making payments, and changing settings. The fingerprint sensor 1214 can be located on the front, back, or side of the terminal 1200. When the terminal 1200 has physical buttons or a manufacturer's logo, the fingerprint sensor 1214 can be integrated with the physical buttons or manufacturer's logo.
[0148] The optical sensor 1215 is used to collect ambient light intensity. In one embodiment, the processor 1201 can control the display brightness of the touch screen 1205 based on the ambient light intensity collected by the optical sensor 1215. Specifically, when the ambient light intensity is high, the display brightness of the touch screen 1205 is increased; when the ambient light intensity is low, the display brightness of the touch screen 1205 is decreased. In another embodiment, the processor 1201 can also dynamically adjust the shooting parameters of the camera assembly 1206 based on the ambient light intensity collected by the optical sensor 1215.
[0149] The proximity sensor 1216, also known as a distance sensor, is typically located on the front panel of the terminal 1200. The proximity sensor 1216 is used to detect the distance between the user and the front of the terminal 1200. In one embodiment, when the proximity sensor 1216 detects that the distance between the user and the front of the terminal 1200 is gradually decreasing, the processor 1201 controls the touchscreen display 1205 to switch from a screen-on state to a screen-off state; when the proximity sensor 1216 detects that the distance between the user and the front of the terminal 1200 is gradually increasing, the processor 1201 controls the touchscreen display 1205 to switch from a screen-off state to a screen-on state.
[0150] Those skilled in the art will understand that Figure 12 The structure shown does not constitute a limitation on terminal 1200 and may include more or fewer components than shown, or combine certain components, or use different component arrangements.
[0151] Figure 13 This is a schematic diagram of a server structure provided in an embodiment of this application. The server 1300 can vary significantly due to different configurations or performance. It may include one or more Central Processing Units (CPUs) 1301 and one or more memories 1302. The memories 1302 store at least one instruction, which is loaded and executed by the processor 1301 to implement the methods provided in the various method embodiments described above. Of course, the server may also have wired or wireless network interfaces, a keyboard, and input / output interfaces for input and output. The server may also include other components for implementing device functions, which will not be elaborated upon here.
[0152] Server 1300 can be used to execute the steps performed by the computer device in the above-described data model-based code generation method.
[0153] This application also provides a computer device for generating code based on a data model. The computer device includes a processor and a memory. The memory stores at least one instruction, which is loaded and executed by the processor to implement the operations in the data model-based code generation method of the above embodiments.
[0154] This application also provides a computer-readable storage medium storing at least one instruction, which is loaded and executed by a processor to implement the operations in the data model-based code generation method of the above embodiments.
[0155] This application also provides a computer program that includes at least one instruction, which is loaded and executed by a processor to implement the operations in the data model-based code generation method described above.
[0156] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.
[0157] The above description is only an optional embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present application should be included within the protection scope of the present application.
Claims
1. A code generation method based on a data model, characterized in that, The method includes: A data model is obtained, comprising multiple data table graphs and multiple relationship graphs. The relationship graphs are connected to the multiple data table graphs. Each data table graph indicates the descriptive information of a data table. The multiple data table graphs include multiple original data table graphs and a target data table graph. The relationship graphs indicate the relationships between the multiple original data tables to generate the target data table. The relationship graphs include operation type graphs and directed lines carrying operation direction identifiers. The operation type graphs indicate the operation type, and the directed lines indicate the operation direction. Based on the direction of operation indicated by the directed lines connecting the multiple data table graphs, the multiple data table graphs are converted into multiple first data table code elements arranged in sequence; Based on the operation direction indicated by the directed lines connecting the multiple data table graphs, and the operation type graphs connected by the directed lines, the multiple operation type graphs are converted into multiple operation type code elements arranged in order. Based on the order of the multiple operation type code elements, each operation type code element is combined with the operation direction identifier carried by the connected directed lines to obtain multiple first association code elements arranged in order. Obtain template code; parse the template code to obtain multiple second code elements; according to the sorting of the first data table code elements, replace each sequentially arranged second data table code element with its corresponding first data table code element; according to the sorting of the first association code elements, replace the second association code elements with the first association code elements to obtain the data processing code corresponding to the data model. The multiple first code elements include sequentially arranged multiple first data table code elements and sequentially arranged multiple first association code elements. The data processing code is used to generate the target data table based on the multiple original data tables.
2. The method according to claim 1, characterized in that, The step of converting the multiple data table graphs into multiple sequentially arranged first data table code elements according to their sorting includes: Based on the sorting of the multiple original data table graphics, the multiple original data table graphics are converted into multiple original data table code elements arranged in order, and the target data table graphics are converted into target data table code elements. The ordered original data table code elements are arranged to form an original data table code element set; or, the target data table code element is arranged after the original data table code elements, and the original data table code elements and the target data table code element are combined to form a data table code element set.
3. The method according to claim 1, characterized in that, The data acquisition model includes: Based on the data model generation interface, create multiple data table graphs, at least one operation type graph, and a directed line connecting any data table graph and any operation type graph; Based on the editing operations detected by the data model generation interface, descriptive information is added to each data table graph, operation type is added to each operation type graph, and operation direction identifier is added to at least one directed line to obtain the data model.
4. The method according to claim 1, characterized in that, The method further includes: Receive the execution instruction for the data processing code; The target data table is generated by running the data processing code based on the multiple original data tables.
5. The method according to claim 1, characterized in that, The method further includes: The parser processes the multiple data table graphs and the relationship graphs to obtain the multiple first code elements.
6. A code generation device based on a data model, characterized in that, The device includes: The model acquisition module is used to acquire a data model, which includes multiple data table graphs and relationship graphs. The relationship graphs are connected to the multiple data table graphs. Each data table graph indicates the description information of a data table. The multiple data table graphs include multiple original data table graphs and a target data table graph. The relationship graphs indicate the relationships between the multiple original data tables to generate the target data table. The relationship graphs include operation type graphs and directed lines carrying operation direction identifiers. The operation type graphs indicate the operation type, and the directed lines indicate the operation direction. The conversion module is used to convert the multiple data table graphics into multiple first data table code elements arranged in sequence, according to the operation direction indicated by the directed lines connecting the multiple data table graphics. The conversion module is further configured to convert multiple operation type graphics into multiple operation type code elements arranged in order, based on the operation direction indicated by the directed lines connecting the multiple data table graphics and the operation type graphics connected by the directed lines; and to combine each operation type code element with the operation direction identifier carried by the connected directed lines according to the order of the multiple operation type code elements to obtain multiple first association code elements arranged in order. A combination module is used to obtain template code; parse the template code to obtain multiple second code elements in the template code; replace each second data table code element in the second code elements with the corresponding first data table code element according to the sorting of the first data table code elements; replace the second association code elements in the second code elements with the first association code elements according to the sorting of the first association code elements, thereby obtaining the data processing code corresponding to the data model. The multiple first code elements include the multiple first data table code elements and the multiple first association code elements arranged in order. The data processing code is used to generate the target data table based on the multiple original data tables.
7. The apparatus according to claim 6, characterized in that, The conversion module includes a conversion unit for: Based on the sorting of the multiple original data table graphics, the multiple original data table graphics are converted into multiple original data table code elements arranged in order, and the target data table graphics are converted into target data table code elements. The ordered original data table code elements are combined into a set of original data table code elements; Alternatively, the target data table code element can be arranged after the plurality of original data table code elements, and the plurality of original data table code elements and the target data table code element can be combined to form a data table code element set.
8. The apparatus according to claim 6, characterized in that, The model acquisition module includes: The graphics creation unit is used to create multiple data table graphics, at least one operation type graphics, and directed lines connecting any data table graphics and any operation type graphics based on the data model generation interface. The information adding unit is used to add descriptive information to each data table graph, add operation type to each operation type graph, and add operation direction identifier to at least one directed line according to the editing operation detected by the data model generation interface, so as to obtain the data model.
9. The apparatus according to claim 6, characterized in that, The device further includes: The instruction receiving module is used to receive the execution instructions for the data processing code; The code execution module is used to generate the target data table based on the multiple original data tables by running the data processing code.
10. The apparatus according to claim 6, characterized in that, The conversion module includes: The graph parsing unit is used to parse and process the multiple data table graphs and the relationship graphs through a parser to obtain the multiple first code elements.
11. A computer device, characterized in that, The computer device includes a processor and a memory, the memory storing at least one instruction, which is loaded and executed by the processor to implement the data model-based code generation method as described in any one of claims 1 to 5.
12. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores at least one instruction, which is loaded and executed by a processor to implement the data model-based code generation method as described in any one of claims 1 to 5.
13. A computer program product, characterized in that, The computer program product includes at least one instruction, which is loaded and executed by a processor to implement the data model-based code generation method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Imaging analysis system and imaging analysis method of data model
CN103106188A
Automatic data model generating system and automatic data model generating method
CN103885754A