A knowledge graph path retrieval method and system
The method optimizes knowledge graph path queries by using PageRank-based PR values to identify and avoid low-value nodes and relationships, enhancing query efficiency and reducing complexity.
Patent Information
- Application Number
- CN202110997869.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-27
- Publication Date
- 2024-12-24
- Estimated Expiration
- 2041-08-27
AI Technical Summary
Existing knowledge graph path queries face challenges such as uncontrolled large nodes, inability to systematically avoid large nodes, and lack of mechanisms to discover and skip low-value node and relationship combinations, leading to increased server pressure and query timeouts.
A method and system that utilize the PageRank algorithm to calculate unweighted and weighted PR values, screen out low-value nodes and relationships, and determine query direction based on bidirectional PR values to optimize path queries, reducing data traversal and improving query efficiency.
The method effectively reduces data traversal and query complexity by identifying and avoiding low-value nodes and relationships, ensuring query results meet preset rules and enhance query performance.
Smart Images

Figure CN114003727B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technologies, and in particular to a knowledge graph path retrieval method and system thereof. Background Art
[0002] Knowledge graphs usually organize and manage data in a graph model. In actual application scenarios, querying the path between two nodes is an important query mode. For example, the relationship between two people and the organizational structure of an organization can be attributed to this scenario.
[0003] However, path query usually has performance risks, that is, the selection of some query details will have a great impact on query performance, such as the selection of query direction, large nodes along the way, etc. If not handled properly, it is easy to cause large-scale data traversal, thereby increasing the pressure on the server and causing query timeouts.
[0004] In order to avoid these problems, some customized logic is usually added in the existing technology. For example, the direction is specified when querying, and the query direction is decided by the business layer. Once the business layer is negligent or used improperly, it is easy to affect the system; large nodes are one of the most difficult problems in the graph. Usually, query conditions are manually tuned to avoid these nodes during query. However, the timing of the generation of large nodes is not controllable and may appear after query tuning, which will affect the stability of the system.
[0005] The path query in the above prior art may have the following problems:
[0006] (1) When searching for a path, the system cannot select the query direction to reduce the amount of data to be traversed
[0007] (2) Unable to systematically avoid large nodes in the query path
[0008] (3) There is no mechanism to discover low-value node and relationship combinations (e.g., Han Chinese as nodes and ethnic groups as relationships) and skip them in queries. Summary of the invention
[0009] In view of the above-mentioned problems existing in the prior art, a knowledge graph path retrieval method and system are provided.
[0010] The specific technical solutions are as follows:
[0011] A method for retrieving a knowledge graph path, comprising the following steps:
[0012] Step S1, obtaining a knowledge graph, the knowledge graph includes multiple nodes, calculating the unweighted PR value group of each node through the pagerank algorithm, the unweighted PR value group includes an unweighted forward PR value, an unweighted reverse PR value and an unweighted bidirectional PR value, and calculating the weighted bidirectional PR value according to the unweighted bidirectional PR value of the node;
[0013] Step S2, screening the nodes according to the unweighted PR value group of each node to screen out low-value nodes, and obtaining low-value node relationships, the low-value node relationships including node relationships corresponding to the low-value nodes;
[0014] Step S3, obtaining a query request from a user, the query request including first query data, second query data and query conditions, determining a query direction according to a bidirectional PR value of a node corresponding to the first query data and a node corresponding to the second query data, filtering a path in the knowledge graph that includes the low-value node and / or the low-value node relationship according to the query condition and in combination with the query direction, so as to obtain a path between the first query data and the second query data, forming a first path set, wherein the first path includes a plurality of nodes, and there is a node relationship between every two adjacent nodes;
[0015] Step S4, calculating the weighted harmonic mean of the paths according to the query condition and the bidirectional PR value of each node in the paths in the first path set, screening the paths that meet the preset rules in the first path set according to the weighted harmonic mean of the paths as the query paths, and feeding back the query paths to the user;
[0016] The two-way PR value is an unweighted two-way PR value or a weighted two-way PR value.
[0017] Preferably, in the knowledge graph path retrieval method, the low-value nodes screened out in step S2 specifically include:
[0018] Nodes with positive PR values exceeding a preset positive PR threshold are considered low-value nodes; and / or
[0019] Nodes whose reverse PR values exceed a preset reverse PR threshold are considered low-value nodes; and / or
[0020] Nodes whose bidirectional PR values exceed the preset bidirectional PR threshold are regarded as low-value nodes.
[0021] Preferably, the retrieval method of the knowledge graph path, wherein the screening in step S2 to obtain low-value nodes, specifically includes:
[0022] The absolute value of the difference between the forward PR value and the reverse PR value of the node is calculated, and the nodes whose absolute values exceed the preset absolute value threshold are regarded as low-value nodes.
[0023] Preferably, in the knowledge graph path retrieval method, the step S1 of obtaining the weighted bidirectional PR value specifically includes:
[0024] The bidirectional PR values of the nodes are weighted and summed according to a preset weight algorithm to obtain a weighted sum of the nodes;
[0025] And according to the weighted sum, the weighted bidirectional PR value corresponding to the node is calculated through the pagerank algorithm.
[0026] Preferably, the knowledge graph path retrieval method, wherein the low-value node relationship is obtained in step S2, specifically includes:
[0027] Obtain the node relationships associated with low-value nodes;
[0028] And the node relationships associated with the low-value nodes are sorted according to the number of occurrences, so as to set a preset number of sorted node relationships as low-value node relationships.
[0029] Preferably, in the knowledge graph path retrieval method, the query condition in step S4 includes: a query termination condition and a query method;
[0030] Among them, the query termination conditions include: end node or maximum hop count;
[0031] The node relationship of the paths in the first path set is less than or equal to the maximum hop count.
[0032] Preferably, the retrieval method of the knowledge graph path, wherein the query direction is determined in step S3, specifically comprises the following steps:
[0033] Get the query mode in the query condition. When the query mode is full path mode:
[0034] Analyze the first query data to obtain a first node of the first query data, obtain an unweighted bidirectional PR value of the first node and an unweighted bidirectional PR value of at least one adjacent node to the first node, and sum the unweighted bidirectional PR value of the first node and the unweighted bidirectional PR value of at least one adjacent node to the first node to obtain a first sum value;
[0035] Analyze the second query data to obtain a second node of the second query data, obtain an unweighted bidirectional PR value of the second node and an unweighted bidirectional PR value of at least one adjacent node to the second node, and sum the unweighted bidirectional PR value of the second node and the unweighted bidirectional PR value of at least one adjacent node to the second node to obtain a second summed value;
[0036] Determine whether the first sum value is greater than the second sum value;
[0037] If so, take the second node as the starting node;
[0038] If not, take the first node as the starting node.
[0039] Preferably, the retrieval method of the knowledge graph path, wherein the query direction is determined in step S3, specifically comprises the following steps:
[0040] Get the query mode in the query condition. When the query mode is the key path mode:
[0041] Analyze the first query data to obtain a first node of the first query data, obtain a weighted bidirectional PR value of the first node and a weighted bidirectional PR value of at least one adjacent node to the first node, and sum the weighted bidirectional PR value of the first node and the weighted bidirectional PR value of at least one adjacent node to the first node to obtain a third summed value;
[0042] Analyze the second query data to obtain a second node of the second query data, obtain a weighted bidirectional PR value of the second node and a weighted bidirectional PR value of at least one adjacent node to the second node, and sum the weighted bidirectional PR value of the second node and the weighted bidirectional PR value of at least one adjacent node to the second node to obtain a fourth summed value;
[0043] Determine whether the third sum value is greater than the fourth sum value;
[0044] If so, take the second node as the starting node;
[0045] If not, take the first node as the starting node.
[0046] Also included is a knowledge graph path retrieval method, which includes the following steps:
[0047] Step A1, obtaining a knowledge graph, the knowledge graph includes multiple nodes, and calculating the unweighted PR value group of each node through the pagerank algorithm, the unweighted PR value group includes an unweighted forward PR value, an unweighted reverse PR value and an unweighted bidirectional PR value;
[0048] Step A2, obtaining a query request from a user, the query request including first query data, second query data and query conditions, determining a query direction according to the query conditions combined with an unweighted bidirectional PR value of a node corresponding to the first query data and a node corresponding to the second query data, so as to obtain a path between the first query data and the second query data in the knowledge graph according to the query conditions and combined with the query direction, forming a second path set, wherein the first path includes a plurality of nodes, and there is a node relationship between every two adjacent nodes;
[0049] Step A3, calculating the weighted harmonic mean of the path according to the unweighted bidirectional PR value of each node in the path in the second path set, screening the path that meets the preset rules in the second path set according to the weighted harmonic mean of the path as the query path, and feeding back the query path to the user.
[0050] It also includes a knowledge graph path retrieval system, which specifically includes:
[0051] The calculation module obtains the knowledge graph, which includes multiple nodes. The unweighted PR value group of each node is calculated by the pagerank algorithm. The unweighted PR value group includes an unweighted forward PR value, an unweighted reverse PR value, and an unweighted bidirectional PR value. The weighted bidirectional PR value is calculated based on the unweighted bidirectional PR value of the node.
[0052] A screening module screens nodes according to the unweighted forward PR value and the unweighted reverse PR value of each node to screen out low-value nodes, and obtain low-value node relationships, wherein the low-value node relationships include node relationships corresponding to the low-value nodes;
[0053] A query module, which obtains a query request from a user, wherein the query request includes first query data, second query data, and a query condition, and determines a query direction according to a bidirectional PR value of a node corresponding to the first query data and a node corresponding to the second query data, so as to filter the paths in the knowledge graph that include the low-value nodes and / or the low-value node relationships according to the query condition and in combination with the query direction, so as to obtain a path between the first query data and the second query data, and form a first path set, wherein the first path includes a plurality of nodes, and there is a node relationship between every two adjacent nodes;
[0054] A feedback module calculates the weighted harmonic mean of the path according to the query condition and the bidirectional PR value of each node in the path in the first path set, selects the path that meets the preset rules in the first path set according to the weighted harmonic mean of the path as the query path, and feeds back the query path to the user;
[0055] The two-way PR value is an unweighted two-way PR value or a weighted two-way PR value.
[0056] The above technical solution has the following advantages or beneficial effects:
[0057] First, the knowledge graph is combined with the PageRank algorithm. Since the node relationships in the knowledge graph have weights, after calculating the unweighted PR value group of each node, the weighted PR value calculation is introduced. That is, the weight of each node relationship is additionally considered during the calculation, so as to more objectively reflect the arrival rate of each node in the path query scenario.
[0058] Second, in path query, the query direction can be determined according to the bidirectional PR value to reduce the scale of data traversal.
[0059] Third, by analyzing the forward and reverse unweighted PR values, low-value node & relationship combinations can be screened out, so that low-value node & relationship combinations can be avoided in path queries, which can effectively reduce the impact of large nodes.
[0060] Fourth, relationship weights are introduced into the path query results to obtain a query path that complies with preset rules, making the query results more valuable for reference. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] The embodiments of the present invention will be described more fully with reference to the attached drawings, which are provided for illustration and description only and are not intended to limit the scope of the present invention.
[0062] Figure 1 This is a flowchart of the first embodiment of the method for retrieving a knowledge graph path of the present invention;
[0063] Figure 2 A schematic diagram of a knowledge graph of Embodiment 1 of the method for searching a knowledge graph path of the present invention;
[0064] Figure 3 This is a flowchart of Example 2 of the knowledge graph path retrieval method of the present invention. DETAILED DESCRIPTION
[0065] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only 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 ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0066] It should be noted that, in the absence of conflict, the embodiments of the present invention and the features in the embodiments may be combined with each other.
[0067] The present invention will be further described below in conjunction with the accompanying drawings and specific embodiments, but they are not intended to limit the present invention.
[0068] The present invention comprises:
[0069] Embodiment 1;
[0070] When the user specifies to execute the key path query mode or the user does not specify the path query mode, low-value nodes and low-value node relationships need to be filtered;
[0071] At this time, a method for retrieving a knowledge graph path includes the following steps:
[0072] Step S1, obtaining a knowledge graph, the knowledge graph includes multiple nodes, calculating the unweighted PR value group of each node through the pagerank algorithm, the unweighted PR value group includes an unweighted forward PR value, an unweighted reverse PR value and an unweighted bidirectional PR value, and calculating the weighted bidirectional PR value according to the unweighted bidirectional PR value of the node;
[0073] Step S2, screening the nodes according to the unweighted PR value group of each node to screen out low-value nodes, and obtaining low-value node relationships, the low-value node relationships including node relationships corresponding to the low-value nodes;
[0074] Step S3, such as Figure 1 As shown, a query request of a user is obtained, the query request includes first query data, second query data and query conditions, and a query direction is determined according to a bidirectional PR value of a node corresponding to the first query data and a node corresponding to the second query data, so as to filter the paths containing the low-value nodes and / or the low-value node relationships in the knowledge graph according to the query conditions and in combination with the query direction, so as to obtain a path between the first query data and the second query data, and form a first path set, wherein the paths in the first path set include a plurality of nodes, and there is a node relationship between every two adjacent nodes, such as Figure 2 As shown, the node relationships between the head office node and the nodes adjacent to the head office are all subordinate relationships;
[0075] Step S4, calculating the weighted harmonic mean of the paths according to the query condition and the bidirectional PR value of each node in the paths in the first path set, screening the paths that meet the preset rules in the first path set according to the weighted harmonic mean of the paths as the query paths, and feeding back the query paths to the user;
[0076] The two-way PR value is an unweighted two-way PR value or a weighted two-way PR value.
[0077] In the above embodiment, unlike the PageRank calculation logic in the prior art, the path query of the knowledge graph does not have the probability problem of random click behavior, so the damping factor (where the damping factor represents the probability that the user continues to click on the links in each web page) and the direct transfer probability (the direct transfer probability represents the probability that the user directly visits a web page) are not considered here.
[0078] In the above embodiment, the knowledge graph and PageRank algorithm are combined. Since the node relationships in the knowledge graph have weights, the calculation of weighted PR values can be introduced after calculating the unweighted PR value group of each node. That is, the weight of the node relationship is additionally considered in the calculation of each node relationship, so as to more objectively reflect the arrival rate of each node in the path query scenario.
[0079] In the above embodiment, in the path query, the query direction may be determined according to the bidirectional PR value to reduce the scale of data traversal.
[0080] In the above embodiment, low-value node & relationship combinations are screened out by analyzing the forward and reverse unweighted PR values, thereby avoiding low-value node & relationship combinations in path queries and effectively reducing the impact of large nodes.
[0081] In the above embodiment, the relationship weight is introduced into the path query result to obtain a query path that meets the preset rules, so that the query result is more in line with the needs of the user, that is, the query result has more reference value.
[0082] In the above embodiment, the first query data may be the entity ID of the entity to be queried or the entity to be queried. Similarly, the second query data may be the entity ID of the entity to be queried or the entity to be queried.
[0083] It should be noted that the above steps are not necessarily executed in sequence.
[0084] In the above embodiment, the knowledge graph is a graph-like knowledge collection with associations, that is, the knowledge graph usually organizes data using a graph data structure, which is very similar to the structure of outbound / inbound links of a web page. The most representative algorithm in web page ranking analysis is the PageRank algorithm, and the PR value obtained by it is essentially the reach of each web page. The algorithm is widely cited in the search field and has influenced many other fields, such as the TextRank algorithm in text analysis (used to generate keywords and summaries for texts).
[0085] How to introduce the idea of PageRank into the knowledge graph and the concept of PR value into the analysis of the graph has high application value. The difference between the knowledge graph and PageRank is:
[0086] 1) The path search of the knowledge graph is not one-way;
[0087] Among them, one-way can be understood as: A's outbound link includes B (B's outbound link does not include A), only the link from A to B needs to be considered, and the jump from B to A does not need to be considered;
[0088] The graph is different. For example, if the father of A is B, the query can go to the B node when it passes through the A node, and vice versa. The query must also be able to go to the A node when it passes through the B node.
[0089] 2) In the PageRank algorithm, the probability of each web page jumping to other outbound links is equal (the mean method is used to calculate the probability), while in graph analysis, relationships have weights, and different relationships have different values in path queries.
[0090] Therefore, considering that the path query of the knowledge graph is usually bidirectional in terms of direction selection; at the same time, in order to find abnormal nodes, it is necessary to analyze the forward PR and reverse PR values of each node. Generally speaking, for nodes with forward PR much larger or smaller than reverse PR, there is a high probability that there are low-value node relationship combinations, such as XX as nationality (a large number of nodes will point to XX, but the number of other nodes pointed to by XX as a source node will not be too large, which is reflected in the unweighted PR value that the forward PR is much larger than the reverse PR). It can be seen that in order to achieve the purpose of path query optimization, it is necessary to analyze the PR values of three dimensions (forward PR value - only consider outgoing, reverse PR value - only consider incoming, and bidirectional PR value). For each node, the difference between the three is the range of Mpi in formula (1) and the choice of relationship direction.
[0091] The calculation logic of the single PR value of the node in step S1 specifically includes the following steps:
[0092] First, the unweighted PR value group of the nodes of the knowledge graph is calculated, where the PR value calculation formula of the node is shown in the following formula (1):
[0093]
[0094] in, Used to represent the set of nodes included in the calculation;
[0095] When calculating the forward PR value of a node i, is the set of all nodes pointing to the node i;
[0096] When calculating the reverse PR value of a node i, is the set of all other nodes pointed to by the node i;
[0097] When calculating the bidirectional PR value of a node i, Contains the set of all nodes that have bidirectional connections with the node i, where bidirectional means that there are both forward and reverse connections at the same time;
[0098] P i Used to indicate the node whose PR value is to be sought;
[0099] P j Used to represent M pi The nodes being traversed in
[0100] L(p j ) is used to represent l(p i , p j ), where l(p i , p j ) is used to represent the probability of node j transferring to node i;
[0101] PR(p i ) is used to represent p i PR value of the node;
[0102] PR(pj) is used to represent p j The PR value of the node.
[0103] Next, multiple rounds of iterations are performed on the PageRank solution, where the calculation logic of each round of state transition is shown in the following formula (2):
[0104]
[0105] In the above formula (2), l(p i , p j ) is used to represent the probability of node j transferring to node i. The sum of the probabilities of transferring from node j to other nodes is 1, which is reflected in the state transfer matrix as the sum of each column is 1, that is, in, R is the feature vector used to represent the PR value.
[0106] In the unweighted PR calculation logic, there is no difference in the various relationships, so the average calculation method is adopted. For example, when calculating the positive PR value, node A has three outgoing edges pointing to B, C, and D respectively, then the corresponding probability value l(p B , p A ), l(p C , p A ), l(p D , p A ) are both 1 / 3;
[0107] Unlike PageRank, where only the relationship between two links needs to be considered whether there is a jump, there may be multiple relationships between two nodes in the knowledge graph. Here, the relationship affected is l(p i , p j ) calculation logic, when there are multiple relationships between two nodes, the value here is the accumulation of multiple relationship jump probabilities;
[0108] In PageRank, the initial value of R has no effect on the convergence of R, so the initial PR value of each node is set to 1 / N, where N is the number of all nodes.
[0109] Finally, after multiple rounds of iterations, the calculation converges to obtain the final PR value.
[0110] Furthermore, in the above embodiment, in order to find abnormal nodes, it is necessary to analyze the forward PR and reverse PR values of each node. Therefore, there are several ways to screen out low-value nodes in step S2:
[0111] The first one is to regard nodes whose positive PR value exceeds the preset positive PR threshold as low-value nodes.
[0112] The second method is to regard nodes whose reverse PR values exceed the preset reverse PR threshold as low-value nodes.
[0113] The third method is to regard nodes whose bidirectional PR values exceed the preset bidirectional PR threshold as low-value nodes.
[0114] Fourthly, the absolute value of the difference between the forward PR value and the reverse PR value of the node is calculated, and the node whose absolute value exceeds the preset absolute value threshold is regarded as a low-value node.
[0115] For example, the difference between the forward PR value and the reverse PR value of the low-value node exceeds the preset absolute value threshold, that is, the forward PR value of the low-value node at this time is much greater than the reverse PR value;
[0116] For example, the difference between the reverse PR value and the forward PR value of the low-value node exceeds a preset absolute value threshold, that is, the reverse PR value at this time is much greater than the forward PR value.
[0117] It should be noted that for low-value nodes and the relationship points corresponding to low-value nodes, you can regularly check and confirm whether they are low-value nodes or low-value node relationships, and maintain low-value node & relationship combinations, which can be used to reduce the weight when calculating the weighted PR value, and skip it in the path query.
[0118] Among them, the above four methods of screening and obtaining low-value nodes can be freely combined.
[0119] For example, the nodes obtained in the first, second and third types may all be regarded as low-value nodes.
[0120] Further, in the above embodiment, obtaining the weighted bidirectional PR value in step S1 specifically includes:
[0121] The bidirectional PR values of the nodes are weighted and summed according to a preset weight algorithm to obtain a weighted sum of the nodes;
[0122] And according to the weighted sum, the weighted bidirectional PR value corresponding to the node is calculated through the pagerank algorithm.
[0123] In the above embodiment, the weighted sum of the nodes can be calculated by the following formula (3):
[0124]
[0125] In the above formula (3), r(p i , p j ) is used to represent the weighted sum of node i;
[0126] P i Used to indicate the node whose PR value is to be sought;
[0127] P j Used to represent M pi The nodes being traversed in
[0128] K is used to represent the node relationship number between node i and node j;
[0129] M is used to represent the number of node relationships between node i and node j;
[0130] weight(p i , p j , k) represents the kth relationship between node i and node j;
[0131] Furthermore, in the above embodiment, the weighted bidirectional PR value of the node is calculated by the following formula (4):
[0132]
[0133] In the above formula (4), l(p i , p j ) is used to represent the probability of node j transferring to node i;
[0134] P i Used to indicate the node whose PR value is to be sought;
[0135] P j Used to represent M pi The nodes being traversed in
[0136] It is used to represent the set of all nodes that have a bidirectional relationship with the node j, where bidirectional means that there is a forward relationship and a reverse relationship at the same time;
[0137] r(p i , p j ) is used to represent the weighted sum from node i to node j;
[0138] r(p k , p j ) is used to represent the weighted sum from node k to node j;
[0139] p k Used to represent the nodes traversed during the weighted summation process;
[0140] and, N is used to represent and p i The number of nodes with relationships.
[0141] Furthermore, in the above embodiment, the acquisition of low-value node relationships in step S2 specifically includes:
[0142] Obtain the node relationships associated with low-value nodes;
[0143] And the node relationships associated with the low-value nodes are sorted according to the number of occurrences, so as to set a preset number of sorted node relationships as low-value node relationships.
[0144] In the above embodiment, the preset number can be set customarily;
[0145] For example, the preset number can be set to 10. At this time, the number of occurrences of the node relationships involved in these low-value nodes is counted, and they are sorted in descending order according to the counted number, and the top 10 node relationships are taken as low-value node relationships.
[0146] Furthermore, in the above embodiment, after step S2, the following steps are further included:
[0147] Set filter labels for low-value nodes and low-value node relationships.
[0148] In the above embodiment, low-value nodes and low-value node relationships provided with filtering tags may be filtered to obtain a first path set.
[0149] As a preferred implementation, low-value nodes and low-value node relationships provided with filtering tags may be directly filtered during the query process to directly obtain the first path set.
[0150] As a preferred implementation, a path set can be first obtained based on the query conditions and combined with the query direction, and then the paths in the above path set that contain the low-value nodes and / or the low-value node relationships can be filtered to obtain the path between the first query data and the second query data to form a first path set.
[0151] In the above embodiment, by setting filtering tags for low-value nodes and low-value node relationships, the load problem of blacklist query in the prior art is avoided, so as to further reduce the complexity of the query and thus improve the query efficiency.
[0152] Further, in the above embodiment, the query conditions in step S4 include: query termination conditions and query methods;
[0153] Among them, the query termination conditions include: end node or maximum hop count;
[0154] The node relationship of the paths in the first path set is less than or equal to the maximum hop count.
[0155] In the above embodiment, when the node relationship between the start node and the end node is less than or equal to the maximum hop count, the query termination condition may be reaching the end node;
[0156] When the node relationship between the start node and the end node is greater than the maximum number of hops, the query termination condition is that the maximum number of hops is reached.
[0157] In the above embodiment, the complexity of the path query is strongly correlated with the maximum number of hops, so the complexity of the path query can be limited by setting the maximum number of hops to improve the query efficiency.
[0158] In the above embodiment, the query mode includes one-way query and two-way query.
[0159] Among them, one-way query refers to the path query from the starting node to the ending node. For example, the starting node is node A and the ending node is node D. At this time, the query direction is: node A→node B→node C→node D;
[0160] A bidirectional query means that there are two directions in the path from the starting node to the ending node at the same time. For example, the starting node is node A and the ending node is node D. The query direction at this time can be: node A→node B←node C→node D.
[0161] As a preferred implementation, the maximum number of hops can be customized, for example, the maximum number of hops can be set to 5.
[0162] Further, an example is given to explain why the query direction should be obtained;
[0163] like Figure 2 As shown, when the first keyword in the query data is associated with a certain A1 city branch node, and the second keyword is associated with the head office node, and it is necessary to obtain the organizational structure between a certain city branch node and the head office node;
[0164] At this time, if we start the query from the head office as the starting node, and traverse layer by layer, we need to obtain all the branches in each province at each layer, and finally find the branch in a certain city that is the target of the query. Finally, an umbrella-shaped query path will be formed, which will be expanded layer by layer, and the query complexity will be high. If we start the query from a branch in A1 city as the starting node, the query path will be a simple one-way path, and the query complexity will be very low. It can be seen that the selection of the query starting point and direction is crucial for path query. Once the wrong data traversal direction is selected, a data traversal storm and timeout may occur.
[0165] Therefore, it is necessary to obtain the correct query direction here (where the correct query direction means: starting the query with a certain A1 city branch as the starting node), and select the query direction based on the bidirectional PR value of the node associated with the first query data and the bidirectional PR value of the node associated with the second query data.
[0166] As a preferred implementation, determining the query direction in step S3 may include the following steps:
[0167] Get the query mode in the query condition. When the query mode is the key path mode:
[0168] Analyze the first query data to obtain a first node of the first query data, obtain a weighted bidirectional PR value of the first node and a weighted bidirectional PR value of at least one adjacent node to the first node, and sum the weighted bidirectional PR value of the first node and the weighted bidirectional PR value of at least one adjacent node to the first node to obtain a third summed value;
[0169] Analyze the second query data to obtain a second node of the second query data, obtain a weighted bidirectional PR value of the second node and a weighted bidirectional PR value of at least one adjacent node to the second node, and sum the weighted bidirectional PR value of the second node and the weighted bidirectional PR value of at least one adjacent node to the second node to obtain a fourth summed value;
[0170] Determine whether the third sum value is greater than the fourth sum value;
[0171] If so, take the second node as the starting node;
[0172] If not, take the first node as the starting node.
[0173] In the above determination of the query direction, the query direction is diffused from low PR and to high PR and, in the above embodiment, since the bidirectional PR value reflects the reach and influence of a node in the entire knowledge graph, the larger the bidirectional PR value, the higher the reach of its subgraph. Therefore, this embodiment uses the bidirectional PR value to measure the clear query direction, thereby reducing the data diffusion range by querying from low reach rate to high reach rate.
[0174] In the above embodiment, when the user does not specify a query mode, the critical path mode may be used as the default query mode, thereby reducing the data diffusion range by querying from a low arrival rate to a high arrival rate.
[0175] As a preferred implementation, determining the query direction in step S3 may further include the following steps:
[0176] Get the query mode in the query condition. When the query mode is the full path mode:
[0177] Analyze the first query data to obtain a first node of the first query data, obtain an unweighted bidirectional PR value of the first node and an unweighted bidirectional PR value of at least one adjacent node to the first node, and sum the unweighted bidirectional PR value of the first node and the unweighted bidirectional PR value of at least one adjacent node to the first node to obtain a first sum value;
[0178] Analyze the second query data to obtain a second node of the second query data, obtain an unweighted bidirectional PR value of the second node and an unweighted bidirectional PR value of at least one adjacent node to the second node, and sum the unweighted bidirectional PR value of the second node and the unweighted bidirectional PR value of at least one adjacent node to the second node to obtain a second summed value;
[0179] Determine whether the first sum value is greater than the second sum value;
[0180] If so, take the second node as the starting node;
[0181] If not, take the first node as the starting node.
[0182] In the above determination of the query direction, the query direction is diffused from low PR and to high PR and, in the above embodiment, since the bidirectional PR value reflects the reach and influence of a node in the entire knowledge graph, the larger the bidirectional PR value, the higher the reach of its subgraph. Therefore, this embodiment uses the bidirectional PR value to measure the clear query direction, thereby reducing the data diffusion range by querying from low reach rate to high reach rate.
[0183] Embodiment 2: When the user executes the full path query mode, that is, path filtering is not required at this time, a knowledge graph path retrieval method at this time includes the following steps:
[0184] Step A1, obtaining a knowledge graph, the knowledge graph includes multiple nodes, and calculating the unweighted PR value group of each node through the pagerank algorithm, the unweighted PR value group includes an unweighted forward PR value, an unweighted reverse PR value and an unweighted bidirectional PR value;
[0185] Step A2, such as Figure 3 As shown, a query request of a user is obtained, the query request includes first query data, second query data and query conditions, and a query direction is determined according to the query conditions in combination with an unweighted bidirectional PR value of a node corresponding to the first query data and a node corresponding to the second query data, so as to obtain a path between the first query data and the second query data in the knowledge graph according to the query conditions and in combination with the query direction, to form a second path set, the second path includes a plurality of nodes, and there is a node relationship between every two adjacent nodes;
[0186] Step A3, calculating the weighted harmonic mean of the path according to the unweighted bidirectional PR value of each node in the path in the second path set, screening the path that meets the preset rules in the second path set according to the weighted harmonic mean of the path as the query path, and feeding back the query path to the user.
[0187] It should be noted that, compared with the first embodiment, except for the implementation method involving low-value nodes and low-value node relationships, the other implementation methods of the second embodiment are the same and will not be elaborated here.
[0188] Embodiment 3, a knowledge graph path retrieval system, specifically comprising:
[0189] The calculation module obtains the knowledge graph, which includes multiple nodes. The unweighted PR value group of each node is calculated by the pagerank algorithm. The unweighted PR value group includes an unweighted forward PR value, an unweighted reverse PR value, and an unweighted bidirectional PR value. The weighted bidirectional PR value is calculated based on the unweighted bidirectional PR value of the node.
[0190] A screening module screens nodes according to the unweighted forward PR value and the unweighted reverse PR value of each node to screen out low-value nodes, and obtain low-value node relationships, wherein the low-value node relationships include node relationships corresponding to the low-value nodes;
[0191] A query module, which obtains a query request from a user, wherein the query request includes first query data, second query data, and query conditions, and determines a query direction according to a bidirectional PR value of a node corresponding to the first query data and a node corresponding to the second query data, so as to obtain a path between the first query data and the second query data in the knowledge graph according to the query conditions and in combination with the query direction, and form a first path set, wherein the first path includes a plurality of nodes, and there is a node relationship between every two adjacent nodes;
[0192] The feedback module filters the paths containing low-value nodes in the first path set to obtain the first path set, calculates the weighted harmonic mean of the paths according to the query condition and the bidirectional PR value of each node in the paths in the first path set, filters the paths that meet the preset rules in the first path set according to the weighted harmonic mean of the paths as the query paths, and feeds back the query paths to the user;
[0193] The two-way PR value is an unweighted two-way PR value or a weighted two-way PR value.
[0194] It should be noted that the implementation methods of the third embodiment are consistent with those of the first embodiment and will not be elaborated here.
[0195] The above are only preferred embodiments of the present invention, and are not intended to limit the implementation methods and protection scope of the present invention. Those skilled in the art should be aware that all solutions obtained by equivalent substitutions and obvious changes made using the description and illustrations of the present invention should be included in the protection scope of the present invention.
Claims
1. A knowledge graph path retrieval method, characterized in that: The following steps are involved: Step S1, obtaining a knowledge graph, the knowledge graph includes multiple nodes, calculating an unweighted PR value group of each node by using a pagerank algorithm, the unweighted PR value group includes an unweighted forward PR value, an unweighted reverse PR value and an unweighted bidirectional PR value, and calculating a weighted bidirectional PR value according to the unweighted bidirectional PR value of the node; Step S2, screening the nodes according to the unweighted PR value group of each node to screen out low-value nodes, and obtaining low-value node relationships, wherein the low-value node relationships include node relationships corresponding to the low-value nodes; Step S3, obtaining a query request from a user, the query request including first query data, second query data and query conditions, determining a query direction according to a bidirectional PR value of a node corresponding to the first query data and a node corresponding to the second query data, so as to obtain a path between the first query data and the second query data in the knowledge graph according to the query conditions and in combination with the query direction, and forming a path set, wherein a path in the path set includes a plurality of nodes, and a node relationship exists between every two adjacent nodes; Step S4, calculating the weighted harmonic mean of the paths according to the query condition combined with the bidirectional PR value of each node in the paths in the path set, screening the paths that meet the preset rules in the path set according to the weighted harmonic mean of the paths as the query paths, and feeding back the query paths to the user; Among them, the two-way PR value is an unweighted two-way PR value or a weighted two-way PR value; The low-value nodes screened in step S2 specifically include: Nodes whose positive PR values exceed a preset positive PR threshold are regarded as low-value nodes; and / or Nodes whose reverse PR values exceed a preset reverse PR threshold are regarded as low-value nodes; and / or The nodes whose bidirectional PR values exceed a preset bidirectional PR threshold are regarded as the low-value nodes; and / or Calculate the absolute value of the difference between the forward PR value and the reverse PR value of the node, and take the node whose absolute value exceeds a preset absolute value threshold as the low-value node; Determining the query direction in step S3 to obtain a path between the first query data and the second query data in the knowledge graph according to the query condition and in combination with the query direction includes: Obtain the query mode in the query condition, when the query mode is a key path mode: Analyze the first query data to obtain a first node of the first query data, obtain a weighted bidirectional PR value of the first node and a weighted bidirectional PR value of at least one adjacent node to the first node, and sum the weighted bidirectional PR value of the first node and the weighted bidirectional PR value of at least one adjacent node to the first node to obtain a third summed value; Analyze the second query data to obtain a second node of the second query data, obtain a weighted bidirectional PR value of the second node and a weighted bidirectional PR value of at least one adjacent node to the second node, and sum the weighted bidirectional PR value of the second node and the weighted bidirectional PR value of at least one adjacent node to the second node to obtain a fourth summed value; Determining whether the third sum value is greater than the fourth sum value; If yes, take the second node as the starting node; If not, taking the first node as the starting node; Filtering the paths in the knowledge graph that contain the low-value nodes and / or the low-value node relationships; Get the query mode in the query condition. When the query mode is the full path mode: Analyzing the first query data to obtain a first node of the first query data, obtaining an unweighted bidirectional PR value of the first node and an unweighted bidirectional PR value of at least one adjacent node to the first node, and summing the unweighted bidirectional PR value of the first node and the unweighted bidirectional PR value of at least one adjacent node to the first node to obtain a first summed value; Analyze the second query data to obtain a second node of the second query data, obtain an unweighted bidirectional PR value of the second node and an unweighted bidirectional PR value of at least one adjacent node to the second node, and sum the unweighted bidirectional PR value of the second node and the unweighted bidirectional PR value of at least one adjacent node to the second node to obtain a second summed value; Determine whether the first sum value is greater than the second sum value; If yes, take the second node as the starting node; If not, the first node is used as the starting node.
2. The knowledge graph path retrieval method according to claim 1, characterized in that: The step S1 of obtaining the weighted bidirectional PR value specifically includes: Performing weighted summation on the bidirectional PR values of the nodes according to a preset weight algorithm to obtain a weighted sum of the nodes; And according to the weighted sum, the weighted bidirectional PR value corresponding to the node is calculated by the pagerank algorithm.
3. The knowledge graph path retrieval method according to claim 1, characterized in that: The acquisition of low-value node relationships in step S2 specifically includes: Obtaining the node relationship associated with the low-value node; And the node relationships associated with the low-value nodes are sorted according to the number of occurrences, so as to set a preset number of sorted node relationships as the low-value node relationships.
4. The knowledge graph path retrieval method according to claim 1, characterized in that: The query conditions in step S4 include: query termination conditions and query methods; Wherein, the query termination condition includes: the end node or the maximum number of hops; The node relationship of the paths in the path set is less than or equal to the maximum hop number.
5. A knowledge graph path retrieval system, characterized in that: Specifically include: A calculation module is used to obtain a knowledge graph, wherein the knowledge graph includes multiple nodes, and an unweighted PR value group of each node is calculated by a pagerank algorithm, wherein the unweighted PR value group includes an unweighted forward PR value, an unweighted reverse PR value, and an unweighted bidirectional PR value, and a weighted bidirectional PR value is calculated according to the unweighted bidirectional PR value of the node; A screening module, screening nodes according to the unweighted forward PR value and the unweighted reverse PR value of each node, so as to screen out low-value nodes, and obtain low-value node relationships, wherein the low-value node relationships include node relationships corresponding to the low-value nodes; A query module, which obtains a query request from a user, wherein the query request includes first query data, second query data, and a query condition, and determines a query direction according to a bidirectional PR value of a node corresponding to the first query data and a node corresponding to the second query data, so as to obtain a path between the first query data and the second query data in the knowledge graph according to the query condition and in combination with the query direction, to form a first path set, wherein the first path includes a plurality of nodes, and a node relationship exists between every two adjacent nodes; a feedback module, which calculates the weighted harmonic mean of the path according to the query condition and the bidirectional PR value of each node in the path in the first path set, screens the first path set according to the weighted harmonic mean of the path to obtain a path that meets the preset rules as a query path, and feeds back the query path to the user; Among them, the two-way PR value is an unweighted two-way PR value or a weighted two-way PR value; The low-value nodes screened in the screening module specifically include: Nodes whose positive PR values exceed a preset positive PR threshold are regarded as low-value nodes; and / or Nodes whose reverse PR values exceed a preset reverse PR threshold are regarded as low-value nodes; and / or The nodes whose bidirectional PR values exceed a preset bidirectional PR threshold are regarded as the low-value nodes; and / or Calculate the absolute value of the difference between the forward PR value and the reverse PR value of the node, and take the node whose absolute value exceeds a preset absolute value threshold as the low-value node; Determining a query direction to obtain a path between the first query data and the second query data in the knowledge graph according to the query condition and in combination with the query direction includes: Obtain the query mode in the query condition, when the query mode is a key path mode: Analyze the first query data to obtain a first node of the first query data, obtain a weighted bidirectional PR value of the first node and a weighted bidirectional PR value of at least one adjacent node to the first node, and sum the weighted bidirectional PR value of the first node and the weighted bidirectional PR value of at least one adjacent node to the first node to obtain a third summed value; Analyze the second query data to obtain a second node of the second query data, obtain a weighted bidirectional PR value of the second node and a weighted bidirectional PR value of at least one adjacent node to the second node, and sum the weighted bidirectional PR value of the second node and the weighted bidirectional PR value of at least one adjacent node to the second node to obtain a fourth summed value; Determining whether the third sum value is greater than the fourth sum value; If yes, take the second node as the starting node; If not, taking the first node as the starting node; Filtering the paths in the knowledge graph that contain the low-value nodes and / or the low-value node relationships; Get the query mode in the query condition. When the query mode is the full path mode: Analyzing the first query data to obtain a first node of the first query data, obtaining an unweighted bidirectional PR value of the first node and an unweighted bidirectional PR value of at least one adjacent node to the first node, and summing the unweighted bidirectional PR value of the first node and the unweighted bidirectional PR value of at least one adjacent node to the first node to obtain a first summed value; Analyze the second query data to obtain a second node of the second query data, obtain an unweighted bidirectional PR value of the second node and an unweighted bidirectional PR value of at least one adjacent node to the second node, and sum the unweighted bidirectional PR value of the second node and the unweighted bidirectional PR value of at least one adjacent node to the second node to obtain a second summed value; Determine whether the first sum value is greater than the second sum value; If yes, take the second node as the starting node; If not, the first node is used as the starting node.
Citation Information
Patent Citations
Knowledge graph-based information processing method and device, equipment and storage medium
CN112699249A
Knowledge graph visualization rapid retrieval implementation method, system and device and medium
CN112989029A
