A multi-hop path query method, device, computer equipment and storage medium
By determining multiple groups of path query units in the graph database and updating the path correlation, the problem of low efficiency of multi-hop path query in the graph database is solved, and the effect of simplifying the query process and improving efficiency is achieved.
Patent Information
- Application Number
- CN202311368456.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-20
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2043-10-20
AI Technical Summary
When the distance between the query node and the target node in the graph database is greater than 1, the query process is complex, large-scale and inefficient, resulting in low efficiency of multi-hop path query.
By determining multiple groups of path query units in the graph database, each group of units includes a third entity and a fourth entity that communicate with each other and are adjacent, and the path correlation degree of the fourth entity is updated based on the initial value of the path correlation degree. When the target entity is queried When , its path correlation is used as the final value, and the optimal query path is selected from all paths of the target entity to locate the target entity.
It simplifies the multi-hop path query process in graph databases, reduces the query scope, improves query efficiency, and avoids the need to query target entities one after another.
Smart Images

Figure CN117556086B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of multi-hop path query, and in particular to a multi-hop path query method, device, computer equipment and storage medium. Background Art
[0002] Graph databases have become a common type of database that can effectively store and manage data with complex relationships. However, when the distance between the query node and the target node is greater than 1, it is often necessary to specify the entity type of the starting node and the number of jumps required, as well as the edges to be passed, based on the graph structure, and to enumerate all business requirements. The target entity is then queried one by one based on the written attribute information according to different business requirements, resulting in a more complex query process, a larger query range, and lower query efficiency. Summary of the invention
[0003] In view of this, the present invention provides a multi-hop path query method, apparatus, computer equipment and storage medium to solve the problems of complex query process, large query range and low query efficiency.
[0004] According to a first aspect, an embodiment of the present invention provides a multi-hop path query method, the method comprising:
[0005] Query key information of the target entity based on user input, and obtain a first entity matching the key information;
[0006] Based on the attribute information of the first entity, a second entity associated with the first entity is acquired, and an initial value of the path association degree of the second entity is set;
[0007] Simultaneously determining a plurality of groups of path query units in the graph database, each group of path query units including a third entity and a fourth entity that are in communication with each other and adjacent to each other;
[0008] When traversing and querying the target entity in the graph database, if there is an inclusion relationship between the third entity and the fourth entity in each group of path query units, and the entity type to which the fourth entity belongs has not been traversed and queried, the current value of the path relevance of the fourth entity is updated based on the initial value of the path relevance. Once the target entity is queried, the current value of the path relevance of the fourth entity is used as the final value of the path relevance of the target entity;
[0009] Based on the final value of the path relevance of the target entity obtained by each group of path query units, all target query paths of the target entity are obtained, and the optimal query path is selected from all target query paths of the target entity;
[0010] Based on the optimal query path, locate the target entity.
[0011] By executing the above implementation, multiple groups of path query units are simultaneously determined in the graph database, and based on the inclusion relationship and entity type between the third entity and the fourth entity that communicate with each other and are adjacent in each group of path query units, the current value of the path association of the fourth entity is updated by the initial value of the path association. When the target entity is queried, the current value of the path association of the fourth entity is used as the final value of the path association of the target entity, and the optimal query path is selected from all target query paths of the target entity to obtain the target entity. This can achieve the goal of narrowing the query range of the multi-hop path of the target entity based on the graph database, so as to avoid querying the target entity one by one based on the written attribute information in the graph database, thereby achieving the purpose of simplifying the query process and improving the query efficiency.
[0012] In an optional implementation, the multi-hop path query method in this embodiment further includes: when traversing and querying the target entity in the graph database, if there is an inclusion relationship between the third entity and the fourth entity in each group of path query units, and other entities of the same entity type as the fourth entity have not been traversed and queried, then the current value of the path association of the fourth entity is updated based on the initial value of the path association, and if the target entity is not queried, then returning to the step of simultaneously determining multiple groups of path query units in the graph database until the target entity is queried.
[0013] By executing the above implementation, if the target entity is not found in the current group path query unit, return to step S103, loop query the target entity in the graph database, and finally locate the target entity in the multi-hop path of the graph database with the fastest speed, smallest query scope, and simplest query process.
[0014] In an optional implementation, updating the current value of the path relevance of the fourth entity based on the initial value of the path relevance, and once the target entity is found, using the current value of the path relevance of the fourth entity as the final value of the path relevance of the target entity, includes:
[0015] The initial value of the path relevance is used as the current value of the path relevance of the third entity;
[0016] Obtaining a preset value of the path relevance of the third entity;
[0017] Obtaining a preset path direction of the traversal query target entity and an actual path direction between the third entity and the fourth entity;
[0018] If the preset path direction is consistent with the actual path direction, a minimum value is selected between the current value of the path relevance of the third entity and the preset value of the path relevance of the third entity;
[0019] If the preset path direction is inconsistent with the actual path direction, the path association degree of the third entity is preset to a minimum value;
[0020] When the target entity is found through traversal query, the minimum value is used as the current value of the path relevance of the fourth entity; the current value of the path relevance of the fourth entity is the final value of the path relevance of the target entity;
[0021] When the target entity is not found through traversal query, the process returns to the step of simultaneously determining multiple groups of path query units in the graph database until the target entity is found.
[0022] Based on the initial value of the path relevance, the minimum value between the current value of the path relevance of the third entity and the preset value of the path relevance of the fourth entity is calculated to update the final value of the path relevance of the target entity, which can simplify the query process and improve query efficiency.
[0023] In an optional implementation, selecting an optimal query path from all target query paths of the target entity includes:
[0024] The largest final path relevance value is selected from all target query paths of the target entity, and the largest final path relevance value is used as the optimal query path of the target entity.
[0025] By executing the above implementation, the target entity can be quickly located through the optimal query path.
[0026] In an optional implementation, the multi-hop path query method in this embodiment further includes: when traversing the query target entity in the graph database, if there is no inclusion relationship between the third entity and the fourth entity in each group of path query units, returning to the step of simultaneously determining multiple groups of path query units in the graph database to redetermine the query path.
[0027] By executing the above implementation, the query efficiency of the target entity can be improved and the query scope can be reduced.
[0028] In an optional implementation, the multi-hop path query method in this embodiment further includes: when traversing the query target entity in the graph database, if there is an inclusion relationship between the third entity and the fourth entity in each group of path query units, and the entity type of the fourth entity has been traversed and queried, then returning to the step of simultaneously determining multiple groups of path query units in the graph database to redetermine the query path.
[0029] By executing the above implementation, repeated queries can be avoided, ultimately achieving the purpose of quickly querying the target entity and avoiding expanding the query scope.
[0030] In an optional implementation, the target entity, the first entity, the second entity, the third entity, and the fourth entity are all power grid entities, and entity types of the power grid entities include: substation, manufacturer equipment, asset equipment, manufacturer, and product information.
[0031] By executing the above implementation, a grid entity can be queried.
[0032] In an optional implementation, the substation includes manufacturer equipment; the manufacturer equipment includes asset equipment and product information; the manufacturer includes product information.
[0033] By executing the above implementation, based on the inclusion relationship between different types of power grid entities, it is helpful to further narrow the query scope.
[0034] According to a second aspect, an embodiment of the present invention further provides a multi-hop path query device, the device comprising:
[0035] A key information acquisition module, used to query the key information of the target entity based on user input, and acquire a first entity matching the key information;
[0036] An associated entity acquisition module, used to acquire a second entity associated with the first entity based on the attribute information of the first entity, and set an initial value of the path association degree of the second entity;
[0037] A query unit selection module, used to simultaneously determine multiple groups of path query units in the graph database, each group of path query units including a third entity and a fourth entity that communicate with each other and are adjacent;
[0038] A target entity query module is used to update the current path relevance value of the fourth entity based on the initial path relevance value when traversing and querying the target entity in the graph database. If there is an inclusion relationship between the third entity and the fourth entity in each group of path query units, and the entity type to which the fourth entity belongs has not been traversed and queried, once the target entity is queried, the current path relevance value of the fourth entity is used as the final path relevance value of the target entity;
[0039] An optimal path selection module, used to obtain all target query paths of the target entity based on the final value of the path association degree of the target entity obtained by each group of path query units, and select the optimal query path from all target query paths of the target entity;
[0040] The target entity positioning module is used to locate the target entity based on the optimal query path.
[0041] According to a third aspect, an embodiment of the present invention further provides a computer device, including:
[0042] The memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the multi-hop path query method in the first aspect or any embodiment of the first aspect by executing the computer instructions.
[0043] According to a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, on which computer instructions are stored, and the computer instructions are used to enable a computer to execute the multi-hop path query method in the first aspect or any implementation of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0045] Figure 1 is a schematic diagram of a flow chart of a multi-hop path query method according to an embodiment of the present invention;
[0046] Figure 2 is a schematic diagram of the relationship between entities according to an embodiment of the present invention;
[0047] Figure 3 is a schematic diagram of dividing a path query unit according to an embodiment of the present invention;
[0048] Figure 4 is a schematic diagram of a query target entity according to an embodiment of the present invention;
[0049] Figure 5 is a flow chart of another multi-hop path query method according to an embodiment of the present invention;
[0050] Figure 6 is a flow chart of another multi-hop path query method according to an embodiment of the present invention;
[0051] Figure 7 is a structural block diagram of a multi-hop path query device according to an embodiment of the present invention;
[0052] Figure 8 It is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0053] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0054] According to an embodiment of the present invention, a multi-hop path query method embodiment is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0055] In this embodiment, a multi-hop path query method is provided, which can be used in mobile terminals, such as mobile phones, tablet computers, etc. (the execution subject is described in combination with actual conditions). Figure 1 is a flow chart of a multi-hop path query method according to an embodiment of the present invention. Figure 1 As shown, the process includes the following steps:
[0056] Step S101 : querying key information of a target entity based on user input, and acquiring a first entity matching the key information.
[0057] In some optional implementations, the target entity includes a power grid entity, and the entity type of the power grid entity includes a substation, a manufacturer's equipment, an asset equipment, a manufacturer, and product information; Figure 2 As shown, the substation includes manufacturer equipment; the manufacturer equipment includes asset equipment; the manufacturer includes product information; the manufacturer equipment includes product information.
[0058] Specifically, the entity type of the target entity is also mainly a substation, manufacturer equipment, asset equipment, and product information. In other alternative implementations, the entity type of the target entity can also be an entity in other fields, such as a communication entity, and is not limited to a power grid entity.
[0059] The substation entity mentioned above mainly records the location information, voltage level and maintenance team information of the substation. The substation entity has fields: substation name, station address and other information; manufacturer equipment is a type of equipment designed by the manufacturer according to the model and voltage level, with parameter information designed by the manufacturer, so one manufacturer equipment corresponds to multiple asset equipment, with fields: equipment type, voltage level, model, manufacturer, each manufacturer equipment contains multiple product information, and each manufacturer equipment will contain multiple corresponding asset equipment; asset equipment is the physical equipment placed in the substation by the procurement department, with equipment code and actual operation parameter information, what equipment a substation has, with fields: equipment type, voltage level, model, manufacturer; manufacturer is a collection that describes the manufacturer, mainly including factory address, telephone number, business qualifications, etc.; product information manufacturer provides reference materials for the designed equipment, including all documents such as instruction manual, installation schematic, test report, drawings, etc. A manufacturer-designed equipment includes multiple product information.
[0060] For example, if the relevant product information of Henan Substation is queried according to business needs, the target entity is the relevant product information of Henan Substation, and the key information of the target entity input by the user is obtained as "Henan Substation". The first entity is matched based on the keyword information of "Henan Substation", and the first power grid entity also belongs to the power grid entity, that is, the entity type of the first power grid entity can also be one of substation, manufacturer equipment, asset equipment, manufacturer, and product information. Therefore, the first entity matched based on the keyword information of "Henan Substation" is Henan Substation.
[0061] Step S102: based on the attribute information of the first entity, obtain a second entity associated with the first entity, and set an initial value of the path association degree of the second entity.
[0062] Specifically, if the first entity is abstracted as a node in the graph database, the attribute information can be considered as the edge information of the node, and the second entity connected to it is obtained based on the edge information. The second entity also belongs to the power grid entity. That is, according to the "attribute" relationship of the first power grid entity, the associated second entity is found. Figure 3 As shown, the second entity associated with the first entity (Henan substation) is a substation entity. At this time, the initial value of the path association degree of the second entity can be set, for example, the initial value of the path association degree of the second entity is set to 100.
[0063] Step S103: simultaneously determining a plurality of groups of path query units in the graph database, each group of path query units including a third entity and a fourth entity that are in communication with each other and adjacent to each other.
[0064] For example, in Figure 3 In the first group of path query units, 1# transformer (asset equipment) is the third entity, model 1, Shandong transformer factory (manufacturer equipment) is the fourth entity, 1# transformer (asset equipment) and model 1, Shandong transformer factory (manufacturer equipment) communicate with each other and are adjacent; similarly, in Figure 3 In the second group of path query units, 2# transformer (asset equipment) is the third entity, model 2, Shandong transformer factory (manufacturer) is the fourth entity, 2# transformer (asset equipment) and model 2, Shandong transformer factory (manufacturer) communicate with each other and are adjacent.
[0065] Furthermore, if Figure 4 As shown, when model 1, Shandong Transformer Factory (manufacturer equipment) is the third entity, then the model 1 manual (product information) is the fourth entity, and the third entity and the fourth entity can constitute the third group of path query units; similarly, when model 2, Shandong Transformer Factory (manufacturer) is the third entity, then the model 2 manual is the fourth entity, and the third entity and the fourth entity can constitute the fourth group of path query units. Figure 4In the graph database, after determining the second entity associated with the first entity, multiple groups of path query units including the third entity and the fourth entity that are in communication and adjacent to each other can be determined simultaneously. Therefore, simultaneously determining multiple groups of path query units in the graph database can improve the query efficiency of the target entity.
[0066] Step S104, when traversing and querying the target entity in the graph database, if there is an inclusion relationship between the third entity and the fourth entity in each group of path query units, and the entity type to which the fourth entity belongs has not been traversed and queried, then the current value of the path relevance of the fourth entity is updated based on the initial value of the path relevance. Once the target entity is queried, the current value of the path relevance of the fourth entity is used as the final value of the path relevance of the target entity.
[0067] Specifically, in Figure 2 In the example, the power grid entity at the starting point of the arrow includes the power grid entity at the ending point of the arrow, and the number on the arrow is the path association value between two adjacent power grid entities. Figure 2 It can be seen that the substation points to the asset equipment, that is, the substation contains the asset equipment; the manufacturer equipment points to the asset equipment, that is, the manufacturer equipment contains the asset equipment; the manufacturer equipment points to the product information, that is, the manufacturer equipment contains the product information; the manufacturer points to the asset equipment, the manufacturer equipment, and the product information respectively, that is, the manufacturer contains the asset equipment, the manufacturer equipment, and the product information.
[0068] Furthermore, when determining that there is a containment relationship between the third entity and the fourth entity, the fourth entity can be regarded as the current entity, and the third entity can be regarded as the previous entity of the current entity, that is, in the graph database, it is determined that the edge between the current entity and the previous entity is an included out-edge. Because the third entity and the fourth entity communicate with each other and are adjacent, if the containment relationship between the two is determined, the purpose of limiting the query scope can be achieved, thereby preventing the query scope of the target entity from being expanded.
[0069] Furthermore, for example, if the fourth entity (model 1, Shandong Transformer Factory) is regarded as the current entity, its entity type is manufacturer equipment, and when the current entity of the entity type is marked to confirm that it has not been traversed and queried during the real-time traversal query process, the query can be continued. By confirming that the fourth entity has not been traversed and queried, it can prevent two entities of the same type from appearing in the same group of path query units, thereby improving the query efficiency of the target entity.
[0070] Exemplarily, if there is an inclusion relationship between the third entity and the fourth entity in each group of path query units, and the entity type to which the fourth entity belongs has not been traversed and queried, when this condition is met, for example, the initial value of the path relevance is set to 5 to update the current value of the path relevance of the fourth entity (current entity) until the target entity is found to obtain the final value of the path relevance of the target entity.
[0071] Specifically, based on the initial value of the path relevance as the current path relevance of the third entity, the minimum value between the preset values of the path relevance of the third entity (previous entity) and the fourth entity (current entity) is taken to update the final value of the path relevance of the target entity.
[0072] Step S105 , based on the final value of the path association degree of the target entity obtained by each group of path query units, all target query paths of the target entity are obtained, and the optimal query path is selected from all the target query paths of the target entity.
[0073] For example, if the business demand to be queried by the user is the relevant product information of Henan Substation, through the above steps S101-S105, based on the simultaneous query of each group of path query units, all target query paths are locked. At this time, the final values of all path associations on the query target entity (product information) are counted, and the optimal query path is selected from all target query paths, and the remaining target query paths are discarded. In order to finally obtain the optimal query path, it is necessary to select the target entity corresponding to the maximum value from the final values of all path associations. For example, Figure 4 In the example, the target entity is the instruction manual in the product data. The final value of the path correlation corresponding to the instruction manual of model 1 is 3, and the final value of the path correlation corresponding to the instruction manual of model 2 is 1. Therefore, the target query path corresponding to the instruction manual of model 1 is retained as the optimal query path, and the target query path corresponding to the instruction manual of model 2 is discarded.
[0074] Step S106: locating the target entity based on the optimal query path.
[0075] Specifically, based on the optimal query path, the target entity can be located at the fastest speed.
[0076] Therefore, the multi-hop path query method in this embodiment simultaneously determines multiple groups of path query units in the graph database, and based on the inclusion relationship and entity type between the third entity and the fourth entity that communicate with each other and are adjacent in each group of path query units, updates the current value of the path association of the fourth entity by the initial value of the path association. When the target entity is queried, the current value of the path association of the fourth entity is used as the final value of the path association of the target entity, and the optimal query path is selected from all target query paths of the target entity to obtain the target entity. This can achieve the goal of narrowing the query scope of the multi-hop path of the target entity based on the graph database, so as to avoid querying the target entity one by one based on the written attribute information in the graph database, thereby achieving the purpose of simplifying the query process and improving query efficiency.
[0077] In this embodiment, a multi-hop path query method is provided, which can be used in mobile terminals, such as mobile phones, tablet computers, etc. In step S104, the current value of the path relevance of the fourth entity is updated based on the initial value of the path relevance. Once the target entity is queried, the current value of the path relevance of the fourth entity is used as the final value of the path relevance of the target entity, such as Figure 5 As shown, the process includes the following steps:
[0078] Step S501: taking the initial value of the path relevance as the current value of the path relevance of the third entity.
[0079] Step S502: obtaining a preset value of the path relevance of the third entity.
[0080] For example, in Figure 3 In the example, if the third entity (1# transformer) and the fourth entity (model 1, Shandong transformer factory) are adjacent to each other and communicate with each other in a set of path query units, the third entity is the previous entity of the fourth entity (current entity), and if the initial value of the path association is 5, the preset value of the path association of the third entity (current entity) is set to 3.
[0081] Step S503, obtaining a preset path direction of the traversal query target entity and an actual path direction between the third entity and the fourth entity.
[0082] Specifically, the preset path direction of the target entity is the direction of querying the target object from the starting point to the end point, and the actual path direction between the third entity and the fourth entity is the direction determined by the inclusion relationship between the two. For example, if the fourth entity contains the third entity, then the actual path direction is the direction from the fourth entity to the third entity.
[0083] Step S504: if the preset path direction is consistent with the actual path direction, a minimum value is selected between the current value of the path relevance of the third entity and the preset value of the path relevance of the third entity.
[0084] Specifically, in Figure 3 In the example, if the fourth entity includes the third entity, the actual path direction between the third entity and the fourth entity is pointed to the left, and the arrow of the preset path direction is also pointed to the left. Then, the minimum value is selected between the current value of the path association degree of the third entity and the preset value of the path association degree, that is, min(5,3)=3.
[0085] Step S505: If the preset path direction is inconsistent with the actual path direction, the preset value of the path association degree is used as the minimum value.
[0086] Specifically, if the fourth entity includes the third entity, the actual path direction between the third entity and the fourth entity has an arrow pointing left, and the arrow of the preset path direction also points right, then the preset value 5 of the path association degree of the third entity is taken as the minimum value.
[0087] Step S506, when the target entity is found through traversal query, the minimum value is used as the current value of the path relevance of the fourth entity; the current value of the path relevance of the fourth entity is the final value of the path relevance of the target entity.
[0088] Specifically, for example, in a group of path query units, the minimum value 5 is used as the current value of the path relevance of the fourth entity, and when the target entity is queried, 5 is used as the final value of the path relevance of the target entity.
[0089] Step S507, when the target entity is not found after traversal query, return to the step of simultaneously determining multiple groups of path query units in the graph database until the target entity is found.
[0090] Specifically, for example, in a group of path query units, the minimum value 5 is used as the current value of the path relevance of the fourth entity. When the target entity is not traversed and queried, the process returns to step S103 of simultaneously determining multiple groups of path query units in the graph database, and the next group of path query units is re-determined. For example, Figure 4 In the above, take 1# transformer as the third entity and model 1, Shandong transformer factory as the fourth entity. According to the above steps S501-S507, when the target entity is not found, redetermine the next group of path query units, and take model 1, Shandong transformer factory as the third entity, model 1 instruction manual as the fourth entity, and model 1 Shandong transformer factory as the third entity to continue to query the target entity, and take the minimum value between the current value of the path association degree of the third entity and the preset value of the path association degree of the third entity, until the target entity is found.
[0091] In some optional implementations, the above step S105, selecting the optimal query path from all target query paths of the target entity, includes:
[0092] Step a1: Select the maximum path relevance final value from all target query paths of the target entity, and use the maximum path relevance final value as the optimal query path of the target entity.
[0093] Specifically, because multiple groups of path query units query the target entity at the same time, multiple target query paths based on the target entity are generated, and the maximum path relevance final value is selected from the multiple target query paths as the optimal query path. Figure 4In the example, the target entity is the instruction manual in the product data. The final value of the path relevance corresponding to the instruction manual of model 1 is 3, and the final value of the path relevance corresponding to the instruction manual of model 2 is 1. Therefore, the target query path corresponding to the instruction manual of model 1 is retained as the optimal query path, and the target query path corresponding to the instruction manual of model 2 is discarded. Through the optimal query path, the target entity can be quickly located.
[0094] In an optional implementation, the multi-hop path query method in this embodiment further includes: when traversing and querying the target entity in the graph database, if there is an inclusion relationship between the third entity and the fourth entity in each group of path query units, and other entities of the same entity type as the fourth entity have not been traversed and queried, then the current value of the path association of the fourth entity is updated based on the initial value of the path association, and if the target entity is not queried, return to step S103 of simultaneously determining multiple groups of path query units in the graph database until the target entity is queried.
[0095] Specifically, if the target entity is not found in the current group path query unit, return to step S103, loop through the query for the target entity in the graph database, and finally locate the target entity in the multi-hop path of the graph database with the fastest speed, smallest query scope, and simplest query process.
[0096] In this embodiment, a multi-hop path query method is provided, which can be used in mobile terminals, such as mobile phones, tablet computers, etc. Figure 6 As shown, it also includes:
[0097] Step S1041, when traversing the query target entity in the graph database, if there is no inclusion relationship between the third entity and the fourth entity in each group of path query units, return to the step of simultaneously determining multiple groups of path query units in the graph database to redetermine the query path.
[0098] Specifically, if there is no inclusion relationship between the third entity and the fourth entity in each group of path query units, it means that the third entity and the fourth entity are not highly correlated, and further querying the target entity based on the two entities with low correlation will increase the query scope of the target entity. Therefore, in order to improve the query efficiency of the target entity and reduce the query scope, if there is no inclusion relationship between the third entity and the fourth entity in each group of path query units, the path query unit can be directly discarded, and the step of simultaneously determining multiple groups of path query units in the graph database is returned to redetermine the query path.
[0099] In this embodiment, a multi-hop path query method is provided, which can be used in mobile terminals, such as mobile phones, tablet computers, etc. Figure 6 Also included:
[0100] Step S1042, when traversing and querying the target entity in the graph database, if there is an inclusion relationship between the third entity and the fourth entity in each group of path query units, and other entities of the same entity type as the fourth entity have been traversed and queried, then return to the step of simultaneously determining multiple groups of path query units in the graph database to redetermine the query path.
[0101] Specifically, if there is no inclusion relationship between the third entity and the fourth entity in each group of path query units, but the entity type of the fourth entity is found to have been traversed and queried during the real-time marking process, in order to avoid repeated queries, the group of path query units can still be discarded, and the steps of simultaneously determining multiple groups of path query units in the graph database can be used to redetermine the query path, so as to achieve the purpose of quickly querying the target entity and avoiding expanding the query scope.
[0102] In this embodiment, a multi-hop path query device is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and will not be repeated here. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, it is also possible and conceivable to implement it in hardware, or in a combination of software and hardware. Figure 7 As shown, the device comprises:
[0103] The key information acquisition module 71 is used to query the key information of the target entity based on the user input, and acquire the first entity matching the key information.
[0104] The associated entity acquisition module 72 is used to acquire a second entity associated with the first entity based on the attribute information of the first entity, and set an initial value of the path association degree of the second entity.
[0105] The query unit selection module 73 is used to simultaneously determine multiple groups of path query units in the graph database, each group of path query units includes a third entity and a fourth entity that communicate with each other and are adjacent.
[0106] The target entity query module 74 is used to traverse and query the target entity in the graph database. If there is an inclusion relationship between the third entity and the fourth entity in each group of path query units, and the entity type to which the fourth entity belongs has not been traversed and queried, then the current value of the path association of the fourth entity is updated based on the initial value of the path association. Once the target entity is queried, the current value of the path association of the fourth entity is used as the final value of the path association of the target entity.
[0107] The optimal path selection module 75 is used to obtain all target query paths of the target entity based on the final value of the path association degree of the target entity obtained by each group of path query units, and select the optimal query path from all target query paths of the target entity.
[0108] The target entity positioning module 76 is used to locate the target entity based on the optimal query path.
[0109] In an optional implementation manner, the multi-hop path query device in this embodiment further includes:
[0110] The first loop query module is used to traverse and query the target entity in the graph database. If there is an inclusion relationship between the third entity and the fourth entity in each group of path query units, and other entities of the same entity type as the fourth entity have not been traversed and queried, then the current value of the path association of the fourth entity is updated based on the initial value of the path association. If the target entity is not queried, return to the step of simultaneously determining multiple groups of path query units in the graph database until the target entity is queried.
[0111] In an optional implementation, the target entity query module 74 includes:
[0112] A first path relevance value acquisition submodule, configured to use the path relevance initial value as the path relevance current value of the third entity;
[0113] A second path relevance value acquisition submodule, used to acquire a preset path relevance value of a third entity;
[0114] A target entity query direction acquisition submodule is used to acquire a preset path direction for traversing the query target entity and an actual path direction between the third entity and the fourth entity;
[0115] A third path association value acquisition submodule, configured to select a minimum value between a current value of the path association of the third entity and a preset value of the path association of the third entity if the preset path direction is consistent with the actual path direction;
[0116] A fourth path relevance value acquisition submodule is used to set the path relevance value of the third entity to a minimum value if the preset path direction is inconsistent with the actual path direction;
[0117] The path relevance final value determination submodule is used to, when the target entity is traversed and queried, use the minimum value as the path relevance current value of the fourth entity; the path relevance current value of the fourth entity is the path relevance final value of the target entity;
[0118] The target entity loop query submodule is used to return to the step of simultaneously determining multiple groups of path query units in the graph database when the target entity is not traversed and queried, until the target entity is queried and completed.
[0119] In an optional implementation, the optimal path selection module 75 includes:
[0120] The optimal path determination submodule is used to select the maximum path relevance final value from all target query paths of the target entity, and use the maximum path relevance final value as the optimal query path of the target entity.
[0121] In an optional embodiment, the second loop query module also includes: when traversing the query target entity in the graph database, if there is no inclusion relationship between the third entity and the fourth entity in each group of path query units, returning to the step of simultaneously determining multiple groups of path query units in the graph database to redetermine the query path.
[0122] In an optional embodiment, the third loop query module also includes: when traversing the query target entity in the graph database, if there is an inclusion relationship between the third entity and the fourth entity in each group of path query units, and the entity type of the fourth entity has been traversed and queried, then return to the step of simultaneously determining multiple groups of path query units in the graph database to redetermine the query path.
[0123] In an optional implementation, the target entity, the first entity, the second entity, the third entity, and the fourth entity are all power grid entities, and entity types of the power grid entities include: substation, manufacturer equipment, asset equipment, manufacturer, and product information.
[0124] In an optional implementation, the substation includes manufacturer equipment; the manufacturer equipment includes asset equipment and product information; the manufacturer includes product information.
[0125] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.
[0126] The multi-hop path query device in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.
[0127] An embodiment of the present invention further provides a computer device having the multi-hop path query device.
[0128] See also Figure 8 , Figure 8 is a schematic diagram of the structure of a computer device provided by an optional embodiment of the present invention, such as Figure 8As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 8 A processor 10 is taken as an example.
[0129] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.
[0130] The memory 20 stores instructions executable by at least one processor 10, so that the at least one processor 10 executes the method shown in the above embodiment.
[0131] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0132] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.
[0133] The computer device further comprises a communication interface 30 for the computer device to communicate with other devices or a communication network.
[0134] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.
[0135] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.
Claims
1. A multi-hop path query method, characterized in that: The method comprises: Query key information of a target entity based on user input, and obtain a first entity matching the key information; Based on the attribute information of the first entity, acquiring a second entity associated with the first entity, and setting an initial value of the path association degree of the second entity; Simultaneously determining a plurality of groups of path query units in the graph database, each group of path query units including a third entity and a fourth entity that are in communication with each other and adjacent to each other; When traversing and querying the target entity in the graph database, if there is an inclusion relationship between the third entity and the fourth entity in each group of path query units, and the entity type to which the fourth entity belongs has not been traversed and queried, then the current value of the path relevance of the fourth entity is updated based on the initial value of the path relevance, and once the target entity is queried, the current value of the path relevance of the fourth entity is used as the final value of the path relevance of the target entity; Based on the final value of the path association degree of the target entity obtained by each group of path query units, all target query paths of the target entity are acquired, and the optimal query path is selected from all target query paths of the target entity; Based on the optimal query path, locating the target entity; The method of updating the current value of the path relevance of the fourth entity based on the initial value of the path relevance and taking the current value of the path relevance of the fourth entity as the final value of the path relevance of the target entity once the target entity is found includes: Using the initial value of the path relevance as the current value of the path relevance of the third entity; Obtaining a preset value of the path relevance of the third entity; Obtaining a preset path direction of the target entity for traversal query and an actual path direction between the third entity and the fourth entity; If the preset path direction is consistent with the actual path direction, selecting a minimum value between the current value of the path relevance of the third entity and the preset value of the path relevance of the third entity; If the preset path direction is inconsistent with the actual path direction, the path association degree of the third entity is preset to a minimum value; When the target entity is found through traversal query, the minimum value is used as the current value of the path relevance of the fourth entity; the current value of the path relevance of the fourth entity is the final value of the path relevance of the target entity; When the target entity is not found through traversal query, the process returns to the step of simultaneously determining multiple groups of path query units in the graph database until the target entity is found.
2. The method according to claim 1, characterized in that Also includes: When traversing and querying the target entity in the graph database, if there is an inclusion relationship between the third entity and the fourth entity in each group of path query units, and other entities of the same entity type as the fourth entity have not been traversed and queried, the current value of the path association of the fourth entity is updated based on the initial value of the path association, and if the target entity is not queried, the step of simultaneously determining multiple groups of path query units in the graph database is returned until the target entity is queried and ended.
3. The method according to claim 1, characterized in that Selecting an optimal query path from all target query paths of the target entity includes: A maximum final path relevance value is selected from all target query paths of the target entity, and the maximum final path relevance value is used as the optimal query path of the target entity.
4. The method according to claim 1, characterized in that Also includes: When traversing the query target entity in the graph database, if there is no inclusion relationship between the third entity and the fourth entity in each group of path query units, return to the step of simultaneously determining multiple groups of path query units in the graph database to redetermine the query path.
5. The method according to claim 1, characterized in that Also includes: When traversing and querying the target entity in the graph database, if there is an inclusion relationship between the third entity and the fourth entity in each group of path query units, and the entity type of the fourth entity has been traversed and queried, then return to the step of simultaneously determining multiple groups of path query units in the graph database to redetermine the query path.
6. The method according to any one of claims 1 to 5, characterized in that The target entity, the first entity, the second entity, the third entity, and the fourth entity are all power grid entities, and entity types of the power grid entities include: substation, manufacturer equipment, asset equipment, manufacturer, and product information.
7. The method according to claim 6, characterized in that The substation includes manufacturer equipment; the manufacturer equipment includes asset equipment and product information; the manufacturer includes product information.
8. A multi-hop path query device, characterized in that: The device comprises: A key information acquisition module, used to query the key information of the target entity based on user input, and acquire a first entity matching the key information; An associated entity acquisition module, configured to acquire a second entity associated with the first entity based on the attribute information of the first entity, and set an initial value of the path association degree of the second entity; A query unit selection module, used to simultaneously determine multiple groups of path query units in the graph database, each group of path query units including a third entity and a fourth entity that communicate with each other and are adjacent; a target entity query module, configured to update the current value of the path relevance of the fourth entity based on the initial value of the path relevance when traversing and querying the target entity in the graph database, if there is an inclusion relationship between the third entity and the fourth entity in each group of path query units, and the entity type to which the fourth entity belongs has not been traversed and queried, and once the target entity is queried, use the current value of the path relevance of the fourth entity as the final value of the path relevance of the target entity; An optimal path selection module, used to obtain all target query paths of the target entity based on the final value of the path association degree of the target entity obtained by each group of path query units, and select an optimal query path from all target query paths of the target entity; A target entity positioning module, used for positioning the target entity based on the optimal query path; Target entity query module, including: A first path relevance value acquisition submodule, configured to use the path relevance initial value as the path relevance current value of the third entity; A second path relevance value acquisition submodule, used to acquire a path relevance preset value of a third entity; A target entity query direction acquisition submodule is used to acquire a preset path direction for traversing the query target entity and an actual path direction between the third entity and the fourth entity; A third path association value acquisition submodule, configured to select a minimum value between a current value of the path association of the third entity and a preset value of the path association of the third entity if the preset path direction is consistent with the actual path direction; A fourth path relevance value acquisition submodule is used to set the path relevance value of the third entity to a minimum value if the preset path direction is inconsistent with the actual path direction; The path relevance final value determination submodule is used to, when the target entity is traversed and queried, use the minimum value as the path relevance current value of the fourth entity; the path relevance current value of the fourth entity is the path relevance final value of the target entity; The target entity loop query submodule is used to return to the step of simultaneously determining multiple groups of path query units in the graph database when the target entity is not traversed and queried, until the target entity is queried and completed.
9. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the multi-hop path query method according to any one of claims 1 to 7 by executing the computer instructions.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the multi-hop path query method according to any one of claims 1 to 7.
Citation Information
Cited By
Quick retrieval method and system for multi-hop relationship of data warehouse based on graph embedded index
CN120723757A
Method and system for fast retrieval of multi-hop relationships in data warehouse based on graph embedding index
CN120723757B
