A method and system for translating graph data query language for knowledge base question answering
Through the skeleton structure of the query statement encoding graph neural network, automatic translation from SPARQL to Cypher is realized, solving the high cost and inefficiency of query language migration in KBQA system, and improving the system's migrationability and translation accuracy.
Patent Information
- Application Number
- CN202310393777.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-13
- Publication Date
- 2025-07-25
- Estimated Expiration
- 2043-04-13
AI Technical Summary
During the migration process, especially the conversion between different query languages, existing KBQA systems have problems such as high cost of manual intervention, poor model migration, and poor translation effect of complex query statements.
The skeleton structure of the graph neural network encoding query statement is used to capture its structural semantic information, and the automatic translation from the source query language to the target query language is realized through the structure-to-sequence generation framework, which specifically includes parsing processing, graph structure encoding and sequence decoding processes.
It reduces the difficulty of training the translation model, saves labor costs, and improves the transferability of the KBQA system and the accuracy of query language translation.
Smart Images

Figure CN116521823B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to an encoding and generation method for a graph data query language in knowledge base question answering, and a translation method and system for graph data query languages for knowledge base question answering. Background Art
[0002] Knowledge Base Question Answering (KBQA) is a question answering system that queries knowledge from a knowledge base to answer users' questions. Most early KBQA systems used databases based on the RDF data format (such as Jena, Virtuoso, etc.), and obtained answers by converting the natural language (NL) questions input by users into query statements (Query Language, QL, such as SPARQL) and executing queries on the knowledge base. As a general resource description framework, RDF is widely used as the standard format for data exchange between various databases and is the preferred and most commonly used data format in data publishing and data sharing scenarios. With the development of database technology, more and more graph databases such as Neo4j, NebulaGraph, TigerGraph, and HugeGraph have been developed to meet the usage requirements of the new era for massive and complex data relationship operations. Taking Neo4j as an example, compared with the knowledge base storing data in the RDF format, the query efficiency of the Neo4j graph database is higher (under the same hardware configuration, more query statements can be executed per second, and the query speed is faster), the function of the Cypher query language supported by the Neo4j graph database is more flexible, the user interface is more friendly, and the user community is more active. Therefore, the migration work of KBQA systems between different databases has important value in both scientific research fields and industrial application scenarios. Generally, the migration of KBQA systems includes two aspects of work. First, the conversion between different knowledge base data storage formats, which can be easily completed by manually writing heuristic rules or existing plugins. For example, the format conversion between RDF data and Neo4j data can be easily achieved by automatically generating corresponding Cypher data operation statements according to the Schema of RDF data or using existing relatively mature open-source tools (such as the Neo4j plugin Neosemantics). Second, the conversion between the database query statements of different knowledge base question answering, such as the conversion between the SPARQL query statements supported by RDF data and the Cypher query statements supported by the Neo4j graph database. This is a relatively difficult task for the following reasons: (1) The syntax rules of different query statements vary greatly, and there is no obvious mapping correspondence, making it difficult to convert statements by manually constructing syntax translation rules; (2) The conversion of query statements can be regarded as a machine translation problem between different languages. However, there is a lack of sufficient alignment annotation data between different query languages, resulting in difficulty for machine translation models to obtain sufficient training and learning; (3) Current machine translation mostly uses neural network models based on the Seq2seq architecture, which focuses on modeling the sequence information of query statements and ignores the structural information of query statements, resulting in poor translation effects for longer and more complex query problems; (4) Query statements rely heavily on the Schema information of the knowledge base, and models trained on other knowledge bases cannot be directly applied to the current knowledge base for query statement translation and conversion.
[0003] Currently, the migration solutions between the query languages of different KBQA systems are mostly based on manual methods. This manual translation method requires high professional skills. One needs to have professional grammar knowledge of different query languages, be familiar with the Schema definitions of the current knowledge base, and be able to manually design complex conversion rules. Therefore, the cost of manual intervention is very high. In recent years, researchers have tried to adopt translation models based on deep learning (usually neural network translation models with the Seq2seq architecture). Neural network models mostly use, such as Bi-LSTM, Transformer, etc. for sequence information modeling. This type of method tokenizes the source query statement and inputs it into the encoder to obtain information representation, and then sequentially generates the characters of the target query statement at the decoder end. The disadvantages of this direct Seq2seq method are as follows: (1) The training of the model requires a large amount of labeled data (i.e., parallel corpora aligned with the source language - target language), resulting in a large labor cost; (2) The data Schema definitions in different knowledge bases are different, and it is difficult for the trained neural network translation model to be migrated to other knowledge bases with different Schema definitions, showing poor migration performance; (3) The neural network model can model the sequence information of the source query statement and serially generate the target query statement, but it ignores the structural information of the query statement, and the translation effect for long and complex query statements is very poor.
[0004] Table 1 gives an example of a piece of training data in a football vertical KBQA system, "Which players in a certain league (XLeague) are over 40 years old?" and its corresponding SPARQL and Cypher query statements respectively. The query idea for answering this question on the knowledge base is to find all the football players who are members of clubs in a certain league (X League), and return the query results after restricting their ages. The bold words in Table 1 are the keywords of the SPARQL and Cypher languages. The words starting with "?" in the SPARQL statement represent a (node or relationship) variable, and the symbols inside "<>" are the relationships between nodes; in the Cypher statement, (p:Player) represents a node of the Player entity type named p, and [:member_of] represents an edge of a "member of" relationship. According to the Schema definition of the knowledge base, it is easy to construct a mapping dictionary between entities and relationships in the SPARQL and Cypher query statements, as shown in the appendix Figure 2The entity mappings shown in, such as p:Player => <node_1> =>?p; c:Club => <node_2> =>?c, and relationship mappings, such as member_of => <pred_1>; of_league => <pred_2>, etc. Replace the entities and relationships in the SPARQL and Cypher statements with the mappings constructed previously, and then replace the query operators and query key strings with <operator> , <string>After special tags such as , the query skeletons corresponding to the two query statements are obtained and modeled in the form of a graph structure. Attached Figure 1 Figure a in the appendix is the structure diagram of the SPARQL statement, and Figure b is the structure diagram of its modeled query skeleton sequence without semantics; Attached Figure 2 Figure a in the appendix is the structure diagram of the Cypher statement, and Figure b is the structure diagram of its modeled query skeleton sequence without semantics; It can be observed that the two query statements have obvious similarities in structure. The rectangles in the figure represent the keywords of the query language, the circles represent the entities in the knowledge base, the diamonds represent the relationships in the knowledge base, and the rounded rectangles represent the custom special tags, where <num>And <op>Namely, special markings <number>and <operator>The abbreviated form. By comparing the graph structures of the query skeleton and the query statement, ignoring the SPARQL and Cypher syntax keywords, the skeleton structure information of the two query statements has a high degree of similarity. However, when the traditional Seq2seq neural translation model for sequence modeling translates query languages, it is usually difficult to effectively utilize the structural information of the query language.
[0005] Table 1: Data examples of natural language questions and corresponding two query statements in knowledge base question answering
[0006]
[0007] Summary of the Invention
[0008] The object of the present invention is to propose a translation method and system for graph data query languages (SPARQL, Cypher, and nGQL) for KBQA in view of the deficiencies of existing methods. This method uses a graph neural network to encode the skeleton structure of the query statement, captures its structural semantic information, and generates the target query statement end-to-end to achieve automatic translation from the source query language to the target query language. The present invention takes the conversion between the SPARQL query language supported by RDF data and the Cypher query language supported by the Neo4j graph database as an example to perform language translation from SPARQL to Cypher.
[0009] The specific technical solution for achieving the object of the present invention is as follows:
[0010] A graph data query language translation method for knowledge base question answering, the method comprising the following steps:
[0011] Step 1: Parse and process the SPARQL and Cypher statements to obtain the query skeleton sequence, the mapping dictionary for restoring the original query statement from the skeleton sequence, the graph structure of the query skeleton, and the translation vocabulary;
[0012] Step 2: Adopt a structure-to-sequence generation framework, input the query skeleton graph structure of the SPARQL statement obtained in Step 1 into a structure encoder based on a graph neural network, input the encoded representation of each node in the graph structure into a sequence decoder, and use the query skeleton sequence of the corresponding Cypher statement as the generation target for training to obtain a translation model f including a structure encoder and a sequence decoder θ ; wherein the graph neural network adopted by the structure encoder is GCN or GAT, and the neural network model adopted by the sequence decoder is GRU, LSTM or Transformer; the training adopts a cross-entropy loss function and updates the parameters of the encoder and decoder by the method of gradient descent;
[0013] Step 3: Parse and process the input source SPARQL statement according to Step 1, and input the graph structure of the obtained query skeleton into the translation model f obtained in Step 2 θ Generate the query skeleton sequence of the target Cypher statement, and restore the query skeleton sequence according to the mapping dictionary to obtain the target Cypher statement.
[0014] The specific steps of Step 1 are as follows:
[0015] Step a1: For each pair of SPARQL and Cypher statement pairs (s para with the same semantics in the parallel corpus Q i , c i ), use the grammar-based programming language parser antlr4 to parse the SPARQL statement s i and the Cypher statement c i into the smallest semantic units respectively, and obtain their respective corresponding semantic unit sequences and Use 5 special tokens (specialtoken) <node_n>, <pred_n>, <string> 、 <operator>and <number>Replace respectively and in the entities, relationships, strings, operators and numerical values, to obtain a sequence of SPARQL query skeletons composed of SPARQL language keywords and special tokens A sequence of Cypher query skeletons composed of Cypher language keywords and special tokens Using the special tokens used in the replacement process as keys and the semantic units to be replaced as values, obtain the mapping dictionary d i ;
[0016] Step a2: For the sequence of query skeletons of the SPARQL statement obtained in step a1 Regarding each semantic unit therein as a node, add connected edges between adjacent nodes according to the sequence order and logical structure of the query statement, to obtain a graph structure representation of the SPARQL statement query skeleton
[0017] Step a3: For all SPARQL and Cypher query skeleton sequences and Construct the translation vocabulary V; denote the set of SPARQL language keywords as K sp , the set of Cypher language keywords as K cy , and the set of special tokens as T mark , then V = K sp ∪ K cy ∪ T mark .
[0018] The specific steps of the second step are as follows:
[0019] Step b1: For the constructed translation vocabulary V, randomly initialize the word vectors of each word;
[0020] Step b2: Use the graph neural network GCN or GAT to encode the graph structure ;
[0021] Step b3: Use the node representations of the graph structure after being encoded by the graph neural network as the input of the sequence decoder, and generate the corresponding Cypher query skeleton sequence in an autoregressive decoding manner The neural network model adopted by the sequence decoder is GRU, LSTM or Transformer;
[0022] Step b4: For each SPARQL-Cypher statement pair in the parallel corpus Q para , calculate the cross-entropy loss at each step of the generation, and use the gradient descent method to optimize the model parameters to obtain the trained translation model f θ 。
[0023] Step three specifically includes the following steps:
[0024] Step c1: Process the input SPARQL statement q i , using the preprocessing method in Step one to obtain a mapping dictionary d and the graph structure representation of the query skeleton
[0025] Step c2: Input the graph structure representation of the query skeleton into the translation model f obtained in Step two θ to obtain the query skeleton sequence of the target Cypher statement
[0026] Step c3: According to the mapping dictionary d, restore the special tokens in the query skeleton sequence to specific semantic units to obtain the target Cypher statement
[0027] A graph data query language translation system based on the above method, including a preprocessing module, a source query language encoding module, and a target query language generation module;
[0028] The preprocessing module uses the open-source tool Neosemantics to convert the format of the knowledge base stored in the RDF form to obtain the knowledge base stored on the graph database Neo4j;
[0029] The source query language encoding module is used to parse and process the input SPARQL statement s i to obtain the query skeleton sequence the graph structure of the query skeleton and the mapping dictionary d for restoring from the skeleton sequence to the original query statement i ; Use a structure encoder based on a graph neural network to encode it to obtain a vector representation containing structural information;
[0030] The target query language generation module uses a sequence decoder to decode the vector representation containing structural information to obtain the query skeleton sequence of the target Cypher statement According to the mapping dictionary d i restore the special tokens in the skeleton sequence to specific semantic units to obtain the target Cypher statement c i ; Execute the obtained Cypher statement c i on the knowledge base and evaluate the translation effect of the query statement according to the correctness of the returned answer.
[0031] Differences between the present invention and the prior art: (1) Different from traditional translation models that only encode the sequence information of the input text, the method proposed in the present invention uses graph neural network technology to encode the structural semantic information of the source query language, and realizes translation between two languages through the conversion of the structure between the two query languages. (2) Different from traditional translation models that directly process the input text, the method proposed in the present invention replaces the unstructured semantic units in the input text with special tokens, and only performs structural conversion from the source language to the target language, greatly reducing the size of the vocabulary and significantly reducing the training difficulty. (3) Compared with the method of manual translation, the method proposed in the present invention uses a neural network model that can be trained end-to-end to automatically perform translation, without the need for personnel with professional grammar knowledge, and can effectively save labor costs.
[0032] The beneficial effects of the present invention include: The present invention proposes a method for translating graph data query languages for knowledge base question answering systems, which uses graph neural networks to encode the structural semantic information of source query statements, making up for the deficiency of traditional translation models that only consider the sequence information of input texts; the method proposed in the present invention can greatly reduce the size of the vocabulary of the translation model and reduce the training difficulty of the translation model; the method proposed in the present invention uses an end-to-end trainable neural network to realize the translation between graph database query languages, which can effectively save labor costs. The translation method between graph data query languages for knowledge base question answering (KBQA) breaks down the barriers to migration between different graph databases, provides more data resources for the research of KBQA systems, improves the portability of KBQA systems, and promotes the better and faster development of KBQA systems. Brief Description of the Drawings
[0033] Figure 1 It is the structure diagram of the SPARQL query statement in the background technology and the structure diagram of its query skeleton sequence;
[0034] Figure 2 It is the structure diagram of the Cypher query statement in the background technology and the structure diagram of its query skeleton sequence;
[0035] Figure 3 It is the flow chart of the method described in the present invention;
[0036] Figure 4 It is the schematic diagram of the system module described in the present invention. Detailed Embodiments
[0037] Combined with the following specific embodiments and drawings, the present invention will be further described in detail. The processes, conditions, experimental methods, etc. for implementing the present invention, except for the specifically mentioned content below, are all common knowledge and well-known common sense in the art, and the present invention has no special limitations.
[0038] The definitions of the professional terms involved in the present invention are as follows:
[0039] Knowledge Graph (KG): A web-based semantic knowledge base (KB) formed by linking entities through relationships, which describes concepts in the physical world and their interrelationships in symbolic form. In a knowledge graph, facts are usually represented in the form of triples (head entity, relationship, tail entity), often stored in the RDF (Resource Description Framework) format, and the corresponding query language is SPARQL. In RDF-formatted data, the tail entity can also be of types such as strings, numbers, dates, etc., rather than necessarily being an abstract entity object.
[0040] Graph database: A graph database is a new type of database implemented based on graph theory, and its database storage structure and data query method are both based on graphs. The basic elements of a graph are nodes and edges, which correspond to nodes and relationships in a graph database. The most widely used graph database currently is Neo4j, and the supported query languages include Cypher and GraphQL, etc. Among them, Cypher is a query language specifically designed for Neo4j by developers. In addition, there are also graph databases such as NebulaGraph using the nGQL query language and HugeGraph using the Gremlin query language.
[0041] Graph Neural Network (GNN): A graph neural network is an artificial neural network structure used to process graph-structured data, and it has extensive applications in application scenarios such as knowledge graphs, social networks, and drug discovery; common graph neural network models include Graph Convolutional Network (GCN), Graph Attention Network (GAT), etc.
[0042] Refer to Figure 3 As shown, for the conversion between SPARQL and Cypher, taking the translation process from SPARQL to Cypher as an example (SPARQL is the source query language and Cypher is the target query language, and the translation process is similar vice versa), the input of the present invention is: (1) The set of SPARQL-Cypher data pairs (i.e., parallel corpus) Q para ={(s i , c i ) | i ∈ [1,..., N]}, where N is the number of SPARQL-Cypher data pairs, s i and c i respectively represent the i-th aligned SPARQL statement and Cypher statement, and alignment means that this pair of statements s i and c i have the same query semantics; (2) The source SPARQL query statement q i 。The output of the present invention is the target Cypher statement i with the same query semantics as q
[0043] The first step of the present invention is to parse and process SPARQL and Cypher data, and the specific process is described as follows:
[0044] Input: Parallel corpus Q para Each pair of SPARQL-Cypher query statement pairs (s i , c i )
[0045] Output: The query skeleton graph structure representation of the SPARQL statement s i The query skeleton sequence of the Cypher statement c The mapping dictionary d i to construct the translation vocabulary V required by the translation system The mapping dictionary d i to construct the translation vocabulary V required by the translation system
[0046] Process:
[0047] Step a1: Use the grammar-based programming language parser antlr4 to parse the SPARQL statement s i and the Cypher statement c i into the smallest semantic units respectively to obtain their respective corresponding semantic unit sequences and Use 5 special markers <node_n>, <pred_n>, <string> 、 <operator>and <number>Replace respectively and the entities, relationships, strings, operators and numerical values in, to obtain a sequence of SPARQL query skeletons composed of SPARQL language keywords and special tokens A sequence of Cypher query skeletons composed of Cypher language keywords and special tokens Using the special tokens used in the replacement process as keys and the semantic units to be replaced as values, obtain the mapping dictionary d i ;
[0048] Step a2: For the sequence of query skeletons of the SPARQL statement obtained in step a1 Take each semantic unit therein as a node, and add connected edges between adjacent nodes according to the sequence order and logical structure of the query statement, to obtain a graph structure representation of the SPARQL statement query skeleton
[0049] Step a3: For all SPARQL and Cypher skeleton sequences and Construct the translation vocabulary V; Denote the set of SPARQL language keywords as K sp , and the set of Cypher language keywords as K cy , and the set of special tokens as T mark , then V = K sp ∪K cy ∪T mark ;
[0050] The second step of the training structure-to-sequence translation model of the present invention is specifically described as follows:
[0051] Input: The graph structure representation of the SPARQL statement s i and The skeleton sequence of the Cypher statement c i Output: The structure-to-sequence translation model f
[0052] Process: θ
[0053] Step b1: For the translation vocabulary V constructed in step a3, randomly initialize the word vectors of each word;
[0054] Step b2: Use the graph neural network GCN or GAT to encode the graph structure
[0055] ; For each node p in , obtain its initial representation from the randomly initialized word vector mapping And use a graph neural network to update its representation; taking the graph attention network GAT as an example, the specific calculation formula is as follows:
[0056]
[0057]
[0058]
[0059] Where N p represents the set of neighbor nodes of node p, is the representation of node p after passing through l layers of the network.
[0060] Step b3: Use the node representations encoded by the graph structure after passing through l layers of the network as the input of the decoder, and generate the corresponding Cypher query skeleton sequence in an autoregressive decoding manner. The decoder is a GRU, LSTM or Transformer structure, and the generation method is described as follows:
[0061] Denote the input The target sequence is
[0062] u j = argmax P(u j |X i , u <j , θ) (4)
[0063]
[0064] Where, P(u j |X i , u <j ), θ) represents the probability of generating the j-th semantic unit as u j , is the output of the decoder at the j-th position, and W ∈ R d×|V| is the parameter of the classification linear layer.
[0065] Step b4: For each SPARQL-Cypher statement pair in the parallel corpus Q para , calculate the cross-entropy loss at each step of the generation, and use the gradient descent method to optimize the model parameters to obtain the trained translation model f θ .
[0066] The third step of the present invention translates the input source SPARQL statement q i into a target Cypher statement with the same query semantics The process is described as follows:
[0067] Input: Source SPARQL statement q i , translation model f θ
[0068] Output: Target Cypher statement
[0069] Process:
[0070] Step c1: Process the input SPARQL statement q i , using the parsing and processing method in Step 1 to obtain the mapping dictionary d and the graph structure representation of the query skeleton
[0071] Step c2: Input the graph structure representation into the translation model f obtained in Step 2 θ , to obtain the query skeleton sequence of the target Cypher statement
[0072] Step c3: According to the mapping dictionary d, restore the special markers in the query skeleton sequence to specific semantic units to obtain the target Cypher statement
[0073] Refer to Figure 4 , the present invention also provides a graph data query language translation system for knowledge base question answering, including a preprocessing module, a source query language encoding module, and a target query language generation module:
[0074] The preprocessing module uses the open-source tool Neosemantics to convert the format of the knowledge base stored in the form of RDF to obtain the knowledge base stored on the graph database Neo4j;
[0075] The source query language encoding module is used to parse and process the input SPARQL statement s i to obtain the query skeleton sequence the graph structure of the query skeleton and the mapping dictionary d for restoring from the skeleton sequence to the original query statement i ; use a structure encoder based on a graph neural network to encode it to obtain a vector representation containing structural information;
[0076] The target query language generation module uses a sequence decoder to decode the vector representation containing structural information to obtain the query skeleton sequence of the target Cypher statement According to the mapping dictionary d i restore the special markers in the skeleton sequence to specific semantic units to obtain the target Cypher statement c i ; Execute the obtained Cypher statement c i on the knowledge base. According to the correctness of the returned answers, the translation effect of the query statement can be evaluated, which helps to realize the construction and migration of knowledge base question-answering systems in fields such as sports, e-commerce, and finance.< / number> < / operator> < / string> < / number> < / operator> < / string> < / operator> < / number> < / op> < / num> < / string> < / operator>
Claims
1. A method for translating graph data query languages for knowledge base question answering, characterized in that The method includes the following steps: Step 1: Parse and process SPARQL and Cypher statements to obtain a query skeleton sequence, a mapping dictionary for restoring the original query statement from the skeleton sequence, a graph structure of the query skeleton, and a translation vocabulary; Step 2: Adopt a structure-to-sequence generation framework. Input the query skeleton graph structure of the SPARQL statement obtained in Step 1 into a structure encoder based on a graph neural network. Input the encoded representations of each node in the graph structure into a sequence decoder, and use the query skeleton sequence of the corresponding Cypher statement as the generation target for training to obtain a translation model f that includes a structure encoder and a sequence decoder θ ; where the graph neural network adopted by the structure encoder is GCN or GAT, and the neural network model adopted by the sequence decoder is GRU, LSTM or Transformer; cross-entropy loss function is used for training, and the parameters of the encoder and decoder are updated by the method of gradient descent; Step 3: Parse and process the input source SPARQL statement according to Step 1, and input the graph structure of the obtained query skeleton into the translation model f obtained in Step 2 θ Generate the query skeleton sequence of the target Cypher statement, and restore the query skeleton sequence according to the mapping dictionary to obtain the target Cypher statement.
2. The method for translating a graph data query language for question answering facing a knowledge base according to claim 1, wherein The specific steps of Step 1 include the following steps: Step a1: For the parallel corpus Q para in each pair of SPARQL and Cypher statements (s i , c i ) with the same semantics, use the grammar-based programming language parser antlr4 to parse the SPARQL statement s i and the Cypher statement c i into the smallest semantic units respectively, obtaining their corresponding semantic unit sequences and Use 5 special tokens <node_n>, <pred_n>, <string> 、 <operator>and <number>Replace separately and with the entities, relationships, strings, operators, and numerical values in, to obtain a sequence of SPARQL query skeletons composed of SPARQL language keywords and special markers A sequence of Cypher query skeletons composed of Cypher language keywords and special markers Using the special markers used in the replacement process as keys and the semantic units to be replaced as values, obtain the mapping dictionary d i ;< / number> < / operator> < / string> Step a2: For the query skeleton sequence of the SPARQL statement obtained in step a1 Take each semantic unit therein as a node, and add connected edges between adjacent nodes according to the sequence order and logical structure of the query statement to obtain a graph structure representation of the SPARQL statement query skeleton Step a3: For all SPARQL and Cypher query skeleton sequences and Construct a translation vocabulary V; Let the set of SPARQL language keywords be \(K\). sp The set of Cypher language keywords is \(K'\). cy The set of special markers is \(T\). mark Then \(V = K\). sp \(\cup K'\). cy \(\cup T\). mark .
3. The method for translating a graph data query language for question answering facing a knowledge base according to claim 1, wherein The specific steps of Step 2 include the following steps: Step b1: For the constructed translation vocabulary V, randomly initialize the word vectors of each word; Step b2: Use a graph neural network GCN or GAT to encode the graph structure for encoding; Step b3: Take the graph structure The node representations after being encoded by the graph neural network as the input of the sequence decoder, and generate the corresponding Cypher query skeleton sequence in an autoregressive decoding manner The neural network model adopted by the sequence decoder is GRU, LSTM or Transformer; Step b4: For each SPARQL-Cypher statement pair in the parallel corpus Q para calculate the cross-entropy loss at each step of generation, and optimize the model parameters using gradient descent to obtain the trained translation model f θ .
4. The method for translating a graph data query language for question answering facing a knowledge base according to claim 1, wherein The specific steps of Step 3 include the following steps: Step c1: Process the input SPARQL statement q i , and use the preprocessing method in Step 1 to obtain the mapping dictionary d and the graph structure representation of the query skeleton Step c2: Represent the graph structure of the query skeleton Input the translation model f obtained in Step 2 θ to obtain the query skeleton sequence of the target Cypher statement Step c3: According to the mapping dictionary d, restore the special tokens in the query skeleton sequence to specific semantic units to obtain the target Cypher statement 5. A graph data query language translation system based on the method described in claim 1, characterized in that, It includes a preprocessing module, a source query language encoding module, and a target query language generation module; The preprocessing module uses the open-source tool Neosemantics to convert the format of the knowledge base stored in RDF form to obtain the knowledge base stored on the graph database Neo4j; The source query language encoding module is used to parse the input SPARQL statement s i to obtain a query skeleton sequence the graph structure of the query skeleton and a mapping dictionary d for restoring the original query statement from the skeleton sequence i ; use a structure encoder based on a graph neural network to encode it to obtain a vector representation containing structural information; The target query language generation module uses a sequence decoder to decode the vector representation containing structural information to obtain the query skeleton sequence of the target Cypher statement According to the mapping dictionary d i Restore the special tokens in the skeleton sequence to specific semantic units to obtain the target Cypher statement c i ; Execute the obtained Cypher statement c i on the knowledge base, and evaluate the translation effect of the query statement according to the correctness of the returned answer
Citation Information
Patent Citations
Question and answer query method and device, electronic equipment and computer readable storage medium
CN114942981A
Method and system for ontology-driven querying and programming of sensors
US20120161940A1