Query Method and Device for Knowledge Graph

By splitting the query graph into subgraphs and generating the intersection results of the subquery statements, the problem of low efficiency of knowledge graph query is solved, and efficient information query is achieved.

CN114579716BActive Publication Date: 2025-07-22ZHEJIANG DAHUA TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210093223.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-26
Publication Date
2025-07-22
Estimated Expiration
2042-01-26

AI Technical Summary

Technical Problem

In the prior art, the method of using knowledge graphs for information query is relatively low efficiency, especially when natural statements are more complex, the query performance is insufficient.

Method used

Split the query graph into at least two subgraphs with the query intent point as the split point, generate a subquery statement based on each subgraph, and use the result intersection of the subquery statement as the result of the natural statement, simplifying the query process and improving query performance.

Benefits of technology

While ensuring the accuracy of the result, the query performance and result acquisition efficiency of the query statement are improved, and the ids of more objects can be quickly positioned, which improves the query efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114579716B_ABST
    Figure CN114579716B_ABST
Patent Text Reader

Abstract

The present application discloses a method and apparatus for querying a knowledge graph. Among them, the method for querying the knowledge graph includes: obtaining a query graph that matches a natural sentence, and determining a query intent point in the query graph; using the query intent point as a splitting point to split the query graph into at least two subgraphs; generating each sub-query sentence based on each subgraph; determining the query result of each sub-query sentence; and taking the intersection of the query results of all the sub-query sentences as the query result of the natural sentence. The present application can improve the query performance of query sentences, and further improve the efficiency of information query using the knowledge graph.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of query technologies, and particularly to a query method and apparatus for a knowledge graph. Background Art

[0002] With the development of Internet applications, the technology of using a knowledge graph for information query has received increasing attention. However, the current methods for using a knowledge graph to query information are inefficient. Summary of the Invention

[0003] This application provides a query method and apparatus for a knowledge graph, which can quickly locate more objects using an index and improve the query performance of statements.

[0004] To achieve the above object, this application provides a query method for a knowledge graph, which includes:

[0005] Obtain a query graph that matches a natural statement, and determine the query intent points in the query graph;

[0006] Taking the query intent points as splitting points, split the query graph into at least two subgraphs;

[0007] Generate each sub-query statement based on each subgraph;

[0008] Determine the query results of each sub-query statement;

[0009] Take the intersection of the query results of all sub-query statements as the query result of the natural statement.

[0010] Among them, the step of taking the query intent points as splitting points and splitting the query graph into at least two subgraphs includes:

[0011] When the number of edges connected to the query intent points in the query graph is n, taking the query intent points as splitting points, split the query graph into n subgraphs, and each subgraph includes the query intent points;

[0012] Among them, n≥2.

[0013] Among them, the step of generating each sub-query statement based on each subgraph includes:

[0014] Take the object with the lowest quantity proportion among all entity objects and all entity relationship objects that are in the subgraph and appear in the natural statement as the starting object of the sub-query statement of the subgraph, and construct the sub-query statement of the subgraph.

[0015] Among them, the quantity proportion of an object is the ratio of the total quantity of the object in the knowledge graph to the total quantity of all objects in the knowledge graph.

[0016] Among them, the steps of constructing the sub-query statement of the sub-graph by using the object with the lowest proportion among all entity objects and all entity relationship objects that appear in the sub-graph and in the natural statement as the starting object of the sub-query statement of the sub-graph include:

[0017] Determine the complete link of the object connection of the sub-graph based on the starting object;

[0018] Read the information of each object in turn according to the complete link of the object connection of the sub-graph to form the sub-query statement of the sub-graph.

[0019] Among them, the steps of constructing the sub-query statement of the sub-graph include:

[0020] In the case where there is a quantity limit condition in the query result of the natural statement, add the quantity limit condition to the sub-query statement of the sub-graph.

[0021] Among them, the steps of constructing the sub-query statement of the sub-graph include:

[0022] If there is a place name in the sub-graph whose name length is greater than the length threshold, perform word segmentation on the place name whose length is greater than the length threshold; generate the sub-query statement of the sub-graph based on the place name after word segmentation.

[0023] Among them, the steps of obtaining the query graph that matches the natural statement and determining the query intent point in the query graph include:

[0024] Determine whether there is a query intent point in the obtained query graph; and / or, determine whether the query intent point matches the natural statement;

[0025] The method further includes:

[0026] In the case where there is no query intent point in the obtained query graph and / or the query intent point does not match the natural statement, re-execute the steps of obtaining the query graph that matches the natural statement and determining the query intent point in the query graph.

[0027] Among them, after the steps of obtaining the query graph that matches the natural statement and determining the query intent point in the query graph include:

[0028] Parse the entities and entity relationships in the query graph;

[0029] During the parsing process, preferentially parse the information of the entity relationships in the query graph.

[0030] Among them, the steps of preferentially parsing the information of the entity relationships in the query graph include:

[0031] In the case where the first attribute of the entity relationship is the same as the first attribute of the entity, only load the first attribute of the entity relationship, or only load the first attribute of the entity.

[0032] To achieve the above object, the present application further provides an electronic device, which includes a processor; the processor is used to execute instructions to implement the above method.

[0033] To achieve the above object, the present application further provides a computer-readable storage medium, which is used to store instructions / program data, and the instructions / program data can be executed to implement the above method.

[0034] In the query method of the knowledge graph of the present application, the query graph obtained based on natural sentences is split at the query intent point to obtain at least two subgraphs, and then the sub-query sentences of each subgraph are determined. In this way, there is no need to solve complex query sentences for the knowledge graph. Only the results of simple sub-query sentences need to be obtained from the knowledge graph, and then the intersection of the results of all sub-query sentences is used as the result of the complex natural sentence, which improves the query performance of the query sentence and improves the result acquisition efficiency of the query sentence while ensuring the accuracy of the result of the natural sentence; moreover, indexes can be used to quickly locate the ids of more objects, improving the query performance of the sentence. Description of the Drawings

[0035] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation of the present application. In the drawings:

[0036] Figure 1 is a schematic flowchart of an implementation manner of the query method of the knowledge graph of the present application;

[0037] Figure 2 is a schematic structural diagram of a query graph in the query method of the knowledge graph of the present application;

[0038] Figure 3 is from the present application Figure 2 The sub- Figure 1 obtained by splitting the query graph shown;

[0039] Figure 4 is from the present application Figure 2 The sub- Figure 2 obtained by splitting the query graph shown;

[0040] Figure 5 is a schematic structural diagram of an implementation manner of the electronic device of the present application;

[0041] Figure 6 is a schematic structural diagram of an implementation manner of the computer-readable storage medium of the present application. Detailed Embodiments

[0042] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present application without creative efforts belong to the scope of protection of the present application. Additionally, unless otherwise specified (e.g., "or alternatively" or "or in an alternative"), the term "or" as used herein refers to a non-exclusive "or" (i.e., "and / or"). Moreover, the various embodiments described herein are not necessarily mutually exclusive, as some embodiments can be combined with one or more other embodiments to form new embodiments.

[0043] Currently, the steps of a solution for information query using a knowledge graph may include: obtaining a query graph from the knowledge graph using a natural sentence; then performing object assembly on the entities and entity relationships in the query graph to generate a query statement for the query graph, and further determining the result of the natural sentence by executing the query statement of the query graph. In the case where the natural sentence is relatively complex, the query graph obtained based on the natural sentence will also be relatively complex, and then the query statement generated using the query graph will be even more complex. In this way, the matching of the query statement will be slower, and since only the starting object of the query statement can be quickly located to the id using an index, the remaining objects need to be located through traversal, resulting in a low query performance of the query statement.

[0044] Based on this, in the case where the natural sentence is relatively complex, for example, the natural sentence can be split into at least two simple sub-questions, the present application will split the query graph obtained based on the natural sentence at the query intention point to obtain at least two sub-graphs, and then determine the sub-query statements for each sub-graph. In this way, there is no need to solve complex query statements for the knowledge graph, only the results of simple sub-query statements need to be obtained from the knowledge graph, and then the intersection of the results of all sub-query statements is used as the result of the complex natural sentence, which improves the query performance of the query statement and also improves the efficiency of obtaining the result of the query statement while ensuring the accuracy of the result of the natural sentence; moreover, more object ids can be quickly located using an index, comprehensively improving the query performance of the statement.

[0045] After obtaining the query point and the query intention point based on the above steps, the query graph can be split into at least two sub-graphs at the query intention point, such that the sub-query statements generated based on the sub-graphs are relatively simple, which can improve the performance of querying the result of the natural sentence using the query statement and improve the query efficiency of complex multi-hop query graphs.

[0046] Specifically, such as Figure 1As shown, the query method of the knowledge graph in this embodiment includes the following steps. It should be noted that the following step numbers are only used for simplified description and are not intended to limit the execution order of the steps. Each step of this embodiment can be arbitrarily changed in the execution order on the basis of not violating the technical idea of this application.

[0047] S101: Obtain a query graph that matches the natural sentence and determine the query intent points in the query graph.

[0048] First, a query graph that matches the natural sentence can be obtained and the query intent points in the query graph can be determined, so as to subsequently split the query graph into at least two subgraphs based on the query intent points, so as to quickly obtain the result of the natural sentence based on the at least two subgraphs for quick query.

[0049] Optionally, the natural sentence can be segmented to identify the entities, entity attributes, entity relationships, and / or attributes of entity relationships included in the natural sentence, and then the query graph associated with the natural sentence can be obtained from the knowledge graph by using the entities, entity attributes, entity relationships, and / or attributes of entity relationships identified in the natural sentence. In the case of obtaining the query graph, the query graph can be further matched with the entities, entity attributes, entity relationships, and / or attributes of entity relationships in the natural sentence to determine the position of the result of the natural sentence in the query graph (i.e., the query intent point).

[0050] Specifically, in step S101, the natural sentence can be segmented by using a dictionary tool and the pre-constructed graph structure in the knowledge graph, and the query graph that matches the natural sentence can be obtained from the knowledge graph by using the entities, entity attributes, entity relationships, and / or attributes of entity relationships identified from the natural sentence, and then the position of the query intent point in the query graph can be determined.

[0051] After obtaining the query graph, the query graph can be verified to determine whether the obtained query graph is incorrect; in the case of confirming that the obtained query graph is incorrect, step S101 can be re-executed to regenerate the query graph. Specifically, the query graph can be verified in the following manner.

[0052] First, it can be determined whether the query intent point is empty, that is, it can be understood as confirming whether there is a query intent point in the query graph; if the query intent point is empty, it is confirmed that the obtained query graph is incorrect.

[0053] Second, it is also possible to determine whether the query intent is in the recognized entity list, that is, it can be understood as confirming whether the category attribute of the target result matches the category attribute of the intent result point; in the case where the category attribute of the target result does not match the category attribute of the query intent point, it is confirmed that the obtained query graph is incorrect. For example, when the category attribute of the intent result point is a mobile phone, but the category attribute of the target result of the natural sentence is a person, the category attribute of the intent result point does not match the category attribute of the target result of the natural sentence, and at this time, it can be confirmed that the obtained query graph is incorrect.

[0054] Third, it is also possible to confirm whether the query intent is in the list of connection relationships between the recognized entities, that is, it can be understood as confirming whether the query graph matches the natural sentence. If not, it is confirmed that the obtained query graph is incorrect. For example, if the query graph shows the relationship between a person and an event, but the natural sentence asks why the person's mobile phone number is, it can be confirmed that the query graph does not match the natural sentence, and it can be confirmed that the obtained query graph is incorrect.

[0055] After obtaining a query graph that matches the natural sentence, the query graph can be parsed and optimized to assemble corresponding point objects and edge objects.

[0056] In the process of parsing the query graph, the information of the edges of the query graph can be parsed first, and then the information of the points can be parsed. This can improve the performance of the query statement generated based on the query graph and improve the fault tolerance of the graph information. Among them, the edges in the query graph correspond to the connection relationships between entities (i.e., entity relationships), and the points in the query graph correspond to entities.

[0057] Among them, the point information can include the index name, attributes, entity name, and their quantity ratios corresponding to the point object itself. The edge information can include the starting point name, ending point name, edge relationship name, attributes, and / or quantity ratios corresponding to the edge object itself.

[0058] Specifically, preferentially parsing the information of the edges of the query graph can include: in the case where an attribute of a point is the same as an attribute of an edge, the same attribute can be loaded only on the edge or only on the point, which can avoid redundant attribute duplication loading in the query graph information.

[0059] Preferably, the same attribute can be loaded on the edge, because when filtering the attributes on the edge during the execution of the query statement, no multi-jump is required, while when filtering the attributes on the point, a jump operation is required. Therefore, by loading the redundant attributes on the edge, the time consumption of the screening conditions can be reduced and the query efficiency can be improved.

[0060] In addition, during the process of parsing the query graph, if the parsed point object is not in the edge object, the point object can be treated as an error object without being loaded, and the generated query statement will not include the object either, so as to improve the fault tolerance of the query graph information.

[0061] S102: Use the query intent point as the splitting point to split the query graph into at least two subgraphs.

[0062] After obtaining the query points and query intent points based on the above steps, the query graph can be split into at least two subgraphs with the query intent point as the splitting point, so that the subquery statements generated based on the subgraphs are relatively simple, which can improve the performance of querying the natural statement results using the query statements and enhance the query efficiency of complex multi-hop query graphs.

[0063] It should be noted that all subgraphs split with the query intent point as the splitting point contain the query intent point, so as to use the subgraphs to construct subquery statements whose query results include the results of natural statements, thereby ensuring the accuracy of the query results.

[0064] Optionally, in step S102, the number of edges connected to the query intent point in the query graph can be determined. When the number of edges connected to the query intent point is n (n≥2), the query graph is split into n subgraphs with the query intent point as the splitting point, so as to subsequently determine the starting object of the subquery statement of each subgraph, assemble the subquery statements of the subgraphs, and perform subqueries on the subquery statements of the subgraphs, etc. Finally, the intersection of the query results of all subquery statements is used as the result of the natural statement. In addition, when the number of edges connected to the query intent point is 1, there is no need to split the query graph.

[0065] For example, when the query intent point is Figure 2 the filled point - person2 as shown, the query graph shown in Figure 2 can be split into two subgraphs with the filled point - person2 as the splitting point. The structure of one subgraph is as shown in Figure 3 and the structure of the other subgraph is as shown in Figure 4 as shown.

[0066] S103: Based on generating each subquery statement from each subgraph, determine the query result of each subquery statement.

[0067] After splitting the query graph of the natural statement into at least two subgraphs based on the above steps, in step S103, the subquery statements corresponding to each subgraph can be determined, and then the query results of each subquery statement can be determined.

[0068] In the process of generating a sub-query statement corresponding to the sub-graph based on the sub-graph, the starting object of the sub-query statement can be determined first, and then the remaining objects in the sub-graph can be traversed in sequence starting from the starting object of the sub-query statement to form a complete link of the connection of the objects in the sub-graph, and finally the sub-query statement of the sub-graph can be obtained.

[0069] For example, assume that Figure 4 the starting object of the sub-query statement of the sub-graph shown is peerEvent, then Figure 4 the complete link of the connection of the objects in the sub-graph shown is: peerEvent→hasPeerEvent→person1—hasPeerEvent—peerEvent→hasPeerEvent→person2 (where "→" represents connection and "—" represents backtracking).

[0070] Another example, assume that Figure 4 the starting object of the sub-query statement of the sub-graph shown is person1, then Figure 4 the complete link of the connection of the objects in the sub-graph shown is: person1→hasPeerEvent→peerEvent→hasPeerEvent→person2.

[0071] Among them, the selection of the starting object of the sub-query statement plays a crucial role in the query performance of the query statement. The fewer the starting hit entity objects or entity relationship objects, the fewer the number of times the sub-query statement needs to traverse, and thus the higher the query performance. Therefore, it is more preferable that all entity objects and all entity relationship objects that appear in the natural statement and have the smallest quantity ratio in the sub-graph can be used as the starting object of the sub-query statement of the sub-graph, so that the number of times the sub-query statement of the sub-graph needs to traverse becomes less, thereby improving the query performance and avoiding the situation of low query efficiency caused by improper selection of the starting object. For example, when determining Figure 4 the starting object of the query statement of the sub-graph shown, if the natural statement includes the content of "who is the peer of person1", then it can be determined which object among person1, hasPeerEvent, and peerEvent has the smallest quantity ratio. Assume that it is determined that the quantity ratio of person1 is the smallest, then person1 can be used as Figure 4 the starting object of the sub-query statement of the sub-graph shown.

[0072] Among them, when importing data into the graph database, multi-dimensional grouping counting statistics can be performed by label and by attribute to determine the proportion of the number of each object. Specifically, the proportion of the number of objects in the subgraph can be equal to the ratio of the total number of such objects in the knowledge graph to the total number of all objects (including entity objects and entity relationship objects) in the knowledge graph. Among them, based on the calculation formula of the proportion of the number, the proportion of the number of objects can be dynamically changed as the imported data in the knowledge graph changes.

[0073] Specifically, the proportion of the number of each object can be reflected by the priority, so that the starting object of the subquery statement can be quickly determined through the priority. In one embodiment, the smaller the proportion of the number of each object, the higher the priority; otherwise, the lower the priority; in this way, the object with the highest priority in the subgraph can be used as the starting object of the subquery statement of the subgraph.

[0074] Furthermore, query experience can also be referred to when determining the starting object of the subquery statement. For example, by analyzing a large number of query statements and the actual time consumption at each stage as seeds, if it is determined that the query effects of attributes and labels with precise matches such as name, ID number, mobile phone number, license plate number, etc. are better, then high priorities can be given to these attributes and labels.

[0075] After determining the starting object of the subquery statement based on the above scheme, the remaining objects in the subgraph can be traversed in sequence starting from the starting object of the subquery statement to form a complete link of the connection of objects in the subgraph, ensuring the integrity of the query path and the optimal query path.

[0076] Specifically, if the starting object is a point object, any edge containing the starting object is selected as the starting edge, and then the remaining objects in the subgraph are traversed in sequence according to the splicing order of the edge objects in the subgraph to form a complete link of the connection of objects in the subgraph.

[0077] If the starting object is an edge object, the subsequent edge objects are spliced according to the principle that the end node in the previous edge object is used as the starting node in the subsequent edge object; if the starting node and the end node of the subsequent edge object do not exist in the previous edge object, they are directly discarded without splicing. Specifically, assume that, as Figure 4 shown, the starting object of the subquery statement of the subgraph is hasPeerEvent, then as Figure 4 shown, the complete link of the connection of objects in the subgraph is: hasPeerEvent→person1—hasPeerEvent→peerEvent→hasPeerEvent→person2.

[0078] After determining the complete link of object connections in the sub-graph, the conditional filtering attributes of each object can be read sequentially according to the complete link of object connections in the sub-graph to obtain the sub-query statement of the sub-graph. Specifically, the conditional filtering attributes of each object can be read by calling the toString method of the point-edge object.

[0079] In the process of generating the sub-query statement, the initial query statement of the sub-graph can be optimized to adjust the initial query statement based on certain specific scenarios without changing the order of the sub-graph, so that the final sub-query statement of the sub-graph achieves the optimal query performance.

[0080] Specifically, it can be confirmed whether there are other restrictive conditions. If so, the restrictive condition can be added to the sub-query statement. Specifically, if there is a quantity limit condition in the query result, the quantity limit condition needs to be added to the sub-query statement.

[0081] For example, if there is an upper limit on the number of query results, that is, there is a paging requirement, then range Step can be added to the sub-query statement. The earlier the range Step is located, the higher the query performance, but it is necessary to ensure that the data returned by paging all meet the filtering operations following rangeStep. One of the reference positions of range Step is as follows: if rangeStep is to be added after a point object, it is necessary to ensure that there is no edge connected to the point object; if rangeStep is to be added after an edge object, it is necessary to ensure that there is no attribute filtering condition for the point object connected by the edge object.

[0082] In addition, if there is a geographical location in the natural statement and the geographical location in the natural statement is relatively long, then the geographical location can be appropriately segmented, and then the sub-query statement can be generated based on the segmented geographical location. In this way, when executing the sub-query statement, there is no need to match the complete geographical location, and it can be matched segment by segment to improve the matching efficiency and thus improve the query efficiency. Specifically, an appropriate tokenizer can be selected for segmentation according to the business scenario.

[0083] In addition, after obtaining the sub-query statement based on the above scheme, the generated sub-query statement can be verified to verify whether the sub-query statement is incorrect; in the case of confirming that the generated sub-query statement is an incorrect statement, the sub-query statement of the sub-graph can be regenerated to strongly intercept the generation of incorrect statements by verifying and optimizing the query statement.

[0084] Specifically, it can be judged whether there is V() or E() in the generated query statement. If not, it means that the generated sub-query statement is an incorrect statement, and the query statement generation module needs to be called to regenerate the sub-query statement.

[0085] In addition, it is also possible to determine whether there is a filtering condition in the generated query statement; if not, it means that the generated query statement cannot improve performance with the help of an index and is inefficient, and should be regenerated. Specifically, when it is determined that there is no has condition to filter Step after V() or E() in the generated query statement, it means that there is no filtering condition in the generated query statement.

[0086] S104: Use the intersection of the query results of all sub-query statements as the query result of the natural statement.

[0087] In this embodiment, the query graph obtained based on the natural statement is split at the query intent point to obtain at least two subgraphs, and then the sub-query statements of each subgraph are determined. In this way, there is no need to solve complex query statements for the knowledge graph. Only the results of simple sub-query statements need to be obtained from the knowledge graph, and then the intersection of the results of all sub-query statements is used as the result of the complex natural statement, which improves the query performance of the query statement and improves the efficiency of obtaining the result of the query statement while ensuring the accuracy of the result of the natural statement; moreover, the index can be used to quickly locate the ids of more objects, comprehensively improving the query performance of the statement.

[0088] The following provides specific embodiments of the query of the knowledge graph to exemplarily illustrate for better explaining the query method of the knowledge graph of the present application:

[0089] 1. Obtain and verify the query graph

[0090] If the natural statement is "a person with the mobile phone number 13343345335 who travels with Zhang San", then the structure of the query graph matching the natural statement is as Figure 2 shown.

[0091] 2. Parse and optimize the query graph

[0092] Parse the Figure 2 query graph to obtain the following information.

[0093] (1) The information of the point objects is as follows:

[0094] (person1, name, Zhang San);

[0095] (phone, number, 13343345335);

[0096] (person2, [], []);

[0097] (peerEvent, tag, travels with);

[0098] (2) The information of the edge objects is as follows:

[0099] (person1, hasPeerEvent, peerEvent);

[0100] (peerEvent, hasPeerEvent, person2);

[0101] (person2, hasPhone, phone);

[0102] (3) Query intent point: person2.

[0103] 3. Query graph information splitting

[0104] According to the edge object information, it can be known that there are two edges in the query graph that are connected to the query intent point person2 ( Figure 2 filled point in). Therefore, taking person2 as the reference point, the query graph is split into Figure 3 and Figure 4 the two sub-query graphs shown. In order to subsequently generate a sub-query statement for each of the two sub-query graphs, which are the person with the mobile phone number 13343345335 and the person who travels with Zhang San respectively. In this way, finally, the intersection of the query results of the two sub-query statements can be taken, and this intersection is used as the final query result of the natural statement.

[0105] 4. Determine the starting object of the sub-query statement for the sub-graph

[0106] Using the preset ratio of the number of point-edge objects, it is found after calculation that: Figure 3 in the sub-graph of, the point of the mobile phone with the mobile phone number 13343345335 has the highest priority, so the point of the mobile phone with the mobile phone number 13343345335 can be used as Figure 3 the starting object of the sub-query statement for the sub-graph of; Figure 4 in the sub-graph of, the point of the person with the name Zhang San has the highest priority, so the point of the person with the name Zhang San can be used as Figure 4 the starting object of the sub-query statement for the sub-graph of.

[0107] 5. Assemble the query sub-graph order

[0108] According to the sub-graph information, determine the starting edge object order of the sub-graphs, and select an edge containing the starting object from the Figure 3 sub-graph shown and the Figure 4 edge object information of the sub-graph shown respectively. Figure 3 The starting edge object of the sub-graph shown in is: (person1, hasPhone, person2); Figure 4 The starting edge object of the sub-graph shown in is: (person1, hasPeerEvent, peerEvent); Assemble the query sub-graph order according to the edge object splicing rules. The assembled sub-graph order is:

[0109] Figure 3 The subgraph shown: phone→hasPhone→person2

[0110] Figure 4 The subgraph shown: person1→hasPeerEvent→peerEvent→hasPeerEvent→person2.

[0111] 6. Query statement optimization, generation, and verification

[0112] According to the subgraph order determined in step 5, sequentially call the toString method of the vertex-edge object to generate the subquery statement of the subgraph.

[0113] Among them, the subquery statement can be a Gremlin statement, but is not limited to this.

[0114] 7. Execute the subquery statement

[0115] After obtaining the subquery statement, the subquery statement can be executed to obtain the query result of the subquery statement, and then based on the query result of the subquery statement, obtain the query result of the natural statement.

[0116] Please refer to Figure 5 , Figure 5 which is a schematic structural diagram of an embodiment of the electronic device 20 of the present application. The electronic device 20 of the present application includes a processor 22, and the processor 22 is used to execute instructions to implement the method of any one of the above embodiments of the present application and the method provided by any non-conflicting combination.

[0117] The electronic device 20 can be a device such as a camera device or a server, and is not limited herein.

[0118] The processor 22 can also be referred to as a CPU (Central Processing Unit, central processing unit). The processor 22 may be an integrated circuit chip with signal processing capabilities. The processor 22 can also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. The general-purpose processor can be a microprocessor, or the processor 22 can also be any conventional processor, etc.

[0119] The electronic device 20 may further include a memory 21 for storing instructions and data required for the operation of the processor 22.

[0120] Please refer to Figure 6 , Figure 6This is a schematic structural diagram of a computer-readable storage medium in an embodiment of the present application. The computer-readable storage medium 30 of the embodiment of the present application stores instruction / program data 31, and when the instruction / program data 31 is executed, it implements the methods provided by any one of the above-mentioned methods of the present application and any non-conflicting combination. Among them, the instruction / program data 31 can form a program file and be stored in the above storage medium 30 in the form of a software product, so that a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor can execute all or part of the steps of the methods in various embodiments of the present application. The aforementioned storage medium 30 includes: various media that can store program codes such as USB flash drives, mobile hard disks, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), magnetic disks, or optical discs, or devices such as computers, servers, mobile phones, and tablets.

[0121] In several embodiments provided by the present application, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of units is only a logical function division, and there can be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection to each other can be through some interfaces, and the indirect coupling or communication connection of devices or units can be in an electrical, mechanical, or other form.

[0122] In addition, each functional unit in various embodiments of the present application can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of a software functional unit.

[0123] It should also be noted that the term "including", "comprising", or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, commodity, or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such a process, method, commodity, or device. Without further limitation, an element defined by the statement "including one..." does not exclude the existence of another identical element in the process, method, commodity, or device including the element.

[0124] The above are only the embodiments of the present application, and do not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made by using the content of the specification and drawings of the present application, or directly or indirectly applied in other related technical fields, shall be equally included in the patent protection scope of the present application.

Claims

1. A query method for a knowledge graph, characterized in that, The method includes: Obtaining a query graph that matches the natural statement, and determining a query intent point in the query graph, where the query intent point is the position of the result of the natural statement in the query graph; Taking the query intent point as a split point, splitting the query graph into at least two subgraphs; Generating each sub-query statement based on each subgraph; Determining the query result of each sub-query statement; Taking the intersection of the query results of all the sub-query statements as the query result of the natural statement; Among them, the step of generating each sub-query statement based on each subgraph includes: taking the object with the lowest quantity proportion among all entity objects and all entity relationship objects that appear in the subgraph and also appear in the natural statement as the starting object of the sub-query statement of the subgraph, and constructing the sub-query statement of the subgraph; Among them, the step of taking the query intent point as a split point and splitting the query graph into at least two subgraphs includes: when the number of edges connected to the query intent point in the query graph is n, taking the query intent point as a split point, splitting the query graph into n subgraphs, and each subgraph includes the query intent point; where n≥2.

2. The method according to claim 1, wherein The quantity proportion of an object is the ratio of the total quantity of the object in the knowledge graph to the total quantity of all objects in the knowledge graph.

3. The method according to claim 1, characterized in that The step of taking the object with the lowest quantity proportion among all entity objects and all entity relationship objects that appear in the subgraph and also appear in the natural statement as the starting object of the sub-query statement of the subgraph and constructing the sub-query statement of the subgraph includes: Determining a complete link of the connections of the objects in the subgraph based on the starting object; Sequentially reading the information of each object according to the complete link of the connections of the objects in the subgraph to form the sub-query statement of the subgraph.

4. The method according to claim 1, wherein The step of constructing the sub-query statement of the subgraph includes: When there is a quantity limit condition for the query result of the natural statement, adding the quantity limit condition to the sub-query statement of the subgraph.

5. The method according to claim 1, wherein The step of constructing the sub-query statement of the subgraph includes: If there is a place name in the subgraph whose name length is greater than the length threshold, performing word segmentation on the place name whose length is greater than the length threshold; generating the sub-query statement of the subgraph based on the place name after word segmentation.

6. The method according to claim 1, characterized in that The step of obtaining a query graph that matches the natural statement and determining a query intent point in the query graph includes: Determining whether there is a query intent point in the obtained query graph; and / or, determining whether the query intent point matches the natural statement; The method further includes: When there is no query intent point in the obtained query graph and / or the query intent point does not match the natural statement, re-executing the step of obtaining a query graph that matches the natural statement and determining a query intent point in the query graph.

7. The method according to claim 1, characterized in that, After the step of obtaining a query graph that matches the natural statement and determining a query intent point in the query graph includes: Parsing the entities and entity relationships in the query graph; During the parsing process, the information of the entity relationships in the query graph is preferentially parsed.

8. The method according to claim 7, wherein The step of preferentially parsing the information of the entity relationships in the query graph includes: When the first attribute of the entity relationship is the same as the first attribute of the entity, only load the first attribute of the entity relationship or only load the first attribute of the entity.

9. An electronic device, characterized in that, The electronic device includes a processor, and the processor is configured to execute instructions to implement the steps of the method according to any one of claims 1-8.

10. A computer-readable storage medium, on which a program and / or instructions are stored, characterized in that, When the program and / or instructions are executed, the steps of the method according to any one of claims 1-8 are implemented.

Citation Information

Patent Citations

  • Spark concurrent sub-image querying method

    CN108090179A

  • A multi-strategy fusion knowledge question and answer method and system

    CN109918489A