Model conversion method and device, electronic equipment, storage medium and program product
By converting entities and relationships in the entity relationship model into nodes and edges in the attribute graph model, the transformation problem between the entity relationship model to the attribute graph model is solved, and automated transformation is achieved, improving efficiency and accuracy.
Patent Information
- Application Number
- CN202510192005.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-20
- Publication Date
- 2025-06-10
AI Technical Summary
In the context of the rise of graph data models, how to effectively convert entity relationship models into attribute graph models has become a technical problem that needs to be solved urgently.
A model conversion method is proposed. In the entity relationship model, an entity with a connection relationship is converted into nodes and edges in the attribute graph model, and the source nodes of nodes and edges are determined to realize the automated transformation of the entity relationship model to the attribute graph model.
It realizes the automated transformation from entity relationship model to attribute graph model, improves the efficiency and accuracy of model transformation, reduces the need for manual intervention, and is suitable for ordinary users.
Smart Images

Figure CN120124719A_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of this specification relate to the field of graph technology, and in particular, to a model conversion method, apparatus, electronic device, storage medium, and program product. Background Art
[0002] In the traditional relational data field, the entity-relationship model (ER model) is a classic data modeling method that represents data and its interrelationships in a graphical way, facilitating designers to understand business requirements and is still widely used at present. However, with the rise of the graph data model, a large amount of relational data needs to be converted into the graph data model for better graph analysis and calculation. In this transformation process, how to effectively convert the entity-relationship model into an attribute graph model has become an urgent technical problem to be solved. Summary of the Invention
[0003] In view of this, one or more embodiments of this specification provide the following technical solutions:
[0004] According to the first aspect of one or more embodiments of this specification, a model conversion method is proposed, including:
[0005] When the entity-relationship model includes a first entity and a second entity with a connection relationship, converting the first entity into a first node in the attribute graph model;
[0006] Converting the second entity into a first edge of the first node, and determining the source node of the first edge as the first node.
[0007] According to the second aspect of one or more embodiments of this specification, a model conversion method is proposed, including:
[0008] When the entity-relationship model includes a fifth entity and a sixth entity with a connection relationship, converting the fifth entity into a third edge in the attribute graph model, and converting the sixth entity into a fourth edge in the attribute graph model;
[0009] Determining the source nodes of the third edge and the fourth edge as the foreign keys where the fifth entity and the sixth entity are connected.
[0010] According to the third aspect of one or more embodiments of this specification, a model conversion apparatus is proposed, including:
[0011] The first conversion unit, when the entity relationship model includes a first entity and a second entity with a connection relationship, converts the first entity into a first node in the property graph model; converts the second entity into a first edge of the first node, and determines the source node of the first edge as the first node.
[0012] According to a fourth aspect of one or more embodiments of the present specification, a model conversion device is provided, including:
[0013] The second conversion unit, when the entity relationship model includes a fifth entity and a sixth entity with a connection relationship, converts the fifth entity into a third edge in the property graph model, and converts the sixth entity into a fourth edge in the property graph model; determines the source nodes of the third edge and the fourth edge as the foreign key for the connection between the fifth entity and the sixth entity.
[0014] According to a fifth aspect of one or more embodiments of the present specification, an electronic device is provided, including: a processor; a memory for storing processor-executable instructions; wherein, the processor runs the executable instructions to implement the steps of the foregoing method.
[0015] According to a sixth aspect of one or more embodiments of the present specification, a computer-readable storage medium is provided, on which computer instructions are stored, and when the instructions are executed by a processor, the steps of the foregoing method are implemented.
[0016] According to a seventh aspect of one or more embodiments of the present specification, a computer program product is provided, including a computer program / instructions, and when the computer program / instructions are executed by a processor, the steps of the foregoing method are implemented.
[0017] As can be seen from the above embodiments, the model conversion solution provided in the present specification for converting an entity relationship model into a property graph model, when the entity relationship model includes a first entity and a second entity with a connection relationship, converts the first entity into a first node in the property graph model, converts the second entity into a first edge of the first node, and determines the source node of the first edge as the first node. Thus, the automated conversion from the entity relationship model to the property graph model is realized. The whole process does not require manual intervention, which is highly user-friendly for ordinary users. At the same time, compared with the manual conversion method, the model conversion efficiency can be greatly improved, and the accuracy is relatively high. Brief Description of the Drawings
[0018] Figure 1 is a schematic diagram of the architecture of a model conversion service system provided by an exemplary embodiment.
[0019] Figure 2 is a flowchart of a model conversion method provided by an exemplary embodiment.
[0020] Figure 3 It is a schematic diagram of model conversion provided by an exemplary embodiment.
[0021] Figure 4 It is another schematic diagram of model conversion provided by an exemplary embodiment.
[0022] Figure 5 It is a schematic diagram of splitting an entity relationship model provided by an exemplary embodiment.
[0023] Figure 6 It is a flowchart of another model conversion method provided by an exemplary embodiment.
[0024] Figure 7 It is a flowchart of another model conversion method provided by an exemplary embodiment.
[0025] Figure 8 It is another schematic diagram of model conversion provided by an exemplary embodiment.
[0026] Figure 9 It is another schematic diagram of model conversion provided by an exemplary embodiment.
[0027] Figure 10 It is a flowchart of another model conversion method provided by an exemplary embodiment.
[0028] Figure 11 It is a flowchart of another model conversion method provided by an exemplary embodiment.
[0029] Figure 12 It is a schematic diagram of the structure of a device provided by an exemplary embodiment.
[0030] Figure 13 It is a block diagram of a model conversion device provided by an exemplary embodiment.
[0031] Figure 14 It is a block diagram of another model conversion device provided by an exemplary embodiment. Specific embodiments
[0032] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in this specification are all information and data that have been authorized by the user or fully authorized by all parties. And the collection, use, and processing of relevant data need to comply with the relevant laws, regulations, and standards of relevant countries and regions, and corresponding operation entrances are provided for users to choose to authorize or refuse.
[0033] In the traditional relational data field, the entity-relationship model is a classic data modeling method, which represents data and its interrelationships in a graphical way, facilitating designers to understand business requirements and is still widely used at present. However, with the rise of the graph data model, a large amount of relational data needs to be converted into the graph data model for better graph analysis and calculation. In this transformation process, how to effectively convert the entity-relationship model into the property graph model has become a technical problem to be solved urgently.
[0034] In related technologies, the entity-relationship model is usually converted into the property graph model by manual operation. However, the process of converting the entity-relationship model into the property graph model highly depends on expert experience, which is difficult for ordinary users and the operation is difficult. At the same time, the manual conversion method takes a long time, has low efficiency and is prone to errors.
[0035] Figure 1 It is a schematic diagram of the architecture of a model conversion service system provided by an exemplary embodiment. As Figure 1 shown, the system may include a server 11, a network 12, and several electronic devices, such as a PC (Personal Computer) 13, a mobile phone 14, etc.
[0036] The server 11 may be a physical server including an independent host, or the server 11 may be a virtual server hosted by a host cluster. During operation, the server 11 may run the server-side program of an application to implement the related functions of the application. For example, when the server 11 runs the program of the model conversion service, it may be implemented as a corresponding model conversion service platform.
[0037] PC 13 and mobile phone 14 are only some types of electronic devices that users can use. In fact, users can obviously also use electronic devices of the following types: tablet devices, laptops, personal digital assistants (PDAs), wearable devices (such as smart glasses, smart watches, etc.). One or more embodiments of this specification do not limit this. During operation, the electronic device can run a program on the client side of a certain application to implement the related functions of the application. For example, when the electronic device runs a program of the model conversion service, it can be implemented as a client of the model conversion service. Among them, the application program of the client side of the above model conversion service can be started and run on the electronic device. The program on the client side can be a native application installed on the electronic device, or the program on the client side can be a mini program, a fast application or other similar forms. Of course, when using web technologies such as HTML5 or similar, the related functions can be implemented through the page displayed by the browser. Here, the browser can be an independent browser application or a browser module embedded in some applications.
[0038] For the network 12 for the interaction between electronic devices such as PC 13 and mobile phone 14 and the server 11, it can be specifically selected to use a wired or wireless network to implement communication based on the communication methods supported by the corresponding electronic devices. This specification does not limit this. For example, PC 13 can support both wired and wireless communication, so wired or wireless network can be used to implement communication according to needs, while mobile phone 14 usually only supports wireless communication, so wireless network can be used to implement communication.
[0039] The model conversion solution provided in this specification can be applied to the server shown above Figure 1 and can also be applied to the electronic device shown above Figure 1 This specification does not make special restrictions on this.
[0040] The model conversion solution provided in this specification can be used to convert a given entity relationship model into an attribute graph model. Before introducing the specific implementation method of model conversion, some concepts involved in this specification are explained first.
[0041] The entity-relationship model can be used to represent data and its relationships, mainly including entities, attributes, and relationships. Among them, an entity is an object that can be distinguished in the real world, which can be a person, a place, an item, or a concept, and usually corresponds to a table in a database. Each entity has a unique identifier, called the primary key, which is used to uniquely identify the entity; an attribute is a property or characteristic that an entity has and can be used to describe the entity; a relationship is a logical connection between entities and can be used to represent the connection method between entities.
[0042] In the entity-relationship model, a foreign key is used to establish and maintain the relationship between two entities, and a foreign key can be a field (or a set of fields) in a table. For example, assume that an entity-relationship model includes a user table and a transaction table. The primary key of the user table can be the user ID, and the attributes of the user table can include user information such as the user name and user gender. The primary key of the transaction table can be the transaction ID, and the attributes of the transaction table can include the user ID corresponding to the transaction, the product ID, the logistics ID, etc.; the user table and the transaction table in this entity-relationship model can be connected through the foreign key user ID.
[0043] The property graph model is a graph data model used to represent and process complex data relationships, mainly including nodes, edges, and properties. Among them, a node can represent an entity, and each node can include multiple attributes; an edge can represent the connection between nodes, representing the relationship between entities, and can also include various attributes.
[0044] Figure 2 It is a flowchart of a model conversion method provided by an exemplary embodiment.
[0045] Please refer to Figure 2 , the model conversion method may include the following steps:
[0046] Step 202, when the entity-relationship model includes a first entity and a second entity with a connection relationship, convert the first entity into a first node in the property graph model.
[0047] Step 204, convert the second entity into a first edge of the first node, and determine the source node of the first edge as the first node.
[0048] In this embodiment, the connection between the first entity and the second entity is a relatively basic situation in the entity-relationship model. In this case, one of the entities can be converted into a node in the property graph model, and the other entity can be converted into an edge in the property graph model.
[0049] In this embodiment, the first entity can be converted into a node in the property graph model (referred to as the first node), the second entity can be converted into an edge of the first node (referred to as the first edge), and the first node is determined as the source node of the first edge.
[0050] Of course, in other examples, the second entity can also be converted into a node in the property graph model, the first node can be converted into an edge of the node, and the node can be determined as the source node of the edge. This specification does not impose special restrictions on this.
[0051] Please refer to Figure 3 for an example of Figure 3 The left side shows an entity relationship model. Taking the first entity as T1 and the second entity as T2 as an example, the first entity T1 can be connected to the second entity T2 through the foreign key FK11, and the second entity T2 can be connected to the first entity T1 through the foreign key FK21. Among them, FK11 is a field of entity T1, FK21 is a field of entity T2, and the contents of these two fields are usually the same.
[0052] For example, assume that the first entity T1 is a transaction table and the second entity T2 is a user table. The transaction table T1 is connected to the user table T2 through its field user ID, and the user table T2 is connected to the transaction table T1 through its field user ID. That is, the foreign keys FK11 and FK21 are essentially both user IDs.
[0053] Please refer to Figure 3 The converted property graph model 1 shown on the right side can convert the first entity T1 into a node vT1 (referred to as the first node vT1), and convert the second entity T2 into an edge eT2 (referred to as the first edge eT2). Among them, the attribute of the first edge eT2 is the attribute of the second entity T2. The source node of the first edge eT2 during property graph modeling is the first node vT1, and at the data mapping level, the source node of the first edge eT2 can be mapped by the foreign key FK21. Still taking T1 as the transaction table and T2 as the user table as an example, the source node of the first edge eT2 can be mapped by the user ID.
[0054] In another example, please refer to Figure 3 the converted property graph model 2 shown on the right side, for Figure 3For the entity relationship model shown on the left, T2 can also be regarded as the first entity and T1 as the second entity. In this way, T2 can be converted into the first node vT2, and T1 can be converted into the first edge eT1. Similarly, the attributes of the first edge eT1 are the attributes of the first entity T1. The source node of the first edge eT1 in the property graph modeling is the first node vT2. At the data mapping level, the source node of the first edge eT1 can be mapped by the foreign key FK11. Still taking T1 as the transaction table and T2 as the user table as an example, the source node of the first edge eT1 can be mapped by the user ID. Of course, to achieve such a conversion result, during the conversion, T1 can still be regarded as the first entity and T2 as the second entity, and then the second entity can be converted into the first node in the property graph model, and the first entity can be converted into the first edge of this first node, etc.
[0055] In this embodiment, during the conversion, for the entity relationship model in which the foregoing first entity and second entity are connected, all possible ways can be adopted for the conversion. After the conversion, multiple property graph models can be obtained. Still taking Figure 3 the entity relationship model shown on the left as an example, 2 property graph models shown on the right can be obtained after the conversion. Of course, one of the ways can also be adopted for the conversion, and a corresponding property graph model can be obtained after the conversion. This specification does not make special restrictions on this.
[0056] As can be seen from the above embodiments, for the model conversion solution provided in this specification for converting an entity relationship model into a property graph model, when the entity relationship model includes a first entity and a second entity with a connection relationship, the first entity is converted into the first node in the property graph model, the second entity is converted into the first edge of the first node, and the source node of the first edge is determined as the first node. Thus, the automatic conversion from the entity relationship model to the property graph model is realized. The whole process does not require manual intervention, which is highly friendly to ordinary users. At the same time, compared with the manual conversion method, the model conversion efficiency can be greatly improved, and the accuracy is relatively high.
[0057] In another embodiment of this specification, on the basis that the first entity and the second entity in the entity relationship model are connected, the second entity is also connected to the third entity. In this case, on the basis of converting the first entity into the first node in the property graph model and converting the second entity into the first edge of the first node, the third entity can also be converted into the second edge of the first node, and the source node of the second edge is also determined as the first node.
[0058] Please refer to Figure 4 In Figure 4In the entity relationship model shown above, entity T1 is connected to entity T2, and entity T2 is connected to entity T3. Taking the first entity as T1, the second entity as T2, and the third entity as T3 as an example, using the aforementioned Figure 2 shown conversion method, the first entity T1 can be converted into the first node vT1, and the second entity T2 can be converted into the first edge eT2. This first edge eT2 is still connected to entity T3, obtaining Figure 4 the model shown in the middle position. This model includes both an entity relationship model (such as the third entity T3) and an attribute graph model (such as the first node vT1). Then, the third entity T3 can be converted into an edge eT3 (referred to as the second edge eT3). The attribute of the second edge eT3 is the attribute of the third entity T3. The source node of the second edge eT3 during attribute graph modeling is the same as the source node of the first edge eT2, both being the node vT1. At the data mapping level, the source node of the second edge eT3 can be mapped using the foreign key F31, and then Figure 4 the converted attribute graph model shown below is obtained.
[0059] For example, assume that T1 is a transaction table, T2 is a user table, and T3 is a logistics table. The transaction table T1 and the user table T2 are connected through the foreign key user ID, and the user table T2 and the logistics table T3 are also connected through the foreign key user ID. Thus, the transaction table T1 and the logistics table T3 can also be connected through the foreign key user ID. In other words, the source node of the second edge eT3 can be mapped through the user ID.
[0060] Of course, in other examples, for Figure 4 the entity relationship model shown above, after conversion, the entity T3 can also be converted into a node in the attribute graph model, and then both entities T1 and T2 can be converted into the edges of this node. This specification does not make special restrictions on this.
[0061] In another embodiment of this specification, some entity relationship models may be relatively complex and include many entities. Then, in order to reduce the complexity of model conversion, improve conversion efficiency and accuracy, the relatively complex entity relationship model can be first split into multiple small entity relationship models, and then the split small entity relationship models can be converted.
[0062] In this embodiment, before converting the entity relationship model into an attribute graph model, it is also possible to determine whether the entity relationship model to be converted has the following situation: including a fourth entity having connection relationships with multiple entities, and the fourth entity is connected to the first part of the multiple entities using the same foreign key and is connected to the second part of the multiple entities using different foreign keys. If such a situation exists, that is, the entity relationship model to be converted includes a fourth entity having connection relationships with multiple entities, and the fourth entity is connected to the first part of the multiple entities using the same foreign key and is connected to the second part of the multiple entities using different foreign keys, then the entity relationship model can be split into two small entity relationship models (referred to as entity relationship sub-models). One entity relationship sub-model includes the fourth entity and the first part of the entities it is connected to, and the other entity relationship sub-model includes the fourth entity and the second part of the entities it is connected to. Then, each entity relationship sub-model is respectively converted.
[0063] Please refer to Figure 5 , Figure 5 The entity relationship model shown in the upper half includes multiple entities, namely entities T5 to T10. Among them, entity T5 is referred to as the fourth entity. This fourth entity T5 is connected to 5 entities. Among them, the fourth entity T5 is connected to entities T8, T9, and T10 using the same foreign key FK53, and is connected to entities T6 and T7 using different foreign keys. Specifically, the fourth entity T5 is connected to entity T6 using foreign key FK51 and is connected to entity T7 using foreign key FK52. In this example, the first part of the entities is entities T8, T9, and T10, and the second part of the entities is entities T6 and T7.
[0064] For example, the transaction table can be connected to the user table through the user ID, and can also be connected to the logistics table through the user ID, but needs to be connected to the commodity table through the commodity ID.
[0065] In this embodiment, for such an entity relationship model, due to the large number of entities, it can be split into two entity relationship sub-models. One entity relationship sub-model includes the fourth entity and the first part of the entities, and the other entity relationship sub-model includes the fourth entity and the second part of the entities.
[0066] Please refer to Figure 5 The split entity relationship sub-models shown in the lower half. Among them, the split entity relationship sub-model 1 includes the fourth entity T5-1 and the entities T6 and T7 it is connected to, and the entity relationship sub-model 2 includes the fourth entity T5-2 and the entities T8, T9, and T10 it is connected to.
[0067] In this embodiment, a complex entity relationship model can be split into two entity relationship sub-models, which can achieve the splitting of a relatively complex entity relationship model, reduce the difficulty of subsequent model conversion, and thus improve the efficiency and accuracy of subsequent model conversion.
[0068] In another embodiment of this specification, referring to the foregoing embodiment, in the process of converting an entity relationship model into an attribute graph model, in some cases, multiple attribute graph models can be obtained. For example, in the case of splitting an entity relationship model into two entity relationship sub-models, subsequent conversion is performed separately for each entity relationship sub-model, and at least two attribute graph models can be obtained. Please refer to Figure 6 , the model conversion method provided in this specification further includes the following steps:
[0069] Step 602, when the number of attribute graph models obtained after converting the entity relationship model is multiple, determine the structural complexity of each attribute graph model.
[0070] In this embodiment, when the number of attribute graph models obtained after conversion is multiple, the structural complexity of each attribute graph model can be determined separately.
[0071] In one example, the structural complexity can be determined based on the number of nodes and the number of edges of the attribute graph model. More simply, the sum of the number of nodes and the number of edges of the attribute graph model can be calculated as the structural complexity, or different weights can be assigned to the nodes and edges, and then the structural complexity can be calculated by weighted summation.
[0072] In another example, in addition to the number of nodes and the number of edges, the structural complexity of the attribute graph model can be comprehensively determined by combining the node attribute scale, the edge attribute scale, the presence of loops, the presence of special structures such as trees, etc. This specification does not make special restrictions on this.
[0073] Step 604, determine the attribute graph model with the lowest structural complexity as the conversion result of the entity relationship model.
[0074] Based on the foregoing step 602, after determining the structural complexity of each attribute graph model, the attribute graph model with the lowest structural complexity can be selected as the conversion result of the entity relationship model and output.
[0075] It can be seen that this embodiment selects the attribute graph model with the lowest structural complexity as the conversion result, which can effectively improve the query performance in the subsequent use of the attribute graph model.
[0076] Figure 7 It is a flowchart of another model conversion method provided by an exemplary embodiment.
[0077] Please refer to Figure 7, in another embodiment of this specification, when the entity relationship model to be converted is a connection between two entities, the following steps can also be used for model conversion:
[0078] Step 702, when the entity relationship model includes a fifth entity and a sixth entity with a connection relationship, convert the fifth entity into the third edge in the attribute graph model, and convert the sixth entity into the fourth edge in the attribute graph model.
[0079] Step 704, determine the source nodes of the third edge and the fourth edge as the foreign key for the connection between the fifth entity and the sixth entity.
[0080] In this embodiment, when the entity relationship model includes a fifth entity and a sixth entity with a connection relationship, both of these two entities can be converted into edges in the attribute graph model, and the foreign key for the connection between these two entities is determined as the source nodes of these two edges.
[0081] Please refer to Figure 8 for an example of Figure 8 The left side shows an entity relationship model. Taking the fifth entity as T1 and the sixth entity as T2 as an example, the fifth entity T1 can be connected to the sixth entity T2 through the foreign key FK11, and the sixth entity T2 can be connected to the fifth entity T1 through the foreign key FK21. Among them, FK11 is a field of entity T1, FK21 is a field of entity T2, and the contents of these two fields are usually the same.
[0082] Still assuming that the fifth entity T1 is a transaction table and the sixth entity T2 is a user table, the transaction table T1 is connected to the user table T2 through its field user ID, and the user table T2 is connected to the transaction table T1 through its field user ID, that is, the foreign key FK11 and the foreign key FK21 are essentially both user IDs.
[0083] Please refer to Figure 8 The converted attribute graph model shown on the right side. The fifth entity T1 can be converted into the third edge eT1, the sixth entity T2 can be converted into the fourth edge eT2, and the source nodes of the third edge eT1 and the fourth edge eT2 are both FKx. FKx is both the foreign key F11 for the connection between the fifth entity T1 and the sixth entity T2 and the foreign key FK21 for the connection between the sixth entity T2 and the fifth entity T1. Still taking the fifth entity T1 as a transaction table and the sixth entity T2 as a user table as an example, the source nodes of the converted third edge eT1 and the fourth edge eT2 are both the field user ID. The attribute of the third edge eT1 is the attribute of the fifth entity T1, and the attribute of the fourth edge eT2 is the attribute of the sixth entity T2.
[0084] It should be noted that for this case, since the source nodes of the third side eT1 and the fourth side eT2 are foreign keys and do not have attributes, they can also be regarded as virtual nodes, and this specification does not impose special restrictions on this.
[0085] As can be seen from the above embodiments, the model conversion solution provided in this specification for converting an entity relationship model into an attribute graph model, in the case where the entity relationship model includes a fifth entity and a sixth entity with a connection relationship, converts the fifth entity into the third side in the attribute graph model, converts the sixth entity into the fourth side, and determines the source nodes of the third side and the fourth side as the foreign keys for the connection between the fifth entity and the sixth entity. Thus, the automatic conversion from the entity relationship model to the attribute graph model is realized. The whole process does not require manual intervention, which is highly user-friendly for ordinary users. At the same time, compared with the manual conversion method, the model conversion efficiency can be greatly improved, and the accuracy is relatively high.
[0086] In another embodiment of this specification, on the basis that the fifth entity and the sixth entity in the entity relationship model are connected, the sixth entity is also connected to the seventh entity. In this case, on the basis of converting the fifth entity and the sixth entity into the third side and the fourth side in the attribute graph model, the seventh entity is also converted into the fifth side in the attribute graph model, and the source node of the fifth side is also determined as the foreign key.
[0087] Please refer to Figure 9 , in Figure 9 In the entity relationship model shown above, entity T1 is connected to entity T2, and entity T2 is connected to entity T3. Taking the fifth entity as T1, the sixth entity as T2, and the seventh entity as T3 as an example, on the basis of converting the fifth entity T1 into the third side eT1 and the sixth entity T2 into the fourth side eT2, please refer to Figure 9 In the attribute graph model shown below, the seventh entity T3 can be converted into the fifth side eT3. The attribute of this fifth side eT3 is the attribute of the seventh entity T3, and the source node of this fifth side eT3 is also the virtual node FKx.
[0088] Still taking T1 as the transaction table, T2 as the user table, and T3 as the logistics table, the transaction table T1 and the user table T2 are connected by the foreign key user ID, and the user table T2 and the logistics table T3 are also connected by the foreign key user ID. Then in Figure 9 In the converted attribute graph model, the source nodes of the third side eT1, the fourth side eT2, and the fifth side eT3 are all the field user ID.
[0089] In another embodiment of this specification, when adopting Figure 7When performing model conversion using the conversion method shown, the complex entity relationship model can still be first split into multiple entity relationship sub-models, and then model conversion can be performed separately for each entity relationship sub-model. In the case where multiple property graph models can be obtained after conversion, the property graph model with the lowest structural complexity can be determined as the conversion result of the entity relationship model. The specific implementation method can refer to the foregoing embodiments, and will not be elaborated herein one by one.
[0090] In another embodiment of this specification, multiple conversion templates and their corresponding property graph conversion strategies can be preset in advance, and then the entity relationship model can be converted into a property graph model based on the conversion template and its corresponding property graph conversion strategy. Please refer to Figure 10 , the model conversion method may include the following steps:
[0091] Step 1002, obtain the entity relationship model as the model to be converted.
[0092] Step 1004, match the model to be converted with the i-th conversion template.
[0093] In this embodiment, multiple conversion templates and the property graph conversion strategy corresponding to each conversion template can be preset in advance. Among them, the conversion template may include the connection relationship between entities, and may also include the connection relationship between an entity and an edge in the property graph model, etc. The property graph conversion strategy is used to convert the sub-model that matches the corresponding conversion template during the process of converting the entity relationship model into a property graph model. The converted result may be a property graph model or may still be an entity relationship model. Each conversion template may correspond to one property graph conversion strategy or may correspond to multiple property graph conversion strategies. This specification does not make special restrictions on this.
[0094] In this embodiment, the initial value of i is usually 1, and the model to be converted can be first matched with the first conversion template. Among them, the first conversion template may be the first implementation relationship template written by a developer, or one can be randomly selected from all conversion templates as the first conversion template, etc. Of course, in other examples, the initial value of i can also be other values such as 2, 3, etc.
[0095] In this embodiment, when matching the model to be converted with the conversion template, several entities or nodes can be randomly selected from the model to be converted, and then it is determined whether the selected partial model (subsequent referred to as the sub-model) matches the first conversion template.
[0096] In this embodiment, if the model to be converted matches the i-th conversion template, that is, there is a sub-model in the model to be converted that matches the i-th conversion template, for the convenience of distinction, the sub-model in the model to be converted that matches the conversion template is called the first type of sub-model, and step 1006 can be continued. If the model to be converted does not match the i-th conversion template, that is, there is no first type of sub-model in the model to be converted that matches the i-th conversion template, then i can be updated to i + 1, and this step can be continued to match the model to be matched with the (i + 1)-th conversion template.
[0097] Step 1006, in the case that there is a first type of sub-model in the model to be converted that matches the i-th conversion template, obtain the attribute graph conversion strategy corresponding to the i-th conversion template.
[0098] Based on the matching result of the foregoing step 1004, if it is determined that there is a first type of sub-model in the model to be converted that matches the i-th conversion template, then the attribute graph conversion strategy corresponding to the i-th conversion template can be obtained.
[0099] Step 1008, use the attribute graph conversion strategy to convert the first type of sub-model in the model to be converted into a second type of sub-model to obtain an intermediate model.
[0100] Based on the foregoing step 1006, after obtaining the attribute graph conversion strategy corresponding to the i-th conversion template, the attribute graph conversion strategy can be used to convert the first type of sub-model in the model to be converted, and the model obtained after conversion is called an intermediate model. Among them, the sub-model obtained by converting the first type of sub-model in the intermediate model can be called the second type of sub-model.
[0101] It should be noted that the entities, connection relationships, and other structures in the model to be converted that do not belong to the first type of sub-model are not converted this time because they do not match the conversion template, and their structures do not change. In other words, the intermediate model includes the second type of sub-model obtained by converting the first type of sub-model and the entities, connection relationships, and other structures in the model to be converted that are not converted this time.
[0102] In this embodiment, if the i-th conversion template corresponds to multiple attribute graph conversion strategies, each attribute graph conversion strategy can be used to convert the first type of sub-model in the model to be converted into a second type of sub-model, and multiple intermediate models can be obtained.
[0103] Step 1010, update the model to be converted to the intermediate model, update i to i + 1, and continue to execute the steps of matching the model to be converted with the conversion template until all conversion templates are matched to obtain the converted attribute graph model.
[0104] In this embodiment, after obtaining the intermediate model, the aforementioned model to be converted can be updated to the intermediate model, i is updated to i + 1, and then step 1004 is executed again. The intermediate model is matched with the (i + 1)-th conversion template, and subsequent steps can be executed based on the matching result until all conversion templates are matched, and the attribute graph model after the conversion of the aforementioned entity relationship model can be obtained.
[0105] In this embodiment, if a conversion template corresponds to multiple attribute graph conversion strategies, or an attribute graph conversion strategy is to convert a first type of sub-model into multiple second type of sub-models, then after all conversion templates are matched, multiple attribute graph models can be obtained. In actual implementation, all the obtained multiple attribute graph models can be output as the conversion result of the entity relationship model; alternatively, an attribute graph model with a lower structural complexity can be selected from the obtained multiple attribute graph models as the conversion result of the entity relationship model for output. This specification does not make special restrictions on this.
[0106] As can be seen from the above description, the model conversion solution provided in this specification for converting an entity relationship model into an attribute graph model can first use the entity relationship model as the model to be converted, match the model to be converted with the i-th conversion template, and in the case where there is a first type of sub-model in the model to be converted that matches the i-th conversion template, use the attribute graph conversion strategy corresponding to the i-th conversion template to convert the first type of sub-model in the model to be converted into a second type of sub-model to obtain an intermediate model; then update the model to be converted to the intermediate model, update i to i + 1, and continue to execute the step of matching the model to be converted with the conversion template until all conversion templates are matched to obtain the converted attribute graph model.
[0107] Thus, it can be seen that by adopting the above technical solution provided in this specification, through setting conversion templates and the attribute graph conversion strategies corresponding to the conversion templates, the automatic conversion from an entity relationship model to an attribute graph model can be realized. The whole process does not require manual intervention, which is highly friendly to ordinary users. At the same time, compared with the manual conversion method, the model conversion efficiency can be greatly improved, and the accuracy is relatively high.
[0108] Figure 11 It is a flowchart of another model conversion method provided by an exemplary embodiment.
[0109] Please refer to Figure 11 , the model conversion method may include the following steps:
[0110] Step 1102, obtain an entity relationship model as the model to be converted.
[0111] Step 1104, match the model to be converted with the i-th conversion template.
[0112] In this embodiment, assuming that the initial value of i is 1, the model to be converted can be matched with the first conversion template.
[0113] When performing the matching, an entity can be randomly selected from the model to be converted, and then the entity connected to this entity is selected as the neighbor entity of the entity, and it is determined whether the selected entity matches the first conversion template. If it does not match, the selection of neighbor entities can continue, so as to determine whether there is a first type of sub-model in the model to be converted that matches the first conversion template.
[0114] In this embodiment, if there is a first type of sub-model in the model to be converted that matches the first conversion template, step 1106 can be continued. If there is no first type of sub-model in the model to be converted that matches the first conversion template, i can be updated to i + 1, that is, it is continued to determine whether the model to be converted matches the second conversion template.
[0115] In this embodiment, if the model to be converted does not match all conversion templates, an error prompt can be output.
[0116] Step 1106, in the case that there is a first type of sub-model in the model to be converted that matches the i-th conversion template, obtain the attribute graph conversion strategy corresponding to the i-th conversion template.
[0117] Based on the matching result of the foregoing step 1104, if it is determined that there is a first type of sub-model in the model to be converted that matches the first conversion template, the attribute graph conversion strategy corresponding to the first conversion template can be obtained. If the first conversion template corresponds to one attribute graph conversion strategy, this one attribute graph conversion strategy can be obtained. If the first conversion template corresponds to multiple attribute graph conversion strategies, each corresponding attribute graph conversion strategy can be obtained.
[0118] Step 1108, use the attribute graph conversion strategy to convert the first type of sub-model in the model to be converted into a second type of sub-model to obtain an intermediate model.
[0119] Based on the foregoing step 1106, after obtaining the attribute graph conversion strategy corresponding to the first conversion template, the obtained attribute graph conversion strategy can be used to convert the first type of sub-model in the model to be converted to obtain an intermediate model.
[0120] In this embodiment, there may be only one first type of sub-model in the model to be converted that matches the first conversion template, or there may be multiple first types of sub-models that match the first conversion template. In this step, all first types of sub-models in the model to be converted that match the first conversion template can be converted.
[0121] Suppose there are 5 first-class sub-models in the model to be converted that match the first conversion template. Then, the corresponding attribute graph conversion strategies can be used to convert each first-class sub-model respectively. Suppose the corresponding attribute graph conversion strategy is used to convert 1 first-class sub-model into 1 second-class sub-model. In this way, the intermediate model obtained includes 5 converted second-class sub-models.
[0122] In this embodiment, suppose the first conversion template corresponds to 3 attribute graph conversion strategies, and each attribute graph conversion strategy is used to convert 1 first-class sub-model into 1 second-class sub-model. Then, these 3 attribute graph conversion strategies can be respectively used to convert the first-class sub-models in the model to be converted, and thus 3 intermediate models are obtained.
[0123] In this embodiment, the attribute graph conversion strategy may also be used to convert 1 first-class sub-model into multiple second-class sub-models. For example, the first-class sub-model is split into 2 second-class sub-models, etc. Suppose the model to be converted includes 1 first-class sub-model, and the attribute graph conversion strategy is used to convert 1 first-class sub-model into 2 second-class sub-models. Then, based on this attribute graph conversion strategy, the model to be converted is converted, and 2 intermediate models can be obtained.
[0124] In this embodiment, after completing this round of conversion, the model to be converted can be updated to the intermediate model obtained after this round of conversion, and i is updated to i + 1. Then, step 1104 is continued to match the updated model to be converted with the next conversion template.
[0125] Suppose 1 intermediate model is obtained in this step. Then, the model to be converted can be updated to this intermediate model obtained in this step, and then this intermediate model is matched with the second conversion template.
[0126] Suppose 3 intermediate models are obtained in this step. Then, the model to be converted can be updated to these 3 intermediate models respectively, that is, 3 updated models to be converted are obtained. Then, these 3 updated models to be converted are respectively matched with the second conversion template, that is, these 3 intermediate models are respectively matched with the second conversion template. In other words, if multiple intermediate models are obtained, each intermediate model will be used as a branch to continue to execute subsequent steps such as matching the conversion template.
[0127] Step 1110: Each conversion template has completed the matching, and an attribute graph model after conversion is obtained.
[0128] In this embodiment, after performing multiple rounds of matching and conversion, if the model to be converted has completed the matching with each preset conversion template, an attribute graph model after the conversion of the entity relationship model can be obtained.
[0129] In this embodiment, it is assumed that the first transformation template corresponds to three attribute graph transformation strategies, and other transformation templates each correspond to one attribute graph transformation strategy. Moreover, all attribute graph transformation strategies are used to transform one first-type sub-model into one second-type sub-model. Then, after all the transformation templates are matched, three attribute graph models can be obtained.
[0130] In one example, the three obtained attribute graph models can all be output as the transformation results of the entity relationship model.
[0131] In another example, one attribute graph model can also be selected from these three attribute graph models as the transformation result of the entity relationship model for output. Specifically, step 312 can be continued.
[0132] Step 1112: When the number of transformed attribute graph models is multiple, determine the structural complexity of each attribute graph model.
[0133] In this embodiment, when the number of obtained attribute graph models after transformation is multiple, the structural complexity of each attribute graph model can be determined respectively.
[0134] In one example, the structural complexity can be determined based on the number of nodes and the number of edges of the attribute graph model. More simply, the sum of the number of nodes and the number of edges of the attribute graph model can be calculated as the structural complexity, or different weights can be assigned to the nodes and edges, and then the structural complexity can be calculated by means of weighted summation.
[0135] In another example, in addition to the number of nodes and the number of edges, the structural complexity of the attribute graph model can also be comprehensively determined in combination with special structures such as the scale of node attributes, the scale of edge attributes, the existence of loops, and the existence of trees. This specification does not make special restrictions on this.
[0136] Step 1114: Determine the attribute graph model with the lowest structural complexity as the transformation result of the entity relationship model.
[0137] Based on the foregoing step 1112, after determining the structural complexity of each attribute graph model, the attribute graph model with the lowest structural complexity can be selected as the transformation result of the entity relationship model and output.
[0138] In this embodiment, the attribute graph model with the lowest structural complexity is selected as the transformation result, which can effectively improve the query performance during the subsequent use of the attribute graph model.
[0139] As can be seen from the above description, by setting the conversion template and the corresponding property graph conversion strategy for the conversion template, the present specification can achieve the automatic conversion from the entity relationship model to the property graph model. The entire process does not require manual intervention, which is highly user-friendly for ordinary users. At the same time, compared with the manual conversion method, it can greatly improve the model conversion efficiency and has a high accuracy rate. In addition, based on the model conversion solution provided in the present specification, the conversion template and its corresponding property graph conversion strategy can be extended according to the actual situation, thereby continuously improving the process of converting the entity relationship model to the property graph model and enhancing the conversion efficiency and accuracy.
[0140] The following introduces several conversion templates provided in the present specification and their corresponding property graph conversion strategies.
[0141] I. The conversion template is the connection between the first entity and the second entity.
[0142] The conversion template introduced in this embodiment is the connection between the first entity and the second entity.
[0143] In one example, for the conversion template of the connection between the first entity and the second entity, the corresponding property graph conversion strategy can be to convert both the first entity and the second entity in the first type of sub-model in the model to be converted into edges in the property graph model. For example, convert the first entity into the first edge and the second entity into the second edge, and then the source nodes of these two edges can be determined as the foreign keys for the connection between the first entity and the second entity, and the attributes of these two edges are the attributes of the corresponding entities. For details, reference can be made to the foregoing Figure 8 illustrated embodiment.
[0144] In another example, for the conversion template of the connection between the first entity and the second entity, the corresponding property graph conversion strategy can be to convert one entity in the first type of sub-model into a node in the property graph model and the other entity into an edge in the property graph, and the source node of this edge is the node obtained after the conversion of the other entity. For example, the first entity in the first type of sub-model can be converted into the first node, the second entity can be converted into the third edge, and the source node of the third edge can be determined as the first node. For details, reference can be made to the foregoing Figure 3 illustrated embodiment.
[0145] In this embodiment, when there is a first type of sub-model in the model to be converted that matches the conversion template shown in this embodiment, the corresponding property graph conversion strategy provided in this embodiment can be used to convert it into 3 second type of sub-models respectively, and then 3 intermediate models can be obtained. The 3 second type of sub-models shown in this embodiment are all property graph models.
[0146] It should be noted that in practical applications, in addition to being connected to the first entity, the second entity in the first type of sub-model may also be connected to other entities. For example, the second entity may also be connected to the third entity. Since the conversion template shown in this embodiment shows the connection between the first entity and the second entity and does not involve the third entity, this model conversion does not involve the third entity either. The connection relationship between the second entity and the third entity remains unchanged, and in the resulting intermediate model, the third entity is still connected to the node or edge obtained after the conversion of the second entity. The subsequent attribute graph conversion strategy is similar. For the entities in the model to be converted that do not match the conversion template, the connection relationship with their connection objects remains unchanged.
[0147] Second, the conversion template is that a fourth entity is connected to multiple entities respectively, and the fourth entity is connected to the first part of the multiple entities using the same foreign key and is connected to the second part of the multiple entities using different foreign keys.
[0148] The conversion template introduced in this embodiment is that a fourth entity is connected to multiple entities respectively, and the fourth entity is connected to the first part of the multiple entities using the same foreign key and is connected to the second part of the multiple entities using different foreign keys. Then, the entity relationship model can be split into two entity relationship sub-models. One entity relationship sub-model includes the fourth entity and the first part of the entities it is connected to, and the other entity relationship sub-model includes the fourth entity and the second part of the entities it is connected to. For details, reference can be made to the foregoing Figure 5 illustrated embodiment.
[0149] Third, a fifth entity is connected to a fourth edge.
[0150] The conversion template introduced in this embodiment is that a fifth entity is connected to a fourth edge. Among them, the fifth entity is an entity in the entity relationship model, and the fourth edge is an edge in the attribute graph model. This conversion template is a scenario where the entity relationship model is associated with the attribute graph model. Its corresponding attribute graph conversion strategy can be to convert the fifth entity into an edge (referred to as the fifth edge) in the attribute graph model, and determine the source node of the fifth edge as the source node of the fourth edge. For details, reference can be made to the foregoing Figure 4 illustrated embodiment.
[0151] The above conversion templates and their corresponding attribute graph conversion strategies are only for illustrative purposes. In practical applications, developers can develop other conversion templates and their corresponding attribute graph conversion strategies based on expert experience to improve the model conversion process. This specification places no special restrictions on this.
[0152] Figure 12 is a schematic structural diagram of a device provided by an exemplary embodiment. Please refer to Figure 12At the hardware level, the device includes a processor 1202, an internal bus 1204, a network interface 1206, a memory 1208, and a non-volatile memory 1210, and may also include hardware required for other functions. One or more embodiments of this specification may be implemented based on software, such as the processor 1202 reading the corresponding computer program from the non-volatile memory 1210 into the memory 1208 and then running it. Of course, in addition to the software implementation, one or more embodiments of this specification do not exclude other implementations, such as logic devices or a combination of software and hardware, etc., that is, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0153] Please refer to Figure 13 The model conversion device 1300 can be applied to Figure 12 The device shown in the figure is used to implement the technical solution of this specification. The model conversion device 1300 may include:
[0154] The first conversion unit 1301, when the entity relationship model includes a first entity and a second entity having a connection relationship, converts the first entity into a first node in the property graph model; converts the second entity into a first edge of the first node, and determines the source node of the first edge as the first node.
[0155] Optionally, when the second entity is also connected to a third entity in the entity relationship model, the first conversion unit 1301 further converts the third entity into a second edge of the first node, and determines the source node of the second edge as the first node.
[0156] Optionally, the model conversion device 1300 also includes: a model splitting unit 1302, which, before converting the first entity into the first node in the property graph model, includes a fourth entity in the entity relationship model that has a connection relationship with multiple entities, and the fourth entity uses the same foreign key to connect to a first part of the entities in the multiple entities, and uses different foreign keys to connect to a second part of the entities in the multiple entities. The entity relationship model is split into two entity relationship sub-models, one of which includes the fourth entity and the first part of the entities connected to it, and the other includes the fourth entity and the second part of the entities connected to it.
[0157] Optionally, the model conversion device 1300 also includes: a result determination unit 1303, which determines the structural complexity of each property graph model when there are multiple property graph models obtained after converting the entity relationship model; and determines the property graph model with the lowest structural complexity as the conversion result of the entity relationship model.
[0158] Please refer to Figure 14 , another model conversion device 1400 provided in this specification can also be applied to devices such as Figure 12 shown in the figure to implement the technical solutions of this specification. Among them, the model conversion device 1400 may include:
[0159] A second conversion unit 1401, when the entity relationship model includes a fifth entity and a sixth entity with a connection relationship, converts the fifth entity into a third edge in the attribute graph model, and converts the sixth entity into a fourth edge in the attribute graph model; determines the source nodes of the third edge and the fourth edge as the foreign key for the connection between the fifth entity and the sixth entity.
[0160] Optionally, when the sixth entity in the entity relationship model is also connected to a seventh entity, the second conversion unit 1401 converts the seventh entity into a fifth edge in the attribute graph model, and determines the source node of the fifth edge as the foreign key.
[0161] Optionally, the model conversion device 1400 further includes: a model splitting unit 1402. Before converting the fifth entity into a third edge in the attribute graph model, when the entity relationship model includes a fourth entity that has a connection relationship with multiple entities, and the fourth entity is connected to the first part of the multiple entities using the same foreign key and is connected to the second part of the multiple entities using different foreign keys, splits the entity relationship model into two entity relationship sub-models, where one entity relationship sub-model includes the fourth entity and the first part of the entities it is connected to, and the other entity relationship sub-model includes the fourth entity and the second part of the entities it is connected to.
[0162] Optionally, the model conversion device 1400 further includes: a result determination unit 1403. When the number of attribute graph models obtained after converting the entity relationship model is multiple, determines the structural complexity of each attribute graph model; determines the attribute graph model with the lowest structural complexity as the conversion result of the entity relationship model.
[0163] Based on the same concept as the above method, this specification also provides an electronic device, including: a processor; a memory for storing processor-executable instructions; wherein, the processor runs the executable instructions to implement the steps of the method as described in any one of the above embodiments.
[0164] Based on the same concept as the above method, this specification also provides a computer-readable storage medium, on which computer instructions are stored, and when the instructions are executed by a processor, the steps of the method as described in any one of the above embodiments are implemented.
[0165] Based on the same concept as the above method, this specification also provides a computer program product, including computer programs / instructions, which, when executed by a processor, implement the steps of the method described in any of the above embodiments.
Claims
1. A model conversion method, comprising: In a case where a first entity and a second entity having a connection relationship are included in the entity relationship model, converting the first entity into a first node in the property graph model; The second entity is converted into a first edge of the first node, and a source node of the first edge is determined to be the first node.
2. The method according to claim 1, further comprising: In the case where the second entity is also connected to a third entity in the entity relationship model, the third entity is converted into a second edge of the first node, and the source node of the second edge is determined to be the first node.
3. The method according to claim 1, before converting the first entity into a first node in a property graph model, the method further comprises: In the case where the entity-relationship model includes a fourth entity having a connection relationship with multiple entities, and the fourth entity is connected to a first part of entities among the multiple entities using the same foreign key and is connected to a second part of entities among the multiple entities using different foreign keys, the entity-relationship model is split into two entity-relationship sub-models, one of which includes the fourth entity and the first part of entities connected to it, and the other of which includes the fourth entity and the second part of entities connected to it.
4. According to the method of claim 1, when there are multiple property graph models obtained after converting the entity relationship model, the method further comprises: Determine the structural complexity of each property graph model; The property graph model with the lowest structural complexity is determined as the conversion result of the entity relationship model.
5. A model conversion method, comprising: In the case where the entity relationship model includes a fifth entity and a sixth entity having a connection relationship, converting the fifth entity into a third edge in the property graph model, and converting the sixth entity into a fourth edge in the property graph model; The source nodes of the third edge and the fourth edge are determined as foreign keys connecting the fifth entity and the sixth entity.
6. The method according to claim 5, further comprising: In the case that the sixth entity is also connected to the seventh entity in the entity relationship model, the seventh entity is converted into the fifth edge in the property graph model, and the source node of the fifth edge is determined as the foreign key.
7. The method according to claim 5, before converting the fifth entity into a third edge in the property graph model, the method further comprises: In the case where the entity-relationship model includes an eighth entity having a connection relationship with multiple entities, and the eighth entity is connected to a first part of entities among the multiple entities using the same foreign key and is connected to a second part of entities among the multiple entities using different foreign keys, the entity-relationship model is split into two entity-relationship sub-models, one of which includes the eighth entity and the first part of entities connected to it, and the other of which includes the eighth entity and the second part of entities connected to it.
8. The method according to claim 5, wherein when there are multiple property graph models obtained after converting the entity relationship model, the method further comprises: Determine the structural complexity of each property graph model; The property graph model with the lowest structural complexity is determined as the conversion result of the entity relationship model.
9. A model conversion device, comprising: A first conversion unit, when the entity relationship model includes a first entity and a second entity having a connection relationship, converts the first entity into a first node in the property graph model; The second entity is converted into a first edge of the first node, and a source node of the first edge is determined to be the first node.
10. A model conversion device, comprising: The second conversion unit, when the entity relationship model includes a fifth entity and a sixth entity having a connection relationship, converts the fifth entity into a third edge in the property graph model and converts the sixth entity into a fourth edge in the property graph model; and determines the source nodes of the third edge and the fourth edge as foreign keys connecting the fifth entity and the sixth entity.
11. An electronic device, comprising: processor; A memory for storing processor-executable instructions; wherein the processor implements the steps of the method according to any one of claims 1 to 8 by executing the executable instructions.
12. A computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the steps of the method according to any one of claims 1 to 8.
13. A computer program product, comprising a computer program / instruction, which, when executed by a processor, implements the steps of the method according to any one of claims 1 to 8.