Information query method and device

By constructing knowledge subgraphs and extracting subgraph features in the information query method, estimating the amount of query results and optimizing the query statement, the problem of inaccurate prediction of the amount of query results in the prior art is solved, and the performance of information query is improved.

CN119621767APending Publication Date: 2025-03-14BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411766276.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-03
Publication Date
2025-03-14

AI Technical Summary

Technical Problem

When existing information query methods deal with complex knowledge graphs, they cannot accurately predict the amount of data in the query results, which affects the formulation of query strategies and leads to poor query performance.

Method used

By obtaining the first query statement, determining the query conditions and query logic structure, extracting the target nodes and target edges from the knowledge graph, forming a knowledge subgraph, extracting the subgraph features, and inputting the cardinality to determine the model, estimating the data volume of the query results, optimizing the first query statement, and obtaining the second query statement for information query.

Benefits of technology

Query optimization based on the amount of query results is realized. Through the construction of knowledge subgraphs and the extraction of subgraph features, accurate query results data is obtained, and query statements are optimized, which improves the performance of information query.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119621767A_ABST
    Figure CN119621767A_ABST
Patent Text Reader

Abstract

The invention discloses an information query method and device, and relates to the technical field of computers. A specific embodiment of the method comprises the steps of obtaining a first query statement, and determining a query condition and a query logic structure according to the first query statement; according to the query condition and the query logic structure, extracting a target node and a target edge from the knowledge graph, and forming a knowledge sub-graph; extracting sub-graph features from the knowledge sub-graph, and inputting the query condition and the sub-graph features into a cardinal number determination model to obtain a data volume of a query result corresponding to a first query statement output by the cardinal number determination model; and optimizing and updating the first query statement according to the data volume of the query result to obtain a second query statement, and performing information query by using the second query statement. According to the embodiment, query optimization based on the query result data volume is achieved, the first query statement is optimized according to the obtained accurate query result data volume, and it is guaranteed that the optimized second query statement has good query performance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to an information query method and device. Background Art

[0002] In the information query scenario based on knowledge graph, there are various query methods, such as distributed information query method using distributed computing framework, index information query method using pre-developed index structure, heuristic information query method using heuristic algorithm, etc.

[0003] In the process of implementing the present invention, the inventors found that the prior art has the following problems:

[0004] When processing complex knowledge graphs, various existing information query methods are unable to accurately predict the data volume of the query results, which affects the formulation of query strategies and leads to poor query performance. Summary of the invention

[0005] In view of this, an embodiment of the present invention provides an information query method and device, which realizes query optimization based on the query result data volume, obtains accurate query result data volume through the construction of knowledge subgraphs and the extraction of subgraph features, and then optimizes the first query statement, ensuring that the information query using the optimized second query statement has better query performance.

[0006] To achieve the above object, according to one aspect of an embodiment of the present invention, there is provided an information query method, comprising:

[0007] Obtaining a first query statement, and determining a query condition and a query logic structure according to the first query statement;

[0008] According to the query condition and the query logic structure, target nodes and target edges are extracted from the knowledge graph and formed into a knowledge subgraph;

[0009] Extracting subgraph features from the knowledge subgraph, inputting the query condition and the subgraph features into a preset cardinality determination model, and obtaining a data volume of a query result corresponding to the first query statement output by the cardinality determination model;

[0010] According to the data volume of the query result, the first query statement is optimized and updated to obtain a second query statement, and the second query statement is used to perform information query.

[0011] Optionally, according to the query conditions and the query logical structure, target nodes and target edges are extracted from the knowledge graph and a knowledge subgraph is formed, including: extracting target nodes and target edges that match the query conditions from the knowledge graph; and according to the query logical structure, structurally integrating the target nodes and the target edges to obtain a knowledge subgraph.

[0012] Optionally, target nodes and target edges matching the query conditions are extracted from the knowledge graph; the target nodes and target edges are structurally integrated according to the query logical structure to obtain a knowledge subgraph, including: obtaining a query triple from the query conditions; searching for a target triple matching the query triple from the knowledge triples corresponding to the knowledge graph; determining the corresponding target nodes and target edges according to the target triples; and structurally integrating the target nodes and target edges according to the query logical structure to obtain a knowledge subgraph, wherein the query logical structure includes at least one of a star structure, a chain structure and a circular structure.

[0013] Optionally, extracting subgraph features from the knowledge subgraph includes: querying the connection relationship between each node in the knowledge subgraph and constructing an adjacency tensor matrix; extracting the features of the nodes in the knowledge subgraph and constructing a node feature matrix; extracting the features of the edges in the knowledge subgraph and constructing an edge feature matrix; and combining the adjacency tensor matrix, the node feature matrix and the edge feature matrix into the subgraph features.

[0014] Optionally, the cardinality determination model is constructed using a graph convolutional network with a parameter sharing mechanism; the cardinality determination model includes an input layer, a graph convolutional layer, a fully connected layer and an output layer; the training samples of the cardinality determination model are derived from the data volume of historical query statements and corresponding query results.

[0015] Optionally, before extracting subgraph features from the knowledge subgraph, the method further includes: classifying the nodes and edges in the knowledge subgraph, encoding the nodes and the edges according to the classification results, and obtaining an encoded knowledge subgraph.

[0016] Optionally, the first query statement is optimized and updated according to the data volume of the query results, including: obtaining the query complexity of the first query statement in the knowledge graph according to the data volume of the query results; and optimizing the query strategy of the first query statement according to the query complexity.

[0017] According to a second aspect of an embodiment of the present invention, there is provided an information query device, including:

[0018] A query information acquisition module, used to acquire a first query statement, and determine a query condition and a query logic structure according to the first query statement;

[0019] A knowledge subgraph extraction module, used to extract target nodes and target edges from the knowledge graph according to the query conditions and the query logical structure, and form a knowledge subgraph;

[0020] A data volume determination module, configured to extract subgraph features from the knowledge subgraph, input the query condition and the subgraph features into a preset cardinality determination model, and obtain the data volume of the query result corresponding to the first query statement output by the cardinality determination model;

[0021] The information optimization query module is used to optimize and update the first query statement according to the data volume of the query result to obtain a second query statement, and use the second query statement to perform information query.

[0022] According to a third aspect of an embodiment of the present invention, there is provided an electronic device for information query, including:

[0023] one or more processors;

[0024] a storage device for storing one or more programs,

[0025] When the one or more programs are executed by the one or more processors, the one or more processors implement the method provided in the first aspect of the embodiment of the present invention.

[0026] According to a fourth aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored, and when the program is executed by a processor, the method provided by the first aspect of the embodiment of the present invention is implemented.

[0027] According to a fifth aspect of an embodiment of the present invention, there is provided a computer program product, including a computer program, wherein when the computer program is executed by a processor, the method provided in the first aspect of the embodiment of the present invention is implemented.

[0028] An embodiment of the invention has the following advantages or beneficial effects: by obtaining a first query statement, determining the query conditions and the query logic structure according to the first query statement; extracting the target nodes and target edges from the knowledge graph according to the query conditions and the query logic structure, and forming a knowledge subgraph; extracting subgraph features from the knowledge subgraph, inputting the query conditions and the subgraph features into a preset cardinality determination model, and obtaining the data volume of the query result corresponding to the first query statement output by the cardinality determination model; optimizing and updating the first query statement according to the data volume of the query result to obtain the second query statement, and using the second query statement to perform information query. The technical solution realizes a query optimization method based on the data volume of the query result, obtains the accurate data volume of the query result through the construction of the knowledge subgraph and the extracted subgraph features, and then optimizes the first query statement, ensuring that the information query using the optimized second query statement has better query performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.

[0030] Figure 1 is a schematic diagram of the main process of the information query method according to an embodiment of the present invention;

[0031] Figure 2 is a flow chart of an information query method according to a reference embodiment of the present invention;

[0032] FIG. 3( a ), FIG. 3( b ) and FIG. 3( c ) are schematic diagrams of a query logic structure according to an embodiment of the present invention;

[0033] Figure 4 It is a schematic diagram of the overall process of the information query method according to an embodiment of the present invention;

[0034] Figure 5 is a schematic diagram of main modules of an information query device according to an embodiment of the present invention;

[0035] Figure 6 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;

[0036] Figure 7 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION

[0037] It should be noted that the acquisition, storage and application of user personal information involved in the technical solution of the present disclosure are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.

[0038] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0039] When dealing with complex knowledge graphs, various existing information query methods are unable to accurately predict the data volume of the query results, which affects the formulation of query strategies and leads to poor query performance and cannot meet practical applications well.

[0040] In order to solve the above-mentioned problems existing in the prior art, the present invention proposes an information query method, which extracts and constructs a knowledge subgraph that meets the query requirements from a knowledge graph based on the query conditions and query logic structure obtained by a first query statement, and determines the data volume of the query result by using a cardinality determination model according to the subgraph features and query conditions of the knowledge subgraph. Finally, the data volume of the query result is used to optimize the first query statement, and the optimized second query statement is used to perform information query, thereby realizing a query optimization based on the data volume of the query result. By constructing a knowledge subgraph and extracting subgraph features, an accurate data volume of the query result is obtained, thereby optimizing the first query statement, and ensuring that the information query using the optimized second query statement has better query performance.

[0041] Figure 1 is a schematic diagram of the main process of the information query method according to an embodiment of the present invention, such as Figure 1 As shown, the information query method of the embodiment of the present invention includes the following steps S101 to S103.

[0042] Step S101: Obtain a first query statement, and determine a query condition and a query logic structure according to the first query statement.

[0043] Specifically, when the query system receives a query request for the knowledge graph, it obtains the first query statement contained therein by parsing the query request. The first query statement is usually written in a standard query language. The first query statement is an important way for the information demander to retrieve the knowledge graph and obtain the information therein. The first query statement contains specific query conditions and query logic structures, where the query conditions can be variable names or expressions of variable names. The query logic structure is the morphological structure formed by the query logic when executing the query conditions, such as chain queries, star queries, etc. In essence, the query conditions represent the elements of the first query statement at the content level, and the query logic structure represents the morphological structure of the first query statement at the query logic level.

[0044] Step S102: extract target nodes and target edges from the knowledge graph according to the query conditions and the query logical structure, and form a knowledge subgraph.

[0045] Specifically, considering that the knowledge graph is usually a comprehensive and complete network representation of the relationship between entities, such as a social network knowledge graph that includes community users and the relationship between each community user. The role of the first query statement is to query and retrieve specific entities and / or the relationship between entities from the knowledge graph, that is, the first query statement usually only involves a certain area in the knowledge graph. Taking the above-mentioned community network knowledge graph as an example, the first query statement only needs to query the friends of user A. In this case, in order to improve the query efficiency and simplify the calculation, the characteristics of the query elements involved in the query conditions, for example, in the knowledge graph including different types of nodes, determine the nodes in the knowledge graph that are consistent with the type characteristics, and the associated edges according to the type characteristics of the query elements. For example, the nodes of the knowledge graph include nodes of the character type and nodes of the address type. When only the character variable is involved in the first query statement, the character type node in the knowledge graph is used as the target node, and the corresponding edge related to the target node is used as the target edge. Then, combined with the query logic structure of the first query statement, the target node and the target edge are combined into a node relationship graph according to the query logic structure. Since the node relationship graph comes from the knowledge graph, the embodiment of the present invention defines the node relationship graph as a knowledge subgraph.

[0046] According to one embodiment of the present invention, target nodes and target edges are extracted from the knowledge graph according to the query conditions and the query logical structure, and a knowledge subgraph is formed, including: extracting target nodes and target edges that match the query conditions from the knowledge graph; and structurally integrating the target nodes and the target edges according to the query logical structure to obtain a knowledge subgraph.

[0047] Specifically, although the above method of determining the target node and target edge in the knowledge graph by the type characteristics of the query elements involved in the query conditions can narrow the query scope from the knowledge graph, the accuracy is not enough. The embodiment of the present invention further narrows the query scope and directly extracts the target node and target edge from the query elements contained in the query conditions themselves. Query and extract nodes that completely match the query elements in the query conditions from the knowledge graph as target nodes, and accordingly, the edges connected to the target nodes are target edges. Still taking the above as an example, the nodes of the knowledge graph include nodes of various characters and nodes of addresses, and the query conditions include Zhang San and Li Si, then the nodes that are the same as Zhang San and Li Si are searched from the knowledge graph as target nodes, and the edges connected to the nodes of Zhang San and Li Si are used as target edges. Finally, the target nodes and target edges are integrated according to the query logic structure of the first query statement, for example, the target nodes and target edges are integrated into a chain structure to obtain the knowledge subgraph associated with the first query statement extracted from the knowledge graph.

[0048] Step S103: extract subgraph features from the knowledge subgraph, input the query conditions and the subgraph features into a preset cardinality determination model, and obtain the data volume of the query results corresponding to the first query statement output by the cardinality determination model.

[0049] Specifically, based on the knowledge subgraph determined from the knowledge graph by the query conditions and the query logic structure, a cardinality determination model for evaluating the data volume of the query result is pre-constructed using the learning ability of the machine learning model and the estimation ability based on the learning ability. The cardinality of the embodiment of the present invention is the query cardinality, that is, the data volume of the query result. For example, if the query result is that there are 100 employees with the surname Zhang in the knowledge graph of employees, then these 100 are the data volume of the query result, also called the query cardinality.

[0050] Furthermore, subgraph features that can characterize the knowledge subgraph are extracted from the knowledge subgraph, such as the number of nodes, the number of edges, the content of the nodes, the meaning represented by the edges, and other information to form subgraph features, that is, data representation of the knowledge subgraph. The above query conditions and subgraph features are then input into the cardinality determination model, which captures the relationship between each node in the knowledge subgraph, estimates the current query cardinality in combination with the query conditions, and outputs the data volume of the query result corresponding to the first query statement.

[0051] According to one embodiment of the present invention, the cardinality determination model is constructed using a graph convolutional network with a parameter sharing mechanism; the cardinality determination model includes an input layer, a graph convolutional layer, a fully connected layer and an output layer; the training samples of the cardinality determination model are derived from the data volume of historical query statements and corresponding query results.

[0052] Specifically, considering that the query object of the embodiment of the present invention is graph data, in order to improve the efficiency and accuracy of the analysis and processing of graph data, the embodiment of the present invention adopts a graph convolutional network (GCN) to construct a cardinality determination model. The graph convolutional neural network can effectively capture local features in the graph through convolution operations and aggregate the neighbor information of the node. This feature makes the graph convolutional network particularly suitable for processing graph-based tasks. The graph convolutional network can effectively aggregate the feature information of the node with the information of its neighbor nodes, thereby generating a richer node representation, which is particularly important for the task of estimating the query cardinality, because the query cardinality often depends on the features of the node and its neighbor nodes in the graph. In addition, the graph convolutional network using a parameter sharing mechanism can effectively reduce the number of model parameters and is more computationally efficient than a fully connected network. For example, convolution kernel sharing can efficiently aggregate nodes and their neighbor nodes while maintaining high computational efficiency and generalization capabilities, thereby ensuring that the technical determination model has a high estimation accuracy.

[0053] The cardinality determination model constructed by the graph convolutional network based on the parameter sharing mechanism in the embodiment of the present invention mainly comprises an input layer, three graph convolutional layers, two fully connected layers and an output layer. Among them, the graph convolutional layer is mainly used to extract and abstract high-order features in the knowledge subgraph, the fully connected layer is used to further process the high-order features output by the graph convolutional layer, and the output layer uses an activation function to scale the final estimated query cardinality.

[0054] It can be understood that the cardinality determination model of the embodiment of the present invention is determined after sample data training converges. The cardinality determination initial model is pre-built before information query, and historical query statements are selected from historical data as query samples, and together with the corresponding knowledge subgraph, and the data volume of the final query result, a training sample set is constructed. The training sample set is used to train the cardinality determination initial model, and the gradient of the loss function to the model parameters is calculated through the back propagation algorithm. The parameters of the cardinality determination initial model are adjusted and updated. When the training converges, a cardinality determination model that can be used to estimate the query cardinality (the data volume of the query result) is obtained. The loss function is as follows:

[0055]

[0056] Among them, the loss function is the amount of data for the predicted query result of the i-th sample, y i is the data volume of the real query result of the i-th sample, and N is the total number of samples. The parameter adjustment update formula of the back propagation algorithm is:

[0057]

[0058] Among them, θ is the model parameter and η is the learning rate.

[0059] Step S104: Optimize and update the first query statement according to the data volume of the query result to obtain a second query statement, and use the second query statement to perform information query.

[0060] Specifically, according to the data volume of the query results estimated by the above-mentioned cardinality determination model, the corresponding feasible query execution strategy of the current first query statement is determined. In most cases, the first query statement contains a complete query execution strategy for a query. Of course, due to the unknown query results, the query execution strategy in the first query statement is often the initial query execution strategy. After obtaining the data volume of the query results, the initial query execution strategy can be adjusted. For example, when the data volume of the query results is large, the initial query execution strategy can be modified to a multi-task block query execution strategy to improve efficiency without consuming too many resources. And according to the adjusted query execution strategy, the initial query execution strategy in the first query statement is optimized and updated to obtain a second query statement, that is, the second query statement is the preferred query statement after the first query statement is optimized and updated based on the data volume of the query results. Finally, the second query statement is used to query information from the knowledge subgraph to obtain the required query results.

[0061] Figure 2 is a flow chart of an information query method according to a reference embodiment of the present invention. As another embodiment of the present invention, Figure 2 As shown, the information query method may include:

[0062] Step S201: Obtain a first query statement, and determine a query condition and a query logic structure according to the first query statement.

[0063] Specifically, considering that knowledge graphs usually use the Resource Description Framework (RDF) for data representation, based on the RDF data model, the knowledge graph can be composed of pieces of knowledge, each piece of knowledge represents a triple, and the triple, as the core concept of RDF, specifically refers to two physical objects and the relationship between them (subject, predicate, object). Accordingly, on this basis, the present invention uses a standard query language commonly used in the RDF data model to construct the first query statement, such as SPARQL.

[0064] For the first query statement using SPARQL, its main components are as follows:

[0065] SELECT? a? b? c

[0066] WHERE{

[0067] ? a<predicate1>?b.

[0068] ?b <predicate1>? c.

[0069] }

[0070] Among them, SELECT indicates specifying the variables to be returned, and WHERE indicates the query mode, which is specifically used to clarify the query conditions in the knowledge graph RDF to be queried.

[0071] Furthermore, the WHERE part in the first SPARQL query statement is the key information of the query, which may include one or more query conditions, such as the above example? a <predicate1>?b and ?b <predicate1>c. Since all query conditions serve the query requirements of the first query statement, there are inevitably connections between the query conditions. Such connections between the query conditions are the query logic structure of the embodiment of the present invention.

[0072] Step S202, obtain a query triple from the query condition; search for a target triple that matches the query triple from the knowledge triples corresponding to the knowledge graph; determine the corresponding target node and target edge based on the target triple; structurally integrate the target node and target edge according to the query logical structure to obtain a knowledge subgraph, and the query logical structure includes at least one of a star structure, a chain structure and a circular structure.

[0073] Specifically, through the above analysis, it can be seen that for each query condition obtained from the first query statement, the relationship between the query elements and the query elements is similar to the triple in RDF, so the embodiment of the present invention parses the subject, predicate and object from the query condition to obtain the corresponding query triple, such as the above? a <predicate1>In ? b, ? a corresponds to the subject of the triple, ? b corresponds to the object of the triple, <predicate1>Corresponds to the predicate between subject and object.

[0074] At the same time, the nodes and edges in the knowledge graph are parsed, and the relationship between each edge and each node is recorded to construct the knowledge triples corresponding to the knowledge graph. On the premise that the query triple corresponding to the query condition of the first query basis and the knowledge triple corresponding to the knowledge graph are known, the target triple matching the query triple is searched from the knowledge triple, and then according to the target triple, the subject and object contained therein, as well as the corresponding predicate, are summarized, and the subject and object are used as the target node, and the predicate is used as the corresponding target edge.

[0075] Furthermore, based on the above analysis, it can be known that one query condition corresponds to one query triple, and the query triple includes a subject, an object, and the relationship between the subject and the object. In view of the fact that each query condition jointly serves the query requirements of the first query statement, there may be some connections between the subject and the object of the query triple corresponding to each query condition. The connection between the subject and the object of these query triples constitutes the query logical structure of the embodiment of the present invention.

[0076] FIG3(a), FIG3(b) and FIG3(c) are schematic diagrams of the query logic structure of an embodiment of the present invention. FIG3(a) is a star structure. It can be seen that the query logic of the star structure is that each query triple shares the subject X, and each corresponding object is the end point of the query and is no longer further connected to the subject of other query triples, for example: ? x <predicate1>?y and ?x <predicate2>? z have the same subject ? x. The subject and object nodes of these query triples form a star structure. Figure 3(b) shows a chain structure. It can be seen that the query logic of the chain structure is that the subject and object of each query triple are connected in a chain, and the query is performed one by one. The subject of the previous query triple and the object of the next query triple share variables, for example: ? x <predicate1>?y and?y <predicate2>? z, the subject and object nodes of these query triples form a chain structure. Figure 3(c) shows a loop structure. It can be seen that the query logic of the loop structure is that the query of each query triple forms a closed loop, that is, from the query starting point to the query starting point. For example: ? x <predicate1>?z and?z <predicate2>?y and?y <predicate1>? x, the subject and object nodes of these query triples form a circular structure.

[0077] Of course, the query logic structure may be one of the star structure, chain structure and loop structure, or a combination of these structures, such as a combination of a star structure and a chain structure. This is not specifically limited in the embodiments of the present invention.

[0078] Furthermore, according to the query logic structure of the first query statement and combined with the relationship between each target node, the target nodes and target edges obtained by the above triple matching are organized and structurally integrated, and finally a knowledge subgraph containing target nodes and target edges consistent with the query logic structure is obtained.

[0079] Step S203: classify the nodes and edges in the knowledge subgraph, and encode the nodes and edges according to the classification results to obtain an encoded knowledge subgraph.

[0080] Specifically, based on the knowledge subgraph obtained by the above extraction and integration, in order to facilitate the subsequent extraction of subgraph features and simplify data processing and storage, all nodes in the knowledge subgraph are classified, and according to the preset coding rules, the coding method of the category corresponding to each node in the coding rules is found to obtain the coding of each node. For example, for the nodes of the character type, the coding method agreed in the coding rules is category 3_character serial number, and for the nodes of the address type, the coding method agreed in the coding rules is category 5_serial number corresponding to the address longitude and latitude. Similarly, the edges between the nodes are also classified in terms of relationship, and the coding method of the attribution relationship agreed in the coding rules is category 9. Accordingly, the attribution direction between the two nodes is defined in two numerical values, for example, the subject belongs to the object as a numerical value of 1, and the object belongs to the subject as a numerical value of 0, then there is a complete subject belonging to the object relationship encoded as 91. Preferably, the nodes and edges in the knowledge subgraph are encoded as integers, and a global mapping table is established, which can greatly simplify the subsequent data processing and save computing resources. The nodes and edges in the knowledge subgraph are encoded one by one or in batches according to type to obtain the encoded knowledge subgraph.

[0081] Step S204, query the connection relationship between each node in the knowledge subgraph and construct an adjacency tensor matrix; extract the features of the nodes in the knowledge subgraph and construct a node feature matrix; extract the features of the edges in the knowledge subgraph and construct an edge feature matrix; combine the adjacency tensor matrix, the node feature matrix and the edge feature matrix into the subgraph features.

[0082] Specifically, the above-encoded knowledge subgraph facilitates the extraction of subgraph features. The embodiment of the present invention constructs a three-dimensional adjacency tensor matrix A. Each element in the adjacency tensor matrix indicates whether there is a certain type of edge between two nodes. For example, if there is an edge of type k between node i and node j, then the value of A[i,j,k] is 1, otherwise it is 0, and there are:

[0083]

[0084] Among them, the type of edge is determined according to the content of the specific knowledge graph. For example, in the personnel relationship knowledge graph, the relationship types can be divided into friend relationships, family relationships, and employment relationships. Accordingly, corresponding indexes 0, 1, and 2 can be assigned to different types.

[0085] At the same time, extract the features of the nodes in the knowledge subgraph and construct the node feature matrix X. The node feature matrix is ​​used to represent the type or attribute of the node. Specifically, one-hot encoding or binary encoding can be used to represent the type or attribute of the node. If one-hot encoding is used to represent the node type or attribute, each node is represented by a vector. The length of the vector is equal to the number of intersection types or attributes. Only one position is 1, and the rest are 0. If binary encoding is used, each node is represented by a binary vector, which can greatly reduce the space occupied. The specific elements in X are:

[0086]

[0087] Among them, the type or attribute of the node is also determined according to the content of the specific knowledge graph. For example, the knowledge graph of personnel's work and residence contains node types including staff nodes and address nodes, and the corresponding node types are 0 and 1 respectively.

[0088] The construction of the edge feature matrix E is similar to the construction method of the node feature matrix X. The specific elements in the edge feature matrix E are:

[0089]

[0090] Through the above construction of the adjacency tensor matrix A, the node feature matrix X and the edge feature matrix E, it can be seen that the adjacency tensor matrix A reflects the connection relationship between the nodes in the knowledge subgraph, the node feature matrix X reflects the type or attribute information of the nodes in the knowledge subgraph, so as to help the cardinality determination model distinguish different node roles, and the edge feature matrix E reflects the type of edges in the knowledge subgraph, which is used to supplement the connection details of the adjacency tensor matrix.

[0091] Finally, the adjacency tensor matrix A, node feature matrix X, and edge feature matrix E are used as subgraph features of the knowledge subgraph.

[0092] Step S205: input the query condition and the subgraph feature into a preset cardinality determination model to obtain the data volume of the query result corresponding to the first query statement output by the cardinality determination model.

[0093] Specifically, considering that the query object of the embodiment of the present invention is graph data, a graph convolutional network is selected to construct a cardinality determination model, which includes an input layer, a graph convolutional layer, a fully connected layer, and an output layer. The query condition Q, the adjacency tensor matrix A, the node feature matrix X, and the edge feature matrix E are input into the input layer of the cardinality determination model, and the specific formula of the graph convolutional layer can be obtained as follows:

[0094] H (l+1) =σ(A,H (l) , E (l) , Q, W (l) ),

[0095] Among them, H (1) is the node feature matrix of the (l)th layer (H^{(0)}=X), W (l) is the weight matrix, and σ is the activation function σ(x)=max(0,x). The next level of fully connected layer is used to further process the features extracted by the graph convolution layer. Accordingly, the output of the Lth fully connected layer is:

[0096] Z (l+1) =σ(Z (l) W (l) +b (l) ),

[0097] Where Z (l) is the input feature matrix of the lth layer, W (l) is the weight matrix of the lth layer, b (l) is the bias vector of the lth layer, and σ is the activation function. Finally, the output layer uses the sigmoid function to scale the output value to between 0 and 1, which is used to estimate the data volume of the query result. The formula of the output layer is:

[0098]

[0099] in is the predicted value of the model (the amount of data in the query result), Z (L) is the output feature matrix of the last fully connected layer, W (L) is the weight matrix of the output layer, b (L) is the bias vector of the output layer, is the sigmoid function.

[0100] Step S206: Obtain the query complexity of the first query statement in the knowledge graph based on the data volume of the query result; optimize the query strategy of the first query statement based on the query complexity to obtain a second query statement, and use the second query statement to perform information query.

[0101] Specifically, the data volume of the query results output by the model is determined according to the above cardinality, the query complexity of the current first query statement is obtained, and the database optimizer is called to optimize the query strategy of the query plan in the first query statement according to the query complexity. For example, the above-mentioned block partitioning query strategy is used to replace the direct query strategy in the first query statement to obtain the second query statement, and then the optimized second query statement is used to perform information query.

[0102] The embodiment of the present invention utilizes the query triples and query logic structure corresponding to the query conditions to accurately and efficiently extract and construct a knowledge subgraph related to the first query statement from the knowledge graph, and then extracts subgraph features (adjacency tensor matrix, node feature matrix and edge feature matrix) from the knowledge subgraph, and then uses the cardinality determination model constructed by the graph convolutional network to estimate the data volume of the query result corresponding to the first query statement, optimize the first query statement, and obtain the second query statement for information query. Based on the constructed knowledge subgraph with high accuracy and comprehensive and complete subgraph features, a machine learning algorithm is used to accurately estimate the data volume of the query result, so as to achieve the purpose of optimizing information query based on the data volume of the query result and improving the efficiency of information query.

[0103] Figure 4 It is a schematic diagram of the overall process of the information query method of an embodiment of the present invention. First, a first query statement with a query logic structure is obtained, and the first query statement is parsed by a query parser to obtain the query conditions and query logic structure therein. Then, according to the query conditions and query logic structure, the target nodes and target edges are extracted from the data set composed of the knowledge graph, and a knowledge subgraph is formed. Then, subgraph features (adjacency tensor matrix, node feature matrix and edge feature matrix) are extracted from the knowledge subgraph, and the query conditions and subgraph features are input into the cardinality determination model constructed by the graph convolutional network to obtain the data volume of the query result corresponding to the first query statement output by the cardinality determination model. Finally, the query optimizer is called to adjust the query strategy of the first query statement according to the data volume of the query result, to obtain the optimized second query statement, and the second query statement is used to perform information query through the query execution engine to obtain the query result of this information query.

[0104] Figure 5 Schematic diagram of the main modules of the information query device according to an embodiment of the present invention. Figure 5 As shown, the information query device 500 mainly includes a query information acquisition module 501, a knowledge subgraph extraction module 502, a data volume determination module 503 and an information optimization query module 504.

[0105] The query information acquisition module 501 is used to acquire a first query statement and determine a query condition and a query logic structure according to the first query statement;

[0106] A knowledge subgraph extraction module 502 is used to extract target nodes and target edges from the knowledge graph according to the query conditions and the query logical structure, and form a knowledge subgraph;

[0107] A data volume determination module 503 is used to extract subgraph features from the knowledge subgraph, input the query condition and the subgraph features into a preset cardinality determination model, and obtain the data volume of the query result corresponding to the first query statement output by the cardinality determination model;

[0108] The information optimization query module 504 is used to optimize and update the first query statement according to the data volume of the query result to obtain a second query statement, and use the second query statement to perform information query.

[0109] According to one embodiment of the present invention, the knowledge subgraph extraction module 502 is further used to: extract target nodes and target edges that match the query conditions from the knowledge graph; and structurally integrate the target nodes and the target edges according to the query logical structure to obtain a knowledge subgraph.

[0110] According to another embodiment of the present invention, the knowledge subgraph extraction module 502 is further used to: obtain a query triple from the query condition; search for a target triple that matches the query triple from the knowledge triples corresponding to the knowledge graph; determine the corresponding target node and target edge based on the target triple; structurally integrate the target node and target edge according to the query logical structure to obtain a knowledge subgraph, and the query logical structure includes at least one of a star structure, a chain structure and a circular structure.

[0111] According to another embodiment of the present invention, the data amount determination module 503 is also used to: query the connection relationship between each node in the knowledge subgraph and construct an adjacency tensor matrix; extract the features of the nodes in the knowledge subgraph and construct a node feature matrix; extract the features of the edges in the knowledge subgraph and construct an edge feature matrix; and combine the adjacency tensor matrix, the node feature matrix and the edge feature matrix into the subgraph features.

[0112] According to another embodiment of the present invention, the cardinality determination model is constructed using a graph convolutional network with a parameter sharing mechanism; the cardinality determination model includes an input layer, a graph convolutional layer, a fully connected layer and an output layer; the training samples of the cardinality determination model are derived from the data volume of historical query statements and corresponding query results.

[0113] According to another embodiment of the present invention, the information query device 500 also includes an encoding module (not shown in the figure), which is used to: classify the nodes and edges in the knowledge subgraph before extracting subgraph features from the knowledge subgraph, and encode the nodes and the edges according to the classification results to obtain an encoded knowledge subgraph.

[0114] According to another embodiment of the present invention, the information optimization query module 504 is further used to: obtain the query complexity of the first query statement in the knowledge graph according to the data volume of the query result; and optimize the query strategy of the first query statement according to the query complexity.

[0115] Figure 6 is an exemplary system architecture diagram to which embodiments of the present invention can be applied.

[0116] like Figure 6 As shown, system architecture 600 may include terminal devices 601, 602, 603, network 604 and server 605. Network 604 is used to provide a medium for communication links between terminal devices 601, 602, 603 and server 605. Network 604 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.

[0117] Users can use terminal devices 601, 602, 603 to interact with server 605 through network 604 to receive or send messages, etc. Various communication client applications, such as information query applications, etc., can be installed on terminal devices 601, 602, 603 (only as an example).

[0118] The terminal devices 601 , 602 , and 603 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers, etc.

[0119] Server 605 may be a server that provides various services, such as a background management server that provides support for information queries performed by users using terminal devices 601, 602, and 603 (for example only). The background management server may obtain a first query statement, and determine the query conditions and query logic structure according to the first query statement; extract target nodes and target edges from the knowledge graph according to the query conditions and the query logic structure, and form a knowledge subgraph; extract subgraph features from the knowledge subgraph, input the query conditions and the subgraph features into a preset cardinality determination model, and obtain the data volume of the query result corresponding to the first query statement output by the cardinality determination model; optimize and update the first query statement according to the data volume of the query result to obtain a second query statement, use the second query statement to perform information query and other processing, and feed back the processing results to the terminal device.

[0120] It should be noted that the information query method provided in the embodiment of the present invention is generally executed by the server 605 , and accordingly, the information query device is generally arranged in the server 605 .

[0121] It should be understood that Figure 6 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0122] Reference below Figure 7 , Figure 7 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. Figure 7 The terminal device or server shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0123] like Figure 7 As shown, the computer system 700 includes a central processing unit (CPU) 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage part 708 into a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the system 700 are also stored. The CPU 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.

[0124] The following components are connected to the I / O interface 705: an input section 706 including a keyboard, a mouse, etc.; an output section 707 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 708 including a hard disk, etc.; and a communication section 709 including a network interface card such as a LAN card, a modem, etc. The communication section 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the I / O interface 705 as needed. A removable medium 711, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 710 as needed, so that a computer program read therefrom is installed into the storage section 708 as needed.

[0125] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 709, and / or installed from the removable medium 711. When the computer program is executed by the central processing unit (CPU) 701, the above-mentioned functions defined in the system of the present invention are executed.

[0126] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination thereof.

[0127] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a sequence different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0128] The units involved in the embodiments of the present invention may be implemented by software or hardware. The units described may also be set in a processor, for example, may be described as: a processor including: a query information acquisition module, a knowledge subgraph extraction module, a data volume determination module and an information optimization query module.

[0129] Among them, the names of these modules do not constitute a limitation on the modules themselves in some cases. For example, the query information acquisition module can also be described as "a module for obtaining a first query statement and determining a query condition and a query logical structure based on the first query statement."

[0130] On the other hand, the present invention also provides a computer-readable medium, which may be included in the device described in the embodiment; or it may exist independently without being assembled into the device. The computer-readable medium carries one or more programs, and when the one or more programs are executed by a device, the device includes: obtaining a first query statement, determining a query condition and a query logic structure according to the first query statement; extracting target nodes and target edges from a knowledge graph according to the query condition and the query logic structure, and forming a knowledge subgraph; extracting subgraph features from the knowledge subgraph, inputting the query condition and the subgraph features into a preset cardinality determination model, and obtaining the data volume of the query result corresponding to the first query statement output by the cardinality determination model; optimizing and updating the first query statement according to the data volume of the query result, obtaining a second query statement, and using the second query statement to perform information query.

[0131] According to the technical solution of the embodiment of the present invention, it has the following advantages or beneficial effects: by obtaining a first query statement, determining the query conditions and the query logic structure according to the first query statement; extracting the target nodes and target edges from the knowledge graph according to the query conditions and the query logic structure, and forming a knowledge subgraph; extracting subgraph features from the knowledge subgraph, inputting the query conditions and the subgraph features into a preset cardinality determination model, and obtaining the data volume of the query result corresponding to the first query statement output by the cardinality determination model; optimizing and updating the first query statement according to the data volume of the query result to obtain the second query statement, and using the second query statement to perform information query. The technical solution realizes a query optimization based on the data volume of the query result, obtains the accurate data volume of the query result through the construction of the knowledge subgraph and the extracted subgraph features, and then optimizes the first query statement, ensuring that the information query using the optimized second query statement has better query performance.

[0132] The specific implementation methods described herein do not constitute limitations on the scope of protection of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention shall be included in the scope of protection of the present invention.

Claims

1. An information query method, characterized in that: include: Obtaining a first query statement, and determining a query condition and a query logic structure according to the first query statement; According to the query condition and the query logic structure, target nodes and target edges are extracted from the knowledge graph and formed into a knowledge subgraph; Extracting subgraph features from the knowledge subgraph, inputting the query condition and the subgraph features into a preset cardinality determination model, and obtaining a data volume of a query result corresponding to the first query statement output by the cardinality determination model; According to the data volume of the query result, the first query statement is optimized and updated to obtain a second query statement, and the second query statement is used to perform information query.

2. The method according to claim 1, characterized in that According to the query condition and the query logic structure, target nodes and target edges are extracted from the knowledge graph and a knowledge subgraph is formed, including: Extract target nodes and target edges that match the query conditions from the knowledge graph; and perform structural integration on the target nodes and target edges according to the query logic structure to obtain a knowledge subgraph.

3. The method according to claim 2, characterized in that Extracting target nodes and target edges matching the query condition from the knowledge graph; and structurally integrating the target nodes and the target edges according to the query logic structure to obtain a knowledge subgraph, including: Obtaining a query triple from the query condition; Searching for a target triple that matches the query triple from the knowledge triples corresponding to the knowledge graph; According to the target triplet, determine the corresponding target node and target edge; The target nodes and target edges are structurally integrated according to the query logic structure to obtain a knowledge subgraph, wherein the query logic structure includes at least one of a star structure, a chain structure, and a loop structure.

4. The method according to claim 1, characterized in that: Extracting subgraph features from the knowledge subgraph includes: Query the connection relationship between each node in the knowledge subgraph and construct an adjacency tensor matrix; Extracting features of nodes in the knowledge subgraph and constructing a node feature matrix; Extracting the features of the edges in the knowledge subgraph and constructing an edge feature matrix; The adjacency tensor matrix, the node feature matrix and the edge feature matrix are combined into the subgraph feature.

5. The method according to claim 1, characterized in that The cardinality determination model is constructed using a graph convolutional network with a parameter sharing mechanism; the cardinality determination model includes an input layer, a graph convolutional layer, a fully connected layer and an output layer; the training samples of the cardinality determination model come from the data volume of historical query statements and corresponding query results.

6. The method according to claim 1, characterized in that Before extracting subgraph features from the knowledge subgraph, the method further includes: The nodes and edges in the knowledge subgraph are classified, and the nodes and edges are encoded according to the classification results to obtain an encoded knowledge subgraph.

7. The method according to claim 1, characterized in that Optimizing and updating the first query statement according to the data volume of the query result includes: Obtaining the query complexity of the first query statement in the knowledge graph according to the data volume of the query result; According to the query complexity, query strategy optimization is performed on the first query statement.

8. An information query device, characterized in that: include: A query information acquisition module, used to acquire a first query statement, and determine a query condition and a query logic structure according to the first query statement; A knowledge subgraph extraction module, used to extract target nodes and target edges from the knowledge graph according to the query conditions and the query logical structure, and form a knowledge subgraph; A data volume determination module, configured to extract subgraph features from the knowledge subgraph, input the query condition and the subgraph features into a preset cardinality determination model, and obtain the data volume of the query result corresponding to the first query statement output by the cardinality determination model; The information optimization query module is used to optimize and update the first query statement according to the data volume of the query result to obtain a second query statement, and use the second query statement to perform information query.

9. A mobile electronic device terminal, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 7.

10. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

11. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.