A graph database query statement construction method based on natural language semantic conversion
By classifying and extracting entities from graph database nodes, combined with synonym mining and semantic mapping, the problems of low conversion efficiency and poor applicability of natural language to graph database query statements are solved, and efficient and low-cost graph database query statement construction is achieved.
Patent Information
- Application Number
- CN202210460177.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-28
- Publication Date
- 2025-10-21
- Estimated Expiration
- 2042-04-28
AI Technical Summary
Existing technologies cannot efficiently and conveniently convert natural language into graph database query statements, making it difficult for ordinary users to use graph databases for search queries. Existing methods also have problems such as poor context targeting and low statement conversion efficiency.
By classifying and extracting entities from graph database nodes, using synonym mining to establish a corpus entity set, and combining basic graph database query statement templates and semantic mapping tables, natural language query semantics are converted into graph database query statements, including node label classification, entity extraction, synonym mining, corpus concretization, semantic mapping, and query clause splicing.
It realizes the conversion of natural language to graph database query statements with good applicability to multiple graph databases, no need for dataset training, low time overhead and low cost, and improves the efficiency and flexibility of statement conversion.
Smart Images

Figure CN115329137B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a method for constructing graph database query statements based on natural language semantic transformation. Background Art
[0002] A graph database is a data management system that uses nodes and edges as its basic storage units and is designed with the principle of efficiently storing and querying graph data structures. The concept of "graph" is crucial to understanding graph databases. A graph is a data structure, a collection of nodes and edges. In a graph database, nodes represent entities or instances, equivalent to records in a relational database or documents in a document database; edges, also called relationships, are lines connecting nodes to other nodes and represent the relationship between nodes. Edges can be directed or undirected. In an undirected graph, an edge connecting two nodes has a single meaning. In a directed graph, edges connecting two different nodes have different meanings depending on their direction.
[0003] Graph databases are used in many scenarios, such as fraud detection, recommendation engines, and knowledge graphs. Graph database applications rely on information retrieval from graph databases, which in turn relies on graph query languages.
[0004] Today's mainstream graph database query languages include the following: Gremlin, a graph database query language developed by the Apache Tinkerpop project, enables procedural or declarative queries; Cypher, a graph database query language proposed by Neo4j, is a declarative graph database query language with concise syntax and powerful expressiveness, enabling precise and efficient query and update of graph databases; PGQL, a graph database query language developed by Oracle, is used to search for information from vertices that meet the specifications. Graph database query languages lack a unified standard, and their syntax differs, making conversion between them difficult. To address this issue, the International Organization for Standardization proposed GQL, a query language intended to become a universal graph database query language standard. Graph database query languages are designed for professional programmers and data analysts, making them difficult for ordinary users without relevant background knowledge to use.
[0005] Patent number: 201410289468.7, titled: "Natural Language-Supported Data Query Method, Open Platform, and User Terminal." In this patent, the open platform accepts natural language query statements sent by the user terminal and converts the natural language into query statements that can be recognized by third-party content providers. However, this patent is designed for traditional relational databases and serves third-party content providers. It neither meets the search needs of ordinary users nor provides good support for graph database queries.
[0006] Application number 201880033017.3, titled "Natural Language Query to Database Query Conversion Method Based on Neural Networks," describes the invention using a combination of an aggregate classifier model, a column predictor model, and a clause predictor model to achieve the conversion of natural language queries to database queries. However, using neural networks to convert natural language queries to database query language requires a large training dataset. In practical applications, obtaining such a large training dataset is time-consuming, labor-intensive, and costly.
[0007] Currently, there is no efficient and convenient graph database retrieval service method that can convert natural language into graph database query statements, so that ordinary users without background knowledge can use natural language to search and query the graph database. Summary of the Invention
[0008] The current methods for converting natural language into graph database query statements have problems such as poor contextual pertinence, low sentence conversion efficiency, and lack of universality of the conversion method. In order to solve the above problems, the present invention proposes a method for constructing graph database query statements based on natural language semantic conversion. First, entity extraction is performed on the graph database, and then a corpus entity set is established based on the extraction results with the help of an artificial vocabulary. The query semantics in the natural language are extracted using the corpus entity set, and finally the semantics are converted into query statements through the basic graph database query language template. The present invention is conducive to enhancing the contextual pertinence of the process of converting natural semantics into graph database query statements and improving the sentence conversion efficiency.
[0009] The technical solution adopted in the present invention is:
[0010] A method for constructing a graph database query statement based on natural language semantic transformation includes the following steps:
[0011] Step 1: Classify the graph database nodes by node labels, extract entities from the classification results, and establish an abstract entity set E.
[0012] 1.1. Node: A node is the basic storage unit in a graph database, and n is used to represent a node.
[0013] In step 1.1, the node contains the following information:
[0014] 1.1.1. Node name na: The name of the node, used to uniquely identify the node.
[0015] 1.1.2. Label: used to classify nodes. Nodes with the same label belong to the same class.
[0016] 1.1.3 Attribute np: The name of a property of a node. A node may have multiple different attributes.
[0017] 1.1.4 Attribute value nv: A specific description of a property of a node. A node may have multiple different attribute values.
[0018] 1.2. Node set: The node set consists of all nodes in the graph database and is represented by the symbol N. N = [n1, n2, ..., n n ].
[0019] 1.3 Abstract Entity: An abstract entity is an abstraction of nodes with the same label. An abstract entity is a node template used to describe the attributes and status of a class of nodes, represented by the symbol e.
[0020] In step 1.3, the abstract entity includes the following information:
[0021] 1.3.1. Abstract entity name en: The name of the abstract entity, used to uniquely identify the abstract entity.
[0022] 1.3.2 Abstract attribute ep: The name of a property possessed by an abstract entity. An abstract entity may have multiple different attributes.
[0023] 1.4. Classification: A classification consists of several nodes with the same label, represented by the symbol p.
[0024] 1.5. Classification set: A classification set consists of several different classifications and is represented by the symbol P. P = [p1, p2, ..., p n ].
[0025] 1.6. Abstract entity set: An abstract entity set consists of several abstract entities and is represented by the symbol E. E = [e1, e2, ..., e n ], e i Represents the i-th abstract entity in E.
[0026] 1.7. Node classification: Divide the node set N according to the node label, and the result of the division is the classification set P.
[0027] In step 1.7, the node classification process is as follows:
[0028] 1.7.1. Create a classification set P. Initially, the classification set P is empty.
[0029] 1.7.2. Traverse the node set N in order, and record the number of nodes obtained in i times as n i .
[0030] 1.7.3 If n i If the label is empty, then n is discarded. i .
[0031] 1.7.4 If ni If the label is not empty, then traverse the classification set P and check whether there is a classification p in P. e , whose members have labels similar to n i The labels are the same. If the classification p e does not exist, jump to step 1.7.5; if p e If it exists, skip to step 1.7.6.
[0032] 1.7.5. Create a new category p and add node n i Add p, and add p to the classification set P.
[0033] 1.7.6、Node n i Join p e .
[0034] 1.7.7, if n i If it is the last node of N, the traversal ends.
[0035] 1.8. Entity extraction: traverse the classification set P, create abstract entities, and extract common attributes from the classification nodes as the attributes of the abstract entity.
[0036] In step 1.8, the entity extraction process is as follows:
[0037] 1.8.1. Create an abstract entity set E. Initially, E is empty.
[0038] 1.8.2. Traverse the classification set P in order, and record the classification obtained i times as p i .
[0039] 1.8.3. Create an abstract entity e and convert p i The node label label in is used as the abstract entity name en, and p i The attribute name common to all nodes in is used as the abstract attribute ep of the abstract entity.
[0040] 1.8.4. Add abstract entity e to abstract entity set E.
[0041] 1.8.5. Recording abstract entities e and categories p i One-to-one mapping relationship, called e and p i are associated.
[0042] 1.8.6, if p i If it is the last category of P, the traversal ends.
[0043] Step 2: Use synonym mining to concretize abstract entities into corpus entities and establish corpus entity set C.
[0044] 2.1. Synonym mining: Synonym mining is a common method in the field of natural language processing to find synonyms of a given word.
[0045] 2.2. Synonym database: The result of synonym mining of a vocabulary is called a synonym database, which is represented by the symbol syn.
[0046] 2.3 Corpus Entity: A corpus entity is an abstract entity that concretizes abstract attributes. The symbol cor represents a corpus entity. For the abstract attributes of an abstract entity, the corpus entity specifies the value range of the abstract attribute in the form of a synonym library.
[0047] 2.4、Corpus entity set: Corpus entity set consists of several corpus entities, represented by symbol C. C=[cor1,cor2,...,cor n ], cor i Represents the i-th corpus in C.
[0048] 2.5. Corpus concretization: traverse the abstract entity set E, find the categories associated with the abstract entity, perform synonym mining on the categories, and use the mining results as the abstract attribute value range of the abstract entity.
[0049] In step 2.5, the corpus concretization process is as follows:
[0050] 2.5.1. Create a corpus entity set C. Initially, C does not contain any members.
[0051] 2.5.2. Traverse the abstract entity set E in order, and record the abstract entity obtained i times as e i .
[0052] 2.5.3. According to the mapping relationship recorded in step 1.8.5, find e i The corresponding classification p i .
[0053] 2.5.4. Traverse e in order i All abstract attributes of , the abstract attributes obtained i times are recorded as ep i .
[0054] 2.5.5、In p i In the node to which it belongs, if the attribute name of the node is the same as ep i If they are equal, the attribute value of the node is recorded, and all recorded attribute values constitute the set ep_set i .
[0055] 2.5.6, ep_set i Synonym mining is performed, and the results form a synonym database syn i ep_set iMembers of syn i , put syn i As ep i The value range of .
[0056] 2.5.7, when ep i It is e i When the last attribute of i All abstract properties of the corresponding syn i A one-to-one mapping relationship is established, which is called e i is embodied as cor i 。 i Add corpus entity set C.
[0057] 2.5.8, if e i This is the last category of E, and the traversal ends.
[0058] Step 3: Define the basic graph database query statement template; select natural semantics with the help of the knowledge base and convert natural semantics into formal semantics; establish a semantic mapping table based on the mapping relationship between natural semantics and formal semantics, and use the semantic mapping table to extract adjacent query semantics from the query statement NQL described in natural language; convert the corpus entity semantics into semantic entities and establish the semantic set Q.
[0059] 3.1 Basic Graph Database Query Statement Template: The basic graph database query statement template provides a basic query statement and specifies the expression form of the target graph database query statement, represented by the symbol BQT. BQT contains the type descriptor type, the basic query statement bql, and the query clause set pql_set.
[0060] In step 3.1, the basic graph database query statement template includes the following information:
[0061] 3.1.1. Type description field: The type description field specifies the graph database query language type and is represented by the symbol type.
[0062] 3.1.2 Basic Query Statement: BQT's default query statement, denoted by the symbol bql, is a query statement that does not impose any restrictions on the graph database and returns all nodes in the graph database.
[0063] 3.1.3. Query clause: A query statement that conditionally selects data from a graph database is called a query clause, represented by the symbol pql.
[0064] 3.1.4. Query clause set: A set of query clauses, represented by the symbol pql_set.
[0065] 3.2. Template matching: According to the graph database query language type that needs to be converted, select the corresponding basic graph database query statement template BQT, so that the type descriptor type of BQT is consistent with the graph database query language type that needs to be converted. This process is called template matching.
[0066] 3.3. Query statements described in natural language: Use words, phrases, and sentences in the language people use in daily life to express information retrieval intentions, represented by the symbol NQL.
[0067] 3.4 Natural Semantics: Based on the specific application scenarios of graph databases, a group of commonly used predicates in natural language are selected. These predicates embody the query semantics and logic of natural language. These selected predicates are called natural semantics and are represented by the symbol smp.
[0068] 3.5 Formal Semantics: After template matching, the type of graph database query language to be converted is determined. Natural semantics are formally described using this type of graph database query language. The resulting description is called formal semantics and is represented by the symbol ql. Undetermined attribute values in the formal semantics are represented by the placeholder "?".
[0069] 3.6 Semantic Mapping: The many-to-one mapping relationship between natural semantics and formal semantics is represented by the symbol qlt. The formal definition is expressed as "qlt:smp→ql". "→" is the mapping symbol, indicating the many-to-one mapping relationship from smp to ql; ":" is the continuation symbol, indicating that the subsequent content is a formal description of qlt.
[0070] 3.7. Semantic mapping table: The semantic mapping table consists of several semantic mappings and is represented by the symbol QLT.
[0071] 3.8 Semantic Entities: Semantic entities are a further refinement of abstract entities based on corpus entities, denoted by the symbol q. Compared to corpus entities, semantic entities extract the adjacency query semantics implied in natural sentences and concretize abstract attributes into specific values, making them more closely integrated with specific application scenarios.
[0072] In step 3.8, the semantic entity includes the following information:
[0073] 3.8.1. Semantic entity name qa: The name of the semantic entity, used to uniquely identify the semantic entity.
[0074] 3.8.2 Semantic attribute amp_name: The name of a property of a semantic entity. A semantic entity may have multiple different semantic attributes.
[0075] 3.8.3 Semantic attribute value amp_value: A specific description of a property of a node. A semantic entity may have multiple different attribute values.
[0076] 3.8.4. Semantic attribute starting position amp_start: The starting position of the semantic attribute value in NQL.
[0077] 3.8.5. Semantic attribute end position amp_end: The end position of the semantic attribute value in NQL.
[0078] 3.8.6. Adjacency Query Semantics: The query semantics with the highest correlation with the semantic attributes are called adjacency query semantics, denoted by the symbol amp_ql.
[0079] 3.9. Semantic entity set: A semantic entity set consists of several semantic entities and is represented by the symbol Q.
[0080] 3.10 Semantic Conversion: Traverse the corpus entity set C and create semantic entities based on the abstract attributes of the corpus entities. Using the semantic mapping table QLT, extract natural semantics from NQL and calculate semantic distances to obtain adjacent semantics, completing the conversion from corpus entities to semantic entities.
[0081] The processing process of step 3.10 includes the following steps:
[0082] 3.10.1、Traverse the corpus entity set C in order, and record the corpus entity obtained i times as cor i .
[0083] 3.10.2. Create semantic entity q.
[0084] 3.10.3、Retrieve cor i The synonym library corresponding to the abstract attribute ep. If a word t in the vocabulary appears in NQL, the starting position t_start and the ending position t_end of the word are recorded.
[0085] 3.10.4. Assign values to the semantic attribute, semantic attribute value, semantic attribute starting position, and semantic attribute ending position of semantic entity q: Let amp_name be ep, amp_value be t, amp_start be t_start, and amp_end be t_end.
[0086] 3.10.5. Find all natural semantic smp recorded in the semantic mapping table QLT, and record the starting and ending positions of smp in NQL, represented by smp_start and smp_end respectively.
[0087] 3.10.6, according to the formula Calculate the distance. Distance represents the degree of correlation between the semantic attribute and the natural semantics. The smaller the distance, the higher the correlation. Find the natural semantics smp that minimizes the distance, represented by the symbol smp_close.
[0088] 3.10.7. Find the formal semantics corresponding to the natural semantics smp_close and represent it with the symbol ql_close.
[0089] Assign the adjacency query semantics amp_ql of semantic entity q to ql_close.
[0090] 3.10.8. Add semantic entity q to semantic entity set Q.
[0091] 3.10.9, if cor i This is the last entity in the corpus entity set C, and the traversal ends.
[0092] Step 4: Traverse the semantic entity set Q in order, build the query clause pql, combine the basic graph database query statement template BQT with the query clause pql, and generate the target graph database query statement through clause splicing.
[0093] 4.1. Clause construction: Traverse the semantic entity set Q, generate query clauses based on the semantic entities, and add the query clauses to the query clause set.
[0094] The processing process of step 4.1 includes the following steps:
[0095] 4.1.1. Traverse the semantic entity set Q in order, and record the semantic entity obtained i times as q i .
[0096] 4.1.2. Traverse q in order i All semantic attribute names, record the semantic attribute name obtained j times as amp_name j .
[0097] 4.1.3. Extract amp_name j The corresponding adjacency semantics amp_ql takes the adjacency semantics amp_ql as the content of the query clause pql.
[0098] 4.1.4. Extract amp_name j Corresponding semantic attribute value amp_value j If the query clause has a placeholder, use amp_value j Replace the placeholder and assign a value to pql.
[0099] 4.1.5. Add the assigned pql to the query clause set pql_set.
[0100] 4.2. Clause splicing: Traverse the query clause set pql_set and splice the query clause with the basic query statement bql in the basic graph database query statement template BQT. The splicing result is the target graph database query statement.
[0101] The processing process of step 4.2 includes the following steps:
[0102] 4.2.1、Traverse the query clause set pql_set in order, and record the query clauses obtained i times as pql i .
[0103] 4.2.2, if pql i If it is the first query clause obtained, add the "WHERE" string after bql to indicate that the following content is the conditional query clause. i String concatenation of the content and WHERE.
[0104] 4.2.3, if pql i If it is not the first query clause obtained, add the string "AND" after bql and replace pql i The content of the string is concatenated with "AND".
[0105] 4.2.4, if pql i If this is the last clause in the query clause set, the traversal ends and the concatenated result is used as the target graph database query statement.
[0106] The advantages of the present invention are: a method for constructing graph database query statements based on natural language semantic conversion is proposed, which can be applied to many different types of graph databases and has good versatility; unlike the process of converting natural language to graph database language realized by artificial intelligence, this method does not require data set training, has low time overhead and low application cost; for different graph database application scenarios, this method can freely select corpus entity sets, is easy and flexible to use, and has high statement conversion efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0107] Figure 1 This is a process diagram for node classification and entity extraction of Zhejiang Province Cultural Tourism Graph Database (GDB);
[0108] Figure 2 Process diagram for extracting classification attributes, mining synonyms, and establishing mapping relationships;
[0109] Figure 3 A diagram of the process of semantic mapping, calculating semantic distance, and establishing semantic sets;
[0110] Figure 4 This is the query result graph. DETAILED DESCRIPTION
[0111] The present invention will be further described below with reference to the accompanying drawings and embodiments.
[0112] A method for constructing graph database query statements based on natural language semantic transformation, with the following specific steps:
[0113] Step 1: Classify the graph database nodes by node labels, extract entities from the classification results, and establish an abstract entity set E.
[0114] 1.1. Node: A node is the basic storage unit in a graph database, and n is used to represent a node.
[0115] In step 1.1, the node contains the following information:
[0116] 1.1.1. Node name na: The name of the node, used to uniquely identify the node.
[0117] 1.1.2. Label: used to classify nodes. Nodes with the same label belong to the same class.
[0118] 1.1.3 Attribute np: The name of a property of a node. A node may have multiple different attributes.
[0119] 1.1.4 Attribute value nv: A specific description of a property of a node. A node may have multiple different attribute values.
[0120] 1.2. Node set: The node set consists of all nodes in the graph database and is represented by the symbol N. N = [n1, n2, ..., n n ].
[0121] 1.3 Abstract Entity: An abstract entity is an abstraction of nodes with the same label. An abstract entity is a node template used to describe the attributes and status of a class of nodes, represented by the symbol e.
[0122] In step 1.3, the abstract entity includes the following information:
[0123] 1.3.1. Abstract entity name en: The name of the abstract entity, used to uniquely identify the abstract entity.
[0124] 1.3.2 Abstract attribute ep: The name of a property possessed by an abstract entity. An abstract entity may have multiple different attributes.
[0125] 1.4. Classification: A classification consists of several nodes with the same label, represented by the symbol p.
[0126] 1.5. Classification set: A classification set consists of several different classifications and is represented by the symbol P. P = [p1, p2, ..., p n ].
[0127] 1.6. Abstract entity set: An abstract entity set consists of several abstract entities and is represented by the symbol E. E = [e1, e2, ..., e n ], e i Represents the i-th abstract entity in E.
[0128] 1.7. Node classification: Divide the node set N according to the node label, and the result of the division is the classification set P.
[0129] In step 1.7, the node classification process is as follows:
[0130] 1.7.1. Create a classification set P. Initially, the classification set P is empty.
[0131] 1.7.2. Traverse the node set N in order, and record the number of nodes obtained in i times as n i .
[0132] 1.7.3 If n i If the label is empty, then n is discarded. i .
[0133] 1.7.4 If n i If the label is not empty, then traverse the classification set P and check whether there is a classification p in P. e , whose members have labels similar to n i The labels are the same. If the classification p e does not exist, jump to step 1.7.5; if p e If it exists, skip to step 1.7.6.
[0134] 1.7.5. Create a new category p and add node n i Add p, and add p to the classification set P.
[0135] 1.7.6、Node n i Join p e .
[0136] 1.7.7, if n i If it is the last node of N, the traversal ends.
[0137] 1.8. Entity extraction: traverse the classification set P, create abstract entities, and extract common attributes from the classification nodes as the attributes of the abstract entity.
[0138] In step 1.8, the entity extraction process is as follows:
[0139] 1.8.1. Create an abstract entity set E. Initially, E is empty.
[0140] 1.8.2. Traverse the classification set P in order, and record the classification obtained i times as pi.
[0141] 1.8.3. Create an abstract entity e and convert p i The node label label in is used as the abstract entity name en, and p i The attribute name common to all nodes in is used as the abstract attribute ep of the abstract entity.
[0142] 1.8.4. Add abstract entity e to abstract entity set E.
[0143] 1.8.5. Recording abstract entities e and categories p i One-to-one mapping relationship, called e and p i are associated.
[0144] 1.8.6, if p i If it is the last category of P, the traversal ends.
[0145] Step 2: Use synonym mining to concretize abstract entities into corpus entities and establish corpus entity set C.
[0146] 2.1. Synonym mining: Synonyms of a given word are found using common synonym mining methods. Synonym mining is a common method in the field of natural language processing. In the present invention, synonym mining can be performed with the help of the open source Chinese synonym library Synonyms.
[0147] 2.2. Synonym database: The result of synonym mining of a vocabulary is called a synonym database, which is represented by the symbol syn.
[0148] 2.3 Corpus Entity: A corpus entity is an abstract entity that concretizes abstract attributes. The symbol cor represents a corpus entity. For the abstract attributes of an abstract entity, the corpus entity specifies the value range of the abstract attribute in the form of a synonym library.
[0149] 2.4. Corpus entity set: Corpus entity set consists of several corpus entities, represented by symbol C. C = [cor1, cor2, ..., cor n ], cor i Represents the i-th corpus in C.
[0150] 2.5. Corpus concretization: traverse the abstract entity set E, find the categories associated with the abstract entity, perform synonym mining on the categories, and use the mining results as the abstract attribute value range of the abstract entity.
[0151] In step 2.5, the corpus concretization process is as follows:
[0152] 2.5.1. Create a corpus entity set C. Initially, C does not contain any members.
[0153] 2.5.2. Traverse the abstract entity set E in order, and record the abstract entity obtained i times as e i .
[0154] 2.5.3. According to the mapping relationship recorded in step 1.8.5, find e i The corresponding classification p i .
[0155] 2.5.4. Traverse e in order i All abstract attributes of , the abstract attributes obtained i times are recorded as ep i .
[0156] 2.5.5、In p i In the node to which it belongs, if the attribute name of the node is the same as ep i If they are equal, the attribute value of the node is recorded, and all recorded attribute values constitute the set ep_set i .
[0157] 2.5.6, ep_set i Synonym mining is performed, and the results form a synonym database syn i ep_set i Members of syn i , put syn i As ep i The value range of .
[0158] 2.5.7, when ep i It is e i When the last attribute of i All abstract properties of the corresponding syn i A one-to-one mapping relationship is established, and ei is now concretized as cor i 。 i Add corpus entity set C.
[0159] 2.5.8, if e i This is the last category of E, and the traversal ends.
[0160] Step 3: Define the basic graph database query statement template; select natural semantics with the help of the knowledge base and convert natural semantics into formal semantics; establish a semantic mapping table based on the mapping relationship between natural semantics and formal semantics, and use the semantic mapping table to extract adjacent query semantics from the query statement NQL described in natural language; convert the corpus entity semantics into semantic entities and establish the semantic set Q.
[0161] 3.1 Basic Graph Database Query Statement Template: A basic graph database query statement template provides a basic query statement and specifies the target graph database query statement expression, denoted by the symbol BQT. BQT consists of a type descriptor type, a basic query statement bql, and a query clause set pql_set. In this invention, to improve statement conversion speed, basic graph database query statement templates can be pre-established for common graph databases such as neo4j, FlockDB, and GraphDB.
[0162] In step 3.1, the basic graph database query statement template includes the following information:
[0163] 3.1.1. Type description field: The type description field specifies the graph database query language type and is represented by the symbol type.
[0164] 3.1.2 Basic Query Statement: BQT's default query statement, denoted by the symbol bql, is a query statement that does not impose any restrictions on the graph database and returns all nodes in the graph database.
[0165] 3.1.3. Query clause: A query statement that conditionally selects data from a graph database is called a query clause, represented by the symbol pql.
[0166] 3.1.4. Query clause set: A set of query clauses, represented by the symbol pql_set.
[0167] 3.2. Template matching: According to the graph database query language type that needs to be converted, select the corresponding basic graph database query statement template BQT, so that the type descriptor type of BQT is consistent with the graph database query language type that needs to be converted. This process is called template matching.
[0168] 3.3. Query statements described in natural language: Use words, phrases, and sentences in the language people use in daily life to express information retrieval intentions, represented by the symbol NQL.
[0169] 3.4 Natural Semantics: Based on the specific application scenarios of graph databases, a group of commonly used predicates in natural language are selected. These predicates embody the query semantics and logic of natural language. These selected predicates are called natural semantics and are represented by the symbol smp.
[0170] 3.5 Formal Semantics: After template matching, the type of graph database query language to be converted is determined. Natural semantics are formally described using this type of graph database query language. The resulting description is called formal semantics and is represented by the symbol ql. Undetermined attribute values in the formal semantics are represented by the placeholder "?".
[0171] 3.6 Semantic Mapping: The many-to-one mapping relationship between natural semantics and formal semantics is represented by the symbol q1t. The formal definition is expressed as "qlt:smp→ql". "→" is the mapping symbol, indicating the many-to-one mapping relationship from smp to ql; ":" is the continuation symbol, indicating that the subsequent content is a formal description of qlt.
[0172] 3.7. Semantic mapping table: The semantic mapping table consists of several semantic mappings and is represented by the symbol QLT.
[0173] 3.8 Semantic Entities: Semantic entities are a further refinement of abstract entities based on corpus entities, denoted by the symbol q. Compared to corpus entities, semantic entities extract the adjacency query semantics implied in natural sentences and concretize abstract attributes into specific values, making them more closely integrated with specific application scenarios.
[0174] In step 3.8, the semantic entity includes the following information:
[0175] 3.8.1. Semantic entity name qa: The name of the semantic entity, used to uniquely identify the semantic entity.
[0176] 3.8.2 Semantic attribute amp_name: The name of a property of a semantic entity. A semantic entity may have multiple different semantic attributes.
[0177] 3.8.3 Semantic attribute value amp_value: A specific description of a property of a node. A semantic entity may have multiple different attribute values.
[0178] 3.8.4. Semantic attribute starting position amp_start: The starting position of the semantic attribute value in NQL.
[0179] 3.8.5. Semantic attribute end position amp_end: The end position of the semantic attribute value in NQL.
[0180] 3.8.6. Adjacency Query Semantics: The query semantics with the highest correlation with the semantic attributes are called adjacency query semantics, denoted by the symbol amp_ql.
[0181] 3.9. Semantic entity set: A semantic entity set consists of several semantic entities and is represented by the symbol Q.
[0182] 3.10 Semantic Conversion: Traverse the corpus entity set C and create semantic entities based on the abstract attributes of the corpus entities. Using the semantic mapping table QLT, extract natural semantics from NQL and calculate semantic distances to obtain adjacent semantics, completing the conversion from corpus entities to semantic entities.
[0183] The processing process of step 3.10 includes the following steps:
[0184] 3.10.1、Traverse the corpus entity set C in order, and record the corpus entity obtained i times as cor i .
[0185] 3.10.2. Create semantic entity q.
[0186] 3.10.3、Retrieve cor i The synonym library corresponding to the abstract attribute ep. If a word t in the vocabulary appears in NQL, the starting position t_start and the ending position t_end of the word are recorded.
[0187] 3.10.4. Assign values to the semantic attribute, semantic attribute value, semantic attribute starting position, and semantic attribute ending position of semantic entity q: Let amp_name be ep, amp_value be t, amp_start be t_start, and amp_end be t_end.
[0188] 3.10.5. Find all natural semantic smp recorded in the semantic mapping table QLT, and record the starting and ending positions of smp in NQL, represented by smp_start and smp_end respectively.
[0189] 3.10.6, according to the formula Calculate the distance. The distance represents the degree of correlation between the semantic attribute and the natural semantics. The smaller the distance, the higher the correlation. Find the natural semantics that minimizes the distance.
[0190] Semantics smp, represented by the symbol smp_close.
[0191] 3.10.7. Find the formal semantics corresponding to the natural semantics smp_close and represent it with the symbol ql_close.
[0192] Assign the adjacency query semantics amp_ql of semantic entity q to ql_close.
[0193] 3.10.8. Add semantic entity q to semantic entity set Q.
[0194] 3.10.9, if cor i This is the last entity in the corpus entity set C, and the traversal ends.
[0195] Step 4: Traverse the semantic entity set Q in order, build the query clause pql, combine the basic graph database query statement template BQT with the query clause pql, and generate the target graph database query statement through clause splicing.
[0196] 4.1. Clause construction: Traverse the semantic entity set Q, generate query clauses based on the semantic entities, and add the query clauses to the query clause set.
[0197] The processing process of step 4.1 includes the following steps:
[0198] 4.1.1. Traverse the semantic entity set Q in order, and record the semantic entity obtained i times as q i .
[0199] 4.1.2. Traverse q in order i All semantic attribute names, record the semantic attribute name obtained j times as amp_name j .
[0200] 4.1.3. Extract amp_name j The corresponding adjacency semantics amp_ql takes the adjacency semantics amp_ql as the content of the query clause pql.
[0201] 4.1.4. Extract amp_name j Corresponding semantic attribute value amp_value j If the query clause has a placeholder, use amp_value j Replace the placeholder and assign a value to pql.
[0202] 4.1.5. Add the assigned pql to the query clause set pql_set.
[0203] 4.2. Clause splicing: Traverse the query clause set pql_set and splice the query clause with the basic query statement bql in the basic graph database query statement template BQT. The splicing result is the target graph database query statement.
[0204] The processing process of step 4.2 includes the following steps:
[0205] 4.2.5. Traverse the query clause set pql_set in order, and record the query clause obtained i times as pql i .
[0206] 4.2.6, if pql i If it is the first query clause obtained, add the "WHERE" string after bql to indicate that the following content is the conditional query clause. i String concatenation of the content and WHERE.
[0207] 4.2.7, if pql i If it is not the first query clause obtained, add the string "AND" after bql and replace pql iThe content of the string is concatenated with "AND".
[0208] 4.2.8, if pql i If this is the last clause in the query clause set, the traversal ends and the concatenated result is used as the target graph database query statement.
[0209] Example:
[0210] Given a natural language query statement (NQL): "Find all tourist attractions in Hangzhou that offer rafting and are rated higher than 4A," the following illustrates how to convert it into a graph database query statement like neo4j, with accompanying figures.
[0211] Figure 1 The graph database GDB and the process of node classification and entity extraction for GDB are shown. GDB is a graph database about cultural tourism information in Zhejiang Province. Figure 1 This excerpt shows 17 nodes and 26 relationships in the graph database. Among them, the Jianglang Mountain node, the Nianbadu node, the Qiandao Lake node, the West Lake node, the Xixi Wetland node, the Yanziling Fishing Platform node, the Daming Mountain Scenic Area node, the Qinghefang node, the Western Zhejiang Grand Canyon node, the Tianzidi node, the Chuiyun Tongtian River node, the Liuxi River node, and the Yaolin Wonderland node all have the node label "attraction"; the 5A and 4A scenic area nodes all have the node label "category"; and the Hangzhou and Quzhou nodes all have the node label "city." "rank" represents the rating relationship between nodes, and "in_city" represents the location relationship between nodes. After step 1.7, the nodes in the graph database (GDB) are divided into three categories: attraction classification, city classification, and level classification. The attraction classification consists of 13 nodes labeled "attraction," denoted by symbol p1; the city classification consists of two nodes labeled "city," denoted by symbol p2; and the level classification consists of two nodes labeled "category," denoted by symbol p3. Step 1.8 extracts entities from the three categories. All nodes in category p1 have the four attributes: name, location, rating, and leisure style. Category p1 is abstracted into abstract entity e1. Similarly, category p2 is abstracted into abstract entity e2, and category p3 into abstract entity e3. e1, e2, and e3 constitute the abstract entity set E.
[0212] Figure 2This diagram illustrates the process of reifying abstract entities into corpus entities. Taking the abstract entity e1 as an example, we extract the classification attributes of its leisure activities. By traversing all nodes in the classification p1, we extract the four attributes "viewing," "photography," "rafting," and "food." These four attributes form the set ep_set1. Using the open-source Chinese synonym database Synonyms, we perform synonym mining on ep_set1, identifying synonyms such as "floating," "photographing," "sightseeing," "photographing," "visiting," "observing," "playing," "delicacies," and "delicacy." The attributes in ep_set1 and the mined synonyms together form the synonym database syn1. There is a one-to-one mapping between the abstract leisure activities attributes in e1 and the synonym database syn1: the synonym database syn1 represents the value range of the abstract leisure activities attributes in e1. When all abstract attributes of e1 are mapped to their corresponding synonyms, the abstract entity e1 is reified into the corpus entity cor1. Similarly, e2 is reified into cor2, and e3 into cor3. cor1, cor2, and cor3 constitute the corpus entity set C.
[0213] Figure 3 The process of establishing an entity semantic set is illustrated. First, a semantic mapping table (QLT) can be created based on the specific application scenario. In this example, the application scenario is a search query for cultural tourism attractions. Semantic mappings related to cultural tourism can be collected by searching a manual vocabulary or knowledge base. Given a natural language query (NQL) in this example, "Find all tourist attractions located in Hangzhou that include rafting as a leisure activity and are rated higher than 4A." Comparing the query with the QLT reveals that the NQL contains three natural semantics (SMPs): "located in," "leisure activity includes," and "rated higher than." Next, a semantic entity (Q) is created based on the corpus entities. The creation process is illustrated using cor1 as an example. Semantic entity q1 is created. Initially, q1 contains no semantic attributes. The abstract attributes "name," "location," "rating," and "leisure activity" contained in cor1 are used as q1's semantic attribute names. amp_value, amp_start, amp_end, and amp_ql are all initialized to null. A synonym database for cor1's abstract attributes is searched, and the words "4A," "Hangzhou," and "rafting" appear in the NQL. These semantic attributes are assigned to the corresponding semantic attribute values (amp_value). Thirdly, the distance between the semantic attribute value and the natural semantics is calculated. Figure 3The figure shows the distances between the semantic attribute value of "Hangzhou" and all natural semantics. It can be seen that the natural semantic "located" is closest to "Hangzhou." According to the semantic mapping table QLT, the formal semantics corresponding to "located" are used as the adjacent semantics amp_ql for the semantic attribute "location." Following these steps, the adjacent semantics for the other semantic attributes of semantic entity q1 can be obtained. Similarly, semantic entities q2, q3, and so on can be constructed, and all generated semantic entities can be added to the semantic set Q.
[0214] Figure 4 The process of clause construction and splicing and the query results are shown. First, we can build the basic graph database query statement template BQT, initialize the query clause set pql_set to an empty set, initialize the type descriptor type value to "cypher", and initialize the basic query statement bql to "match q0 = (n0) - [] - (m0) return q0". The query result of bql will return a path that contains all nodes and relationships in the queried graph database. Secondly, build the clause set according to step 4.1. Based on the semantic entity set Q, three clauses can be constructed, namely:
[0215] match(n1)-[]-(m1)where m1.relax_type=”drifting”
[0216] match(n2)-[]-(m2)where m2.city_name="Hangzhou"
[0217] match(n3)-[]-(m3)where m3.rank_level="4A"
[0218] Next, follow step 4.2 to perform clause concatenation. The concatenation result is as follows:
[0219] match q0=(n0)-[]-(m0)
[0220] match q1=(n1)-[]-(m1)
[0221] match q2=(n2)-[]-(m2)
[0222] match q3=(n3)-[]-(m3)
[0223] where
[0224] m1.relax_type = "drifting" AND
[0225] m2.in_city=″Hangzhou″ AND
[0226] m3.rank=″4A″
[0227] return q0, q1, q2, q3
[0228] Pass the above splicing results into the neo4j database to obtain the query results.
Claims
1. A method for constructing a graph database query statement based on natural language semantic transformation, characterized in that: The following steps are involved: 1) Classify the graph database nodes by node labels, extract entities from the classification results, and establish an abstract entity set E; 2) Use synonym mining to concretize abstract entities into corpus entities and establish corpus entity set C; 3) Define the basic graph database query statement template; Using the knowledge base, natural semantics are selected and converted into formal semantics. A semantic mapping table is established based on the mapping relationship between natural semantics and formal semantics, and adjacency query semantics are extracted from the query statement NQL described in natural language based on the semantic mapping table. Convert the semantics of corpus entities into semantic entities and establish semantic set Q; 4) Traverse the semantic entity set Q in order, construct the query clause pql, combine the basic graph database query statement template BQT with the query clause pql, and generate the target graph database query statement by clause splicing; The specific steps of step 4) are as follows: 4.1) Clause construction: traverse the semantic entity set Q, generate query clauses based on the semantic entities, and add the query clauses to the query clause set; The processing process of step 4.1) The following steps are involved: 4.1.1) Traverse the semantic entity set Q in order, and record the semantic entity obtained i times as q i ; 4.1.2) Traverse q in order i All semantic attribute names, record the semantic attribute name obtained j times as amp_name j ; 4.1.3) Extract amp_name j The corresponding adjacency semantics amp_ql is used as the content of the query clause pql; 4.1.4) Extract amp_name j Corresponding semantic attribute value amp_value j If the query clause has a placeholder, use amp_value j Replace the placeholder and assign a value to pql; 4.1.5) Add the assigned pql to the query clause set pql_set; 4.2) Clause splicing: Traverse the query clause set pql_set and splice the query clause with the basic query statement bql in the basic graph database query statement template BQT. The splicing result is the target graph database query statement; The processing of step 4.2) comprises the following steps: 4.2.1) Traverse the query clause set pql_set in order, and record the query clause obtained i times as pql i ; 4.2.2) If pql i If it is the first query clause obtained, add the WHERE string after bql to indicate that the following content is the conditional query clause. i Concatenate the content and WHERE into strings; 4.2.3) If pql i If it is not the first query clause obtained, add the AND string after bql and replace pql i The content of and AND are concatenated into strings; 4.2.4) If pql i If this is the last clause in the query clause set, the traversal ends and the concatenation result is used as the target graph database query statement.
2. A graph database query statement construction method based on natural language semantic transformation according to claim 1, characterized in that: The specific steps of step 1) are as follows: 1.1) Node: A node is the basic storage unit in a graph database, and n represents a node. In step 1.1), the node contains the following information: 1.1.1) Node name na: the name of the node, used to uniquely identify the node; 1.1.2) Label: used to classify nodes. Nodes with the same label belong to the same class. 1.1.3) Attribute np: The name of a property of a node. A node can have multiple different attributes. 1.1.4) Attribute value nv: A specific description of a property of a node. A node can have multiple different attribute values. 1.2) Node set: The node set consists of all nodes in the graph database, represented by the symbol N, N = [n1, n2, ..., n n ]; 1.3) Abstract Entity: An abstract entity is an abstraction of nodes with the same label. An abstract entity is a node template used to describe the attributes and status of a type of node, represented by the symbol e. In step 1.3), the abstract entity includes the following information: 1.3.1) Abstract entity name en: the name of the abstract entity, used to uniquely identify the abstract entity; 1.3.2) Abstract attribute ep: The name of a property possessed by an abstract entity. An abstract entity has multiple different attributes. 1.4) Classification: A classification consists of several nodes with the same label, represented by the symbol p; 1.5) Classification set: A classification set consists of several different classifications, represented by the symbol P, P = [p1, p2, ..., p n ]; 1.6) Abstract entity set: An abstract entity set consists of a number of abstract entities, represented by the symbol E, where E = [e1, e2, …, e n ], e i represents the i-th abstract entity in E; 1.7) Node classification: Divide the node set N according to the node labels, and the result of the division is the classification set P; In step 1.7), the node classification process is as follows: 1.7.1) Create a classification set P, which is initially empty. 1.7.2) Traverse the node set N in order, and record the number of nodes obtained in i times as n i ; 1.7.3) If n i If the label is empty, then n is discarded. i ; 1.7.4) If n i If the label is not empty, then traverse the classification set P and check whether there is a classification p in P. e , whose members have labels similar to n i The labels are the same; if the classification p e does not exist, jump to step 1.7.5); if p e If it exists, jump to step 1.7.6); 1.7.5) Create a new category p and add node n i Add p, and add p to the classification set P; 1.7.6) Set node n i Join p e ; 1.7.7) If n i It is the last node of N, then the traversal ends; 1.8) Entity extraction: traverse the classification set P, create abstract entities, and extract common attributes from the classification nodes as the attributes of the abstract entity; In step 1.8), the entity extraction process is as follows: 1.8.1) Create an abstract entity set E, initially E is empty; 1.8.2) Traverse the classification set P in order, and record the classification obtained i times as p i ; 1.8.3) Create an abstract entity e and convert p i The node label label in is used as the abstract entity name en, and p i The attribute name common to all nodes in is used as the abstract attribute ep of the abstract entity; 1.8.4) Add abstract entity e to abstract entity set E; 1.8.5) Record abstract entity e and category p i One-to-one mapping relationship, called e and p i It is related; 1.8.6) If p i If it is the last category of P, the traversal ends.
3. A graph database query statement construction method based on natural language semantic conversion according to claim 1, characterized in that: The specific steps of step 2) are as follows: 2.1) Synonym mining: Use common synonym mining methods to find synonyms of a given word; 2.2) Synonym database: The result of synonym mining is called synonym database, which is represented by the symbol syn; 2.3) Corpus Entity: A corpus entity is an abstract entity that concretizes abstract attributes. The symbol cor represents a corpus entity. For the abstract attributes of an abstract entity, the corpus entity specifies the value range of the abstract attribute in the form of a synonym library. 2.4) Corpus entity set: Corpus entity set consists of several corpus entities, represented by symbol C, C = [cor1, cor2, ..., cor n ], cor i Represents the i-th corpus in C; 2.5) Corpus concretization: Traverse the abstract entity set E, find the categories associated with the abstract entity, perform synonym mining on the categories, and use the mining results as the abstract attribute value range of the abstract entity; In step 2.5), the corpus concretization process is as follows: 2.5.1) Create a corpus entity set C. Initially, C does not contain any members. 2.5.2) Traverse the abstract entity set E in order, and record the abstract entity obtained i times as e i ; 2.5.3) Find e according to the mapping relationship recorded in step 1.8.5) i The corresponding classification p i ; 2.5.4) Traverse e in order i All abstract attributes of , the abstract attributes obtained i times are recorded as ep i ; 2.5.5) In p i In the node to which it belongs, if the attribute name of the node is the same as ep i If they are equal, the attribute value of the node is recorded, and all recorded attribute values constitute the set ep_set i ; 2.5.6) ep_set i Synonym mining is performed, and the results form a synonym database syn i ; Set ep_set i Members of syn i , put syn i As ep i The value range of 2.5.7) When ep i It is e i When the last attribute of i All abstract properties of the corresponding syn i A one-to-one mapping relationship is established, which is called e i is embodied as cor i , will cor i Add corpus entity set C; 2.5.8) If e i This is the last category of E, and the traversal ends.
4. A graph database query statement construction method based on natural language semantic conversion according to claim 1, characterized in that: The specific steps of step 3) are as follows: 3.1) Basic Graph Database Query Statement Template: The basic graph database query statement template provides a basic query statement and specifies the expression form of the target graph database query statement. It is represented by the symbol BQT. BQT contains the type descriptor type, the basic query statement bql, and the query clause set pql_set; In step 3.1), the basic graph database query statement template includes the following information: 3.1.1) Type Description Field: The type description field specifies the graph database query language type, represented by the symbol type; 3.1.2) Basic query statement: BQT's default query statement, denoted by the symbol bql; bql is a query statement that does not impose any restrictions on the graph database and returns all nodes in the graph database; 3.1.3) Query Clause: A query statement that conditionally selects data from a graph database is called a query clause, denoted by the symbol pql; 3.1.4) Query clause set: A set of query clauses, represented by the symbol pql_set; 3.2) Template Matching: Based on the graph database query language type to be converted, the corresponding basic graph database query statement template BQT is selected, and the type descriptor type of the BQT is made consistent with the graph database query language type to be converted. This process is called template matching. 3.3) Natural language query statements: Use words, phrases, and sentences in people's daily language to express information retrieval intent, expressed in the notation NQL; 3.4) Natural semantics: Based on the specific application scenarios of graph databases, a group of commonly used predicates in natural language are selected. These predicates contain the query semantics and query logic in natural language. The selected predicates are called natural semantics and are represented by the symbol smp. 3.5) Formal Semantics: After template matching, the type of graph database query language to be converted is determined. The natural semantics are formally described in this type of graph database query language. The description result is called formal semantics and is represented by the symbol ql. The attribute values to be determined in the formal semantics are represented by placeholders. 3.6) Semantic mapping: The many-to-one mapping relationship between natural semantics and formal semantics is represented by the symbol qlt, and the formal definition is expressed as qlt:smp→ql. Where → is a mapping symbol, indicating a many-to-one mapping relationship from smp to ql; : is a continuation symbol, indicating that the subsequent content is a formal description of qlt; 3.7) Semantic Mapping Table: The semantic mapping table consists of several semantic mappings and is represented by the symbol QLT; 3.8) Semantic Entity: A semantic entity is a further concretization of an abstract entity based on a corpus entity. Represented by the symbol q, compared to a corpus entity, a semantic entity extracts the adjacency query semantics implied in natural sentences and concretizes abstract attributes into specific values, making it more closely integrated with specific application scenarios. In step 3.8), the semantic entity includes the following information: 3.8.1) Semantic entity name qa: the name of the semantic entity, used to uniquely identify the semantic entity; 3.8.2) Semantic attribute amp_name: The name of a property of a semantic entity. A semantic entity may have multiple different semantic attributes. 3.8.3) Semantic attribute value amp_value: A specific description of a property of a node. A semantic entity may have multiple different attribute values. 3.8.4) Semantic attribute starting position amp_start: the starting position of the semantic attribute value in NQL; 3.8.5) semantic attribute end position amp_end: the end position of the semantic attribute value in NQL; 3.8.6) Adjacency Query Semantics: The query semantics with the highest degree of correlation with the semantic attribute is called the adjacency query semantics, denoted by the symbol amp_ql; 3.9) Semantic Entity Set: A semantic entity set consists of several semantic entities and is represented by the symbol Q; 3.10) Semantic Conversion: Traverse the corpus C and create semantic entities based on the abstract attributes of the corpus entities. With the help of the semantic mapping table QLT, extract the natural semantics from the NQL and calculate the semantic distance to obtain the adjacent semantics, thus completing the conversion of corpus entities into semantic entities. The processing of step 3.10) comprises the following steps: 3.10.1) Traverse the corpus entity set C in order, and record the corpus entity obtained i times as cor i ; 3.10.2) Create semantic entity q; 3.10.3) Retrieve cor i The synonym library corresponding to the abstract attribute ep. If a word t in the library appears in NQL, the starting position t_start and the ending position t_end of the word are recorded; 3.10.4) Assign values to the semantic attribute, semantic attribute value, semantic attribute start position, and semantic attribute end position of semantic entity q: Let amp_name be ep, amp_value be t, amp_start be t_start, and amp_end be t_end; 3.10.5) Find all natural semantic smps recorded in the semantic mapping table QLT and record the starting and ending positions of smps in NQL, represented by smp_start and smp_end respectively; 3.10.6) According to the formula Calculate the distance, which represents the degree of correlation between the semantic attribute and the natural semantics. The smaller the distance, the higher the correlation. Find the natural semantics smp that minimizes the distance, represented by the symbol smp_close. 3.10.7) Find the formal semantics corresponding to the natural semantics smp_close, denoted by the symbol ql_close, and assign the adjacency query semantics amp_ql of the semantic entity q to ql_close; 3.10.8) Add semantic entity q to semantic entity set Q; 3.10.9) If cor i This is the last entity in the corpus entity set C, and the traversal ends.
Citation Information
Patent Citations
Supports natural language data query methods, open platforms, and user terminals.
CN105279168B
Neural Network-Based Conversion of Natural Language Queries to Database Queries
CN110945495B
Question answering system construction method and system based on military domain knowledge graph
CN113806513A
Intelligent dialogue method and device based on financial knowledge graph, and electronic equipment
CN113988071A