Method, device, equipment, medium and product for determining knowledge graph query statement
By constructing a model based on user intent analysis and knowledge query statements, and combining it with knowledge graph query templates, the problem of low accuracy in complex semantic queries in existing technologies is solved, and efficient and accurate knowledge graph retrieval is achieved.
Patent Information
- Application Number
- CN202510867390.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-26
- Publication Date
- 2025-11-11
- Estimated Expiration
- 2045-06-26
AI Technical Summary
Existing technologies cannot effectively parse complex semantics when generating knowledge graph query statements, resulting in low query accuracy, complex operation, and poor reusability.
By constructing a model using user intent analysis and knowledge query statements, the model analyzes the intent, entities, attributes, and relationships between entities in the initial query statement. Combined with knowledge graph query templates, a knowledge graph query statement is constructed to improve semantic understanding and query accuracy.
It enables accurate queries for complex statements, reduces operational complexity, and improves the reusability of knowledge graph retrieval.
Smart Images

Figure CN120371943B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of statement analysis technology, and in particular to a method, apparatus, device, medium and product for determining query statements in a knowledge graph. Background Technology
[0002] Knowledge graphs (KGs) store large amounts of knowledge data in the form of triples. They are a structured representation of knowledge and are renowned for their symbolic reasoning capabilities, producing interpretable results. Experts can construct domain-specific knowledge graphs to provide accurate and reliable domain-specific relational knowledge.
[0003] Currently, in existing technologies, when generating query statements for knowledge graphs, simple queries are generated by parsing natural language statements for simple cases. However, for complex multi-hop queries, query templates are pre-edited for different scenarios, and the specific data values are then filled into the templates to complete the query generation. This method can only achieve queries with simple semantics and cannot parse complex semantics, resulting in low query accuracy. Furthermore, for query statements generated by writing templates, the differences in knowledge graphs across industries lead to poor system reusability, requiring the configuration of a large number of templates, making the operation complex and lacking in reusability.
[0004] Therefore, there is an urgent need for a method to determine the query statement for knowledge graphs, so as to improve query accuracy, reduce operational complexity, and enhance reusability. Summary of the Invention
[0005] This invention provides a method, apparatus, device, medium, and product for determining knowledge graph query statements. It addresses the shortcomings of existing technologies where simple semantic queries result in low accuracy, and complex operations and poor reusability are achieved through template queries for complex statements. The invention analyzes the initial query statement based on a user intent analysis model to obtain the user's intent and corresponding intent type. Based on the user intent type, a corresponding target knowledge graph query template is determined. Simultaneously, a knowledge query statement construction model analyzes the entities, attributes, and relationships between entities included in the initial query statement to obtain the knowledge query statement. Then, based on the knowledge query statement and the target knowledge graph query template, the corresponding knowledge graph query statement is determined. This leverages the model's powerful semantic understanding capabilities to extract the user's retrieval intent from the user's question, expressing it as a combination of entities, attributes, and relationships in the knowledge query statement. The invention also constructs a knowledge retrieval statement based on the user's question intent, resulting in a knowledge graph query statement. This improves the accuracy of knowledge graph retrieval, reduces operational complexity, and enhances reusability.
[0006] This invention provides a method for determining a knowledge graph query statement, comprising the following steps.
[0007] Obtain the initial query statement; the initial query statement contains the user's intent, entities, attributes, and relationships between entities for the question they want to query.
[0008] The initial query statement is input into the user intent analysis model to obtain the user intent type output by the user intent analysis model. The user intent analysis model is trained based on user intent query statement samples and is used to analyze the type of intent in the initial query statement.
[0009] The initial query statement is input into the knowledge query statement construction model to obtain the knowledge query statement output by the knowledge query statement construction model. The knowledge query statement construction model is trained based on the query statement association samples and is used to analyze the entities, attributes and relationships between entities in the initial query statement.
[0010] The target knowledge graph query template is determined based on the user intent type and the knowledge graph query template database. The knowledge graph query template database is a database containing user intent types and the corresponding knowledge graph query templates, with a one-to-one correspondence between user intent types and knowledge graph query templates.
[0011] The knowledge graph query statement corresponding to the initial query statement is determined based on the knowledge query statement and the target knowledge graph query template; the knowledge graph query statement is the query statement after performing intent type analysis, entity, attribute and inter-entity relationship analysis on the initial query statement.
[0012] According to the method for determining a knowledge graph query statement provided by the present invention, the user intent analysis model is trained in the following manner: obtaining user intent query statement samples; inputting the user intent query statement samples into the basic intent analysis model to obtain the basic user intent type output by the basic intent analysis model; optimizing the basic intent analysis model based on the basic user intent type and a first optimization function to obtain the user intent analysis model.
[0013] According to a method for determining a knowledge graph query statement provided by the present invention, the knowledge query statement construction model is trained in the following manner: obtaining query statement association samples; inputting the query statement association samples into the basic statement construction model to obtain the basic query statement output by the basic statement construction model; optimizing the basic statement construction model based on the basic query statement and a second optimization function to obtain the knowledge query statement construction model; wherein the first optimization function and the second optimization function are different optimization functions.
[0014] According to a method for determining a knowledge graph query statement provided by the present invention, the method determines the knowledge graph query statement corresponding to the initial query statement based on the knowledge query statement and the target knowledge graph query template, including: determining the target knowledge query statement based on the knowledge query statement and the ontology specification standard; wherein, the ontology specification standard is a pre-defined standard expression containing entities, attributes and relationships between entities, and the ontology specification standard is a standard used to standardize the knowledge query statement; and determining the knowledge graph query statement corresponding to the initial query statement based on the target knowledge query statement and the target knowledge graph query template.
[0015] According to a method for determining a knowledge graph query statement provided by the present invention, the target knowledge query statement is determined based on the knowledge query statement and the ontology specification standard, including: determining an initial knowledge query statement based on the knowledge query statement and the ontology specification standard; wherein, the initial knowledge query statement is the result of standardizing the knowledge query statement through the ontology specification standard; and supplementing the initial knowledge query statement with a knowledge reasoning rule base to determine the target knowledge query statement; wherein, the knowledge reasoning rule base is a rule base used to supplement the initial knowledge query statement with inter-entity relationships.
[0016] According to a method for determining a knowledge graph query statement provided by the present invention, after determining the knowledge graph query statement corresponding to the initial query statement based on the knowledge query statement and the target knowledge graph query template, the method further includes: inputting the knowledge graph query statement into a knowledge graph engine to obtain the statement query result output by the knowledge graph engine; wherein, the knowledge graph engine is a tool used to query and retrieve the knowledge graph query statement to obtain the statement query result corresponding to the knowledge graph query statement.
[0017] The present invention also provides a device for determining a knowledge graph query statement, comprising the following modules.
[0018] The statement retrieval module is used to retrieve the initial query statement; the initial query statement contains the user's intent, entities, attributes, and relationships between entities for the question they want to query.
[0019] The type output module is used to input the initial query statement into the user intent analysis model and obtain the user intent type output by the user intent analysis model. The user intent analysis model is trained based on user intent query statement samples and is a model used to analyze the type of intent in the initial query statement.
[0020] The statement output module is used to input the initial query statement into the knowledge query statement construction model and obtain the knowledge query statement output by the knowledge query statement construction model. The knowledge query statement construction model is trained based on the query statement association samples and is used to analyze the entities, attributes and relationships between entities in the initial query statement.
[0021] The template determination module is used to determine the target knowledge graph query template based on the user intent type and the knowledge graph query template database. The knowledge graph query template database is a database containing user intent types and the corresponding knowledge graph query templates, with a one-to-one correspondence between user intent types and knowledge graph query templates.
[0022] The statement determination module is used to determine the knowledge graph query statement corresponding to the initial query statement based on the knowledge query statement and the target knowledge graph query template. The knowledge graph query statement is the query statement after performing intent type analysis, entity, attribute and inter-entity relationship analysis on the initial query statement.
[0023] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement any of the above-described methods for determining a knowledge graph query statement.
[0024] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a method for determining any of the knowledge graph query statements described above.
[0025] The present invention also provides a computer program product, including a computer program, which, when executed by a processor, implements a method for determining any of the knowledge graph query statements described above.
[0026] This invention provides a method, apparatus, device, medium, and product for determining a knowledge graph query statement. The method involves: acquiring an initial query statement, wherein the initial query statement contains the user's intent, entities, attributes, and relationships between entities; inputting the initial query statement into a user intent analysis model to obtain the user intent type output by the model; wherein the user intent analysis model is trained based on user intent query statement samples and is used to analyze the type of intent in the initial query statement; and inputting the initial query statement into a knowledge query statement construction model to obtain the knowledge query statement output by the model; wherein the knowledge query statement construction model is based on... The query statement association sample training model is used to analyze entities, attributes, and relationships between entities in the initial query statement. The target knowledge graph query template is determined based on the user intent type and the knowledge graph query template database. The knowledge graph query template database contains user intent types and their corresponding knowledge graph query templates, with a one-to-one correspondence. The knowledge graph query statement corresponding to the initial query statement is determined based on the knowledge query statement and the target knowledge graph query template. The knowledge graph query statement is the query statement obtained after performing intent type analysis, entity, attribute, and relationship analysis on the initial query statement. The technical solution of this invention addresses the shortcomings of existing technologies, such as low accuracy in simple semantic queries and cumbersome operation and poor reusability in complex queries requiring template queries. It achieves this by analyzing the initial query statement based on a user intent analysis model to obtain the user's intent and corresponding intent type. Based on the intent type, a corresponding target knowledge graph query template is determined. Simultaneously, a knowledge query statement construction model analyzes the entities, attributes, and relationships between entities included in the initial query statement to obtain the knowledge query statement. Then, based on the knowledge query statement and the target knowledge graph query template, the corresponding knowledge graph query statement is determined. This leverages the model's powerful semantic understanding capabilities to extract the user's retrieval intent from the user's question, expressing it as a combination of entities, attributes, and relationships in the knowledge query statement. The knowledge retrieval statement is then constructed based on the user's question intent, resulting in the knowledge graph query statement. This improves the accuracy of knowledge graph retrieval, reduces operational complexity, and enhances reusability. Attached Figure Description
[0027] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0028] Figure 1 This is a flowchart illustrating the method for determining knowledge graph query statements provided by the present invention.
[0029] Figure 2 This is a schematic diagram of the structure of the knowledge graph query statement determination device provided by the present invention.
[0030] Figure 3 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation
[0031] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0032] The following is combined with Figure 1 The present invention describes a method for determining knowledge graph query statements. This method is applicable to the determination of knowledge graph query statements and knowledge graph retrieval. The execution subject of this method can be an electronic device or a knowledge graph query statement determination device installed in the electronic device. The knowledge graph query statement determination device can be implemented by software, hardware, or a combination of both. Figure 1 This is a flowchart illustrating the method for determining knowledge graph query statements provided by the present invention, such as... Figure 1 As shown, the method includes the following steps 101, 102, 103, 104 and 105.
[0033] Step 101: Obtain the initial query statement.
[0034] In this step, the initial query statement contains the user's intent regarding the question they want to query, the entities, attributes, and relationships between entities.
[0035] Specifically, obtain the initial query statement containing the user's intent to query, entities, attributes, and relationships between entities.
[0036] For example, the initial query could be "What is the information of this person, so-and-so?", where "so-and-so" is an entity, the attribute is "name", and the relationship between entities is "so-and-so - information (name)". This embodiment does not limit this.
[0037] Step 102: Input the initial query statement into the user intent analysis model to obtain the user intent type output by the user intent analysis model.
[0038] In this step, the user intent analysis model is trained based on user intent query statement samples. The user intent analysis model is a model used to analyze the type of intent in the initial query statement.
[0039] User intent types primarily include entity queries, relationship queries, attribute queries, path queries, list queries, statistical queries, sorting queries, aggregation queries, and casual conversation. Entity queries are for users seeking specific entity information within a knowledge graph. Entity queries typically involve the entity's name, unique identifier, or other key attributes. For example, the initial query for an entity query might be: "Please tell me information about '[Entity Name]'." Relationship queries are for users wanting to understand the specific relationship between two entities. Relationship queries focus on the connections and interactions between entities. For example, the initial query for a relationship query might be: "What is the relationship between '[Entity A]' and '[Entity B]'?" Attribute queries are for users interested in a specific attribute of an entity and want to obtain the value of that attribute. For example, the initial query for an attribute query might be: "Please provide the '[Attribute Name]' information for '[Entity Name]'." Path queries are for users wanting to find the shortest path or multiple relationship paths between two entities. For example, the initial query for a path query might be: "Please find the shortest path between '[Entity A]' and '[Entity B]'." List queries are for users wanting to obtain a list of entities that meet specific conditions. For example, the initial query for a list query is: Please list all entities that satisfy "[condition]". A statistical query is used when a user wants to count the number of entities or relationships in the knowledge graph. For example, the initial query for a statistical query is: Please count how many entities satisfy "[condition]". A sorting query is used when a user wants to sort the query results based on a certain attribute. For example, the initial query for a sorting query is: Please sort "[entity name]" by "[attribute name]". A aggregation query is used when a user wants to aggregate the query results, such as calculating the sum, average, maximum, or minimum value. For example, the initial query for an aggregation query is: Please calculate the sum / average / maximum / minimum of "[attribute name]" for all "[entity name]". A casual chat is a request from a user that is unrelated to the knowledge graph query. For example, the initial query for a casual chat is: The weather is really nice today.
[0040] Specifically, the initial query statement is input into the user intent analysis model, which then identifies the intent type of the initial query statement, thereby obtaining the user intent type output by the user intent analysis model.
[0041] In one specific implementation, the user intent analysis model output includes the user intent type ("core_intent", i.e., "core intent type"), as well as "focus_element": "the most direct focus of the question (no need to classify concepts / attributes / relationships)", and "reason": "judgment statement (such as interrogative words, keywords, context, etc.)", which are not limited in this embodiment.
[0042] For example, the processing principle of the user intent analysis model is as follows: the focus element = the target most directly pointed to by the question (such as "capacity", "price", "advantages and disadvantages"); prioritize extracting elements explicitly mentioned in the initial query, and then infer the implicit focus; if the question involves multiple candidate focuses, select the one or two that best match the user intent; if the user intent type is "relational query" or "path query", include two entities related to the query; for other intent category tags, include one entity of interest in the query; if the user intent category tag is "attribute query", this is the attribute that the user is interested in; if the user intent category tag is "statistical query", "sorting query", or "aggregation query", and the data objects for statistics, sorting, and aggregation are attributes, then this is the attribute that the user is interested in. For example, if the initial query is "What is the typical battery capacity of a smartphone?", the output of the user intent analysis model would be {"core_intent": "attribute query", "focus_element": "battery capacity", "reason": the question word "how much" directly points to capacity}.
[0043] In one specific implementation, the user intent analysis model is trained by: obtaining user intent query statement samples; inputting the user intent query statement samples into the basic intent analysis model to obtain the basic user intent type output by the basic intent analysis model; and optimizing the basic intent analysis model based on the basic user intent type and a first optimization function to obtain the user intent analysis model.
[0044] In this step, the basic user intent type could be, for example, Qwen3-32B (a latest generation of large language model that uses complex logical reasoning for sentence analysis), but this embodiment does not limit this.
[0045] The first optimization function is used to train the basic intent analysis model and adjust the parameters of the basic intent analysis model to minimize or maximize a well-defined objective function. This embodiment does not limit this.
[0046] Specifically, the process involves obtaining a sample of user intent query statements; inputting the sample of user intent query statements into the basic intent analysis model to obtain the basic user intent type output by the basic intent analysis model; determining whether the basic user intent type meets the type preset conditions, which include the statement and the type corresponding to the statement; if the basic user intent type does not meet the type preset conditions, optimizing the basic intent analysis model based on the basic user intent type and the first optimization function until the basic user intent type meets the type preset conditions, at which point the model optimization stops, and the user intent analysis model is obtained.
[0047] Step 103: Input the initial query statement into the knowledge query statement construction model to obtain the knowledge query statement output by the knowledge query statement construction model.
[0048] In this step, the knowledge query statement construction model is trained based on the associated samples of the query statement. The knowledge query statement construction model is used to analyze the entities, attributes and relationships between entities in the initial query statement.
[0049] Specifically, the initial query statement is input into the knowledge query statement construction model, and the knowledge query statement output by the knowledge query statement construction model is obtained.
[0050] The knowledge query statement construction model consists of three layers: entity extraction, attribute extraction, and relationship construction between entities. Different prompt words are designed for each layer.
[0051] First, the first layer extracts entities from the user's question (initial query statement). After obtaining the extraction results, the original labels are replaced by alignment with the ontology concept list. The core part of the first layer prompt words may include, for example: Role, you are a knowledge graph extraction expert, your task is to extract entities and their corresponding attributes based on the provided text data content, classify the entities, and select the relationships between entities from the relationship categories. The output content should include the following parts: entities, attributes and relationships; Definition, (1) Category label values of entities: employees, first-level departments and second-level departments, etc.; (2) Category label values of relationships: "WORK_IN" (two entities have a WORK_IN relationship in the initial query statement, for example: "Li XX works in Sales Department 1", then Li XX has a WORK_IN relationship with Sales Department 1); Rule, (1) the returned output format must be a standard lightweight data exchange format (JavaScript Object Notation, JSON) data, do not add any explanation or description, and ensure that the returned JSON The data format is correct, such as: [{{"entities":[{{"name":"XX","attr":["Name":"Li XX",...],"label":"Employee"}},...],"relations":[{{"entity1":{{"name":"Li XX","label":"Employee"}},"entity2":{{"name":"Sales Department 1","label":"Secondary Department"}},"relation":{{"name":"WORK_IN"}}}},...]}}]; (2) Entity uniqueness: One list element in the entities list corresponds to one entity, represented by a dictionary type in Python (a programmable language). The name in the entity corresponds to the name in the original text, and the same entity name cannot be extracted repeatedly; (3) Entity authenticity: The extracted entity name value should be real and unique, and the corresponding original text can be found in the text; (4) Entity category authenticity: label corresponds to the entity category, and the label value must be extracted from the category label value of the entity I provided to you in Define. The provided text data is as follows: {text}.
[0052] Based on the results of the first-level extraction, the second-level prompts perform attribute extraction. During the extraction process, the data format is converted, and attribute labels corresponding to predefined concepts are extracted. The core part of the second-level prompts is as follows: Role: You are an attribute category classification expert. Your task is to select the attribute category corresponding to "attribute text" based on the entity name and the given "attribute category" definition. I now have a batch of entities and their attributes, for example: [{"text":"Entity 1","label_text":"Entity 1 category","attributes":["attribute text 1","attribute text 2"]},{"text":"Entity 2","label_text":"Entity 2 category","attributes":["attribute text 1","attribute text 2"]}], where the value of "text" is the entity name, and the list corresponding to "attributes" stores multiple attributes corresponding to the entity. Strictly speaking, the value of label in each element of attributes must be selected from the given "included attribute categories". You cannot create new values; even if there are no new values, you can only choose the closest one. The result you return must be standard JSON; do not add any explanations or descriptions. Define: Attribute category definition: {label}. Rule: (1) Based on the attribute category definition above, and combining the "text" entity text and entity category at this time, select the most suitable attribute category from the "included attribute categories" definition of the corresponding entity category above for each attribute in "attributes". (2) The output format must be a standard JSON. Do not add any explanations or descriptions. Explanatory words such as "Please note" or "Note" are not allowed. This is very important. The output format is as follows: [{{"text":"Entity 1","label_text": "Entity 1 category","attributes":[{{"name":"Attribute text 1","label":"Attribute category (select 1 value from the attribute categories included in the above entity 1 category. Do not create non-existent values)"}}...]}},...]. (3) The selected attribute category must be selected from the attribute category definition. Steps: (1) Process each element of the input list, and take the first element; (2) Obtain the attribute categories contained in the "attribute category" definition according to the entity category "label_text". For the list of attributes of the entity, judge the category of "attribute text" one by one, and select the most similar or most appropriate value from the included attribute categories until all values in attributes have been judged. Do not create new included attribute categories; (3) Take the next element until the input list has been processed; (4) Assemble into the specified format and output.
[0053] The prompt words are dynamically adjusted, and the adjusted prompt words and the extraction results of the second layer are passed to the third layer. The third layer extracts the relationships, and after extraction, regular expressions are used to adjust the relationships between the entities to the relationship types defined in the ontology.
[0054] The core of the third-level prompt is as follows: Role: You are a relation category classification expert. Your task is to select the subcategory corresponding to "sub_text" based on the semantics of two entities "from_o_text" and "to_o_text" in the text "example_text", and in combination with the given relation category "text" and the "definition of relation category". There is currently a batch of relation samples, for example: [{'example_text':'Li XX works in Sales Department 1.',"text":"Work Relationship","from_o_text":"Li XX","to_o_text":"Sales Department 1"}]. The currently given categories are stored in "text". Your task is to combine the semantics of the two entities in the text, select a more detailed category classification from the relation category definition, and store it in "sub_text". Finally, the output of the knowledge query statement model must be a standard JSON, without any explanation or description. Strictly speaking, the value of "sub_text" must be selected from the "related subcategories" of the given "text", and a new value cannot be created. If there is no suitable one, the closest one should be selected. Define: Relation category definition: {label}. Rule: (1) According to the relation category definition below, combined with the semantic environment of from_o_text and to_o_text in the example_text text, the broad parent category of the input text value needs to be changed to the most suitable subcategory. (2) Output format It must be standard JSON, without any explanations or descriptions, and must not contain explanatory phrases such as "Please note" or "Note". This is very important. The output format of the third layer can be, for example: [{{"text":"Relationship Category 1","sub_text":"Relationship Category 2",(Select a value from the "sub-categories related to Relationship Category 1" contained in the above relationship category definition, do not create new values!!!)"from_o_text":"Entity Text 1","to_o_text":"Entity Text 2"}}...]. The knowledge query statement (knowledge query path) is formed from the results extracted from the third layer. To find an entity, it can be represented in the form of entity, entity=e,C(a,A((=|>|<)v))(r,Re,C(a,A((=>|<)v))).
[0055] Where, e represents the entity extracted by the knowledge query statement construction model in the initial query statement, C represents the concept corresponding to e in the ontology (included in the ontology specification standard) as determined by the knowledge query statement construction model, r represents the relation extracted by the knowledge query statement construction model in the initial query statement, R represents the relation corresponding to r in the ontology as determined by the knowledge query statement construction model, a represents the attribute of entity e extracted by the knowledge query statement construction model in the initial query statement, A represents the attribute corresponding to a in the ontology as determined by the knowledge query statement construction model, and v is the value of a in the question of the initial query statement. a,A((=|>|<)v) represents the query condition represented by attributes when querying a certain entity, and formula (2) represents the knowledge query statement when querying a certain entity, that is, the knowledge query path of the knowledge query statement as the initial query statement.
[0056] Furthermore, the query schemes for different user intent types are not entirely the same. For example, it can be [entity, entity] "relationship query", "path query"; [entity] "entity query", "list query", "statistical query", "sort query"; [entity, intention-attribute] "attribute query", "statistical query", "aggregate query". This embodiment does not limit this.
[0057] In one specific implementation, the knowledge query statement construction model is trained in the following way: obtaining query statement association samples; inputting the query statement association samples into the basic statement construction model to obtain the basic query statement output by the basic statement construction model; optimizing the basic statement construction model based on the basic query statement and the second optimization function to obtain the knowledge query statement construction model; wherein the first optimization function and the second optimization function are different optimization functions.
[0058] In this step, the second optimization function is used to train the basic statement construction model and adjust the parameters of the basic statement construction model to minimize or maximize a well-defined objective function. This embodiment does not limit this.
[0059] Specifically, the process involves obtaining associated samples of the query statements; inputting these samples into the basic statement construction model to obtain the basic construction results output by the model; determining whether the basic construction results meet the preset conditions for the statements, which include the statements and their corresponding entities, attributes, and relationships between entities; if the basic construction results do not meet the preset conditions, optimizing the basic statement construction model based on the basic construction results and the second optimization function until the basic construction results meet the preset conditions, at which point the model optimization stops, resulting in the knowledge query statement construction model.
[0060] Step 104: Determine the target knowledge graph query template based on the user intent type and the knowledge graph query template database.
[0061] In this step, the knowledge graph query template database is a database that contains user intent types and corresponding knowledge graph query templates, with a one-to-one correspondence between user intent types and knowledge graph query templates.
[0062] Specifically, after determining the user intent type, the system searches the knowledge graph query database for the knowledge graph query template corresponding to the user intent type, thereby identifying the retrieved knowledge graph query template as the target knowledge graph query template.
[0063] For example, the correspondence between user intent types and knowledge graph query templates can be shown in Table 1.
[0064] Table 1
[0065]
[0066] In Table 1, uppercase letters (C, R, A) typically represent concepts in the ontology, i.e., the schema layer of the graph. They are the types of categories, relation types, or attribute names. Lowercase letters (a, v) typically represent instance data in specific knowledge query statements within the graph, i.e., the data layer. 'a' is a specific property key, and 'v' is the corresponding property value. Curly braces {} and single quotes ' are used in queries. Curly braces {} are used to define the property list of nodes or relations. {C}, {R}, {a}, {v}, {A}, {Direction}, and {AggregateFunction} in the template are placeholders that need to be dynamically populated based on the user's intent type. {C}, etc., represent placeholders that need to be replaced with the ontology name; the outer {} in {{a:'{v}'}} is the attribute definition syntax, and the inner '{v}' indicates that the attribute value 'v' needs to be replaced and is enclosed in single quotes (assuming 'v' is a string). Other letters (e, r, p, n): These are variable names used to bind results in a Cypher query. e typically binds to an entity, r to a relationship, p to a path, and n to a node. These names are conventional and can be modified as needed; this embodiment does not impose any limitations on them.
[0067] For example, for entity queries of different user intent types, (1) Template: MATCH (e:{C} {{a: '{v}'}}) RETURN e; Explanation: {C}: needs to be replaced with the entity type involved in the user query (class in the ontology, such as Person, Company, Disease). {a}: needs to be replaced with the attribute name used to find the entity (attribute in the ontology, such as name, id, title). {v}: needs to be replaced with the specific value corresponding to the attribute {a} (data value in the graph, such as 'Zhang X', 'C001', 'Pneumonia'). Function: Based on the specified type ({C}), attribute name ({a}), and attribute value ({v}), find and return all information (the node itself and all its attributes) of a single entity node (e) that meets the conditions. (2) Initial query statement of a user question example: "What information is there about Zhang X?". (3) Convert to knowledge query statement: {C}->Person (assuming the class name of person in the ontology is Person) {a}->name (assuming the name attribute is used for search) {v}->'Zhang X' Final query: MATCH (e:Person {name: 'Zhang X'}) RETURN e. (4) Letter correspondence: {C}->Person (corresponding to the entity type "person" in the intent); {a}->name (corresponding to the attribute "name" in the search statement); {v}->'Zhang X' (corresponding to the specific name value "Zhang X"). This embodiment does not limit this.
[0068] For relational queries of different user intent types, (1) Template: MATCH (e:{C} {{a: '{v}'}})-[r:{R}]->(e:{C} {{a: '{v}'}}) RETURN (Note: This template has two problems: 1. Both node variables are named e, which will cause confusion; 2. The two nodes are usually of different types or different values. A more general template is explained below. (2) Explanation (revised general version): {C1}: Entity type of the starting node. {a1}: Attribute name used to find the starting node. {v1}: Specific value corresponding to the starting node attribute {a1}. {R}: Relation type to be queried (relationship in the ontology, such as WORK_AT, HAS_SYMPTOM, LOCATED_IN). {C2}: Entity type of the target node. {a2}: Attribute name used to find the target node (if a specific target node is needed). {v2}: Specific value corresponding to the target node attribute {a2} (if a specific target node is needed). (Note: {a2} and {v2} are only needed when querying a specific relationship between two specific nodes. More commonly, it is used to query a specific relationship between two specific nodes.) A certain relationship starting from a fixed node, the type of the target node may be known or unknown, and the value is usually not specified). Function: Find the relationship starting from a specific starting node (type {C1} and {a1}={v1}), through a specific relation type ({R}), pointing to a specific target node (type {C2} and {a2}={v2}), if the provided relation (r) is provided. Return the relation itself and its attributes. (3) Initial query statement of the user question example (query a specific relation): "What are the details of Zhang X's employment relationship with TengX?" (assuming the relation type is called WORK_AT); (4) Transformed into a knowledge query statement: {C1}->Person; {a1}->name; {v1}->'Zhang X'; {R->WORK_AT; {C2}->Company (assuming the company's class name is Company); {a2}-name; {v2}->'TengX'; Final query: MATCH (p:Person {name: 'Zhang X'})-[r:WORK_AT]->(c:Company {name: 'Teng X'}) RETURNr (the variable names were changed to p and c to avoid confusion); (5) Letter correspondence: {C1}->Person (starting node type "person"); {a1}->name (starting node lookup attribute "name"); {v1}->'Zhang X' (starting node value "Zhang X"); {R}->WORK_AT (relationship type "employment"); {C2}->Company (target node type "company"); {a2}->name (target node lookup attribute "name"); {v2}->'Teng X' (target node value "Teng X").(6) Initial query statement of user question example (more common - query the relationship starting from a specific node): "Which companies has Zhang X worked for?" (Only care about the relationship type and starting node, do not specify the specific target node); (7) Convert to knowledge query statement (simplified, do not specify the target node value): {C1}->Person; {a1}->name; {v1}->'Zhang X'; {R}->WORK_AT; {C2}->Company (or omitted:Company if the target type is not restricted); (omit {a2} and {v2}); (8) Final query: MATCH(p:Person{name:'Zhang X'})-[r:WORK_AT]->(c:Company) RETURN r, c (usually the target node c will also be returned to display company information); (9) Letter correspondence (simplified): {C1}->Person; {a1}->name; {v1}->'Zhang X'; {R}->WORK_AT, this embodiment does not limit this.
[0069] For attribute queries of different user intent types, (1) Template: MATCH (e:{C} {{a: '{v}'}}) RETURN e.{a}; (2) Explanation: {C}: Entity type of the target node; {a}: Attribute name used to find the node (locating the node) and the attribute name to be returned (target attribute); (Note: Here {a} is used for two purposes: locating the node and selecting the attribute to be returned. In practice, the attribute (a1) of the located node and the attribute (a2) to be queried may be different); {v}: The specific value corresponding to the attribute {a} of the located node. (3) Function: First, find a specific node based on the type ({C}), the location attribute name ({a}), and the location attribute value ({v}), and then return the value of the specified attribute (e.{a}) of that node. (Note: {a} in the template is the same attribute when locating and returning. To query different attributes b of node e, the template should be modified to RETURN eb); (4) Initial query statement of user question example (by template): "What is Zhang X's email address?" (Assuming that the locating attribute and the query attribute are both name? This is usually unreasonable); (5) Convert to knowledge query statement (by template - unreasonable): {C}->Person; {a}->name (used for both locating and returning? Returning name is meaningless); {v}->'Zhang X'; Final query (by template): MATCH (e:Person{name: 'Zhang X'}) RETURN e.name (returns the name 'Zhang X' itself, not the email address); (6) Letter correspondence (by template): {C}->Person; {a}->name; {v}-'Zhang X'; (7) Modify template (more reasonable): MATCH (e:{C}{{a1: '{v}'}}) RETURN e.{a2};{a1}: Attribute name used to locate the node;{a2}: Attribute name to be queried / returned. (8) Initial query statement of user question example (reasonable): "What is Zhang X's email address?";(9) Converted into knowledge query statement (corrected): {C}->Person;{a1}->name (locating attribute); {v}->'Zhang X' (locating value); {a2}->email (queried / returned attribute); (10) Final query (corrected): MATCH (e:Person {name: 'Zhang X'}) RETURNe.email;(11) Letter correspondence (corrected): {C}->Person;{a1}->name (corresponding to the attribute "name" of the located entity in the intent); {v}->'Zhang X' (corresponding to the value "Zhang X" of the located entity in the intent); {a2}->email (corresponding to the attribute "email" to be queried in the intent), this embodiment does not limit this.
[0070] For path queries of different user intent types, (1) Template: MATCH p=shortestPath((e:{C}{{a: '{v}'}})-[ ]->(e:{C} {{a: '{v}'}})) RETURN p(Note: both variables are named e, which can be confusing); (2) Explanation: {C1}: Entity type of the starting node of the path; {a1}: Attribute name used to find the starting node; {v1}: Specific value corresponding to the starting node attribute {a1}; {C2}: Entity type of the target node of the path; {a2}: Attribute name used to find the target node. {v2}: Specific value corresponding to the target node attribute {a2}; [ ]: Represents a path of arbitrary length (0 to multiple hops), and the range can be limited as shown in [ ..5] (maximum 5 jumps); shortestPath(): function is used to find the shortest path between two points; function: find the shortest path (p) between the node of type {C1} and attribute {a1} equal to {v1} (starting node) and the node of type {C2} and attribute {a2} equal to {v2} (target node), the path includes all nodes and relationships along the way; (3) initial query statement of user question example: "What is the shortest relationship path between Zhang X and Teng X?"; (4) converted into knowledge query statement: {C1}->Person; {a1}->name; {v1}->'Zhang X'; {C2}->Company; {a2}->name; {v2}->'Teng X'; final query: MATCH p=shortestPath((p1:Person {name: 'Zhang X'})-[ ]-(c1:Company{name: 'TengX'})) RETURN p(The variable names p1 and c1 have been changed to avoid confusion; -[ ] - indicates no direction or any direction); (5) Letter correspondence: {C1}->Person (starting node type "person"); {a1}->name (starting node search attribute "name"); {v1}->'ZhangX' (starting node value "ZhangX"); {C2}->Company (target node type "company"); {a2}->name (target node search attribute "name"); {v2}->'TengX' (target node value "TengX"). This embodiment does not limit this.
[0071] For list queries of different user intent types, (1) Template: MATCH (e:{C} {{a: '{v}'}}) RETURN n (Note: e is used for matching, n is used for returning, which is inconsistent); (2) Explanation (corrected): {C}: the entity type of the node to be queried; {{a: '{v}'}}: (optional) attribute conditions used to filter nodes. If specific attribute values do not need to be filtered, this part can be omitted (e.g., MATCH (e:Person) RETURN e returns all people); Function: find all nodes (e) that match the type ({C}) and the optional attribute conditions ({{a:'{v}'}}) and return a list of these nodes. (3) Initial query statement (with conditions) of the user question example: "List all people aged 30." (4) Convert to a knowledge query statement (correct variable name): {C}->Person; {a}->age; {v}->30 (Note: numeric values do not need single quotes); final query: MATCH(e:Person {age: 30}) RETURN e. (5) Letter correspondence: {C}->Person (corresponds to the entity type "person" in the intent); {a}->age (corresponds to the filter condition attribute "age"); {v}->30 (corresponds to the filter condition value "30"); (6) Initial query statement of the user question example (unconditional): "List all companies."; (7) Convert to a knowledge query statement: {C}->Company; (omit {{a: '{v}'}}); final query: MATCH (e:Company) RETURN e; (8) Letter correspondence: {C}->Company (corresponds to the entity type "company" in the intent), this embodiment does not limit this.
[0072] For statistical queries of different user intent types, (1) Template: MATCH (e:{C} {{a: '{v}'}}) RETURN count(n) (Note: e is used for matching, n is used for statistics, which is inconsistent); (2) Explanation (corrected): {C}: Entity type of the node to be counted; {{a:'{v}'}}: (optional) Attribute conditions used to filter nodes. If no filtering is needed, this part can be omitted; count(e): The aggregate function count() is used to calculate the number of matched nodes e; Function: Count the total number of nodes (e) that match the type ({C}) and the optional attribute conditions ({{a:'{v}'}}). (3) Initial query statement of the user question example (with conditions): "How many employees does TengX Company have?" (Assume that the employees are of type Person and are connected to the Company node TengX through the WORK_AT relationship. This template needs to be expanded to handle relationships! See the correction below) (4) Problem: The original template can only count the number of nodes of a certain type with specific attributes and cannot directly handle the statistics through relationships (such as the number of employees of a company); Corrected template (handling relationships): MATCH (c:Company {name: 'TengX'})<-[:WORK_AT]-(e:Person) RETURN count(e); (5) Initial query statement of the user question example (conforming to the original template): "How many companies have a registered capital of more than 1 billion?". (6) Convert to knowledge query statement (correct variable name): {C}->Company; {a}->registered_capital; {v}->1000000000 (1 billion, numeric value without quotes); final query: MATCH (e:Company {registered_capital: 1000000000}) RETURN count(e) (or more flexible WHERE e.registered_capital>1000000000); (7) letter correspondence: {C}->Company (statistical target type "company"); {a}->registered_capital (filter condition attribute "registered capital"); {v}->1000000000 (filter condition value "1 billion"), this embodiment does not limit this.
[0073] For sorting queries of different user intent types, (1) Template: MATCH (e:{C}) RETURN e ORDERBY e.{A} {Direction}. (2) Explanation: {C}: Entity type of the node to be queried and sorted; {A}: Attribute name (attribute in the ontology) used for sorting statement; {Direction}: Sorting direction, which needs to be replaced with ASC (ascending order, from smallest to largest) or DESC (descending order, from largest to smallest); Function: Find all nodes (e) of type {C} and sort them according to the value of their attribute {A} (ORDER BY e.{A} {Direction}), and then return the sorted list of nodes. (Usually needs to be used in conjunction with LIMIT, otherwise all nodes are returned). (3) Initial query statement of user question example: "List all companies, sorted by registered capital from highest to lowest, and take the top 10." (4) Convert to knowledge query statement: {C}->Company; {A}->registered_capital; {Direction}->DESC; Final query (with LIMIT): MATCH (e:Company)RETURN e ORDER BY e.registered_capital DESC LIMIT 10; (5) Letter correspondence: {C}->Company (sorting target type "company"); {A}->registered_capital (sorting statement attribute "registered capital"); {Direction}->DESC (sorting direction "high to low" corresponds to descending order), this embodiment does not limit this.
[0074] For aggregation queries of different user intent types, (1) Template: MATCH (e:{C}) RETURN{AggregateFunction}(n.{A}) (Note: e is used for matching, n.{A} is used for aggregation, which is inconsistent); (2) Explanation (corrected): {C}: the entity type of the node whose data needs to be aggregated; {AggregateFunction}: needs to be replaced with the name of the aggregation function, such as sum, avg, max, min, count; {A}: the name of the attribute whose value needs to be aggregated (the attribute in the ontology); Function: find all nodes (e) of type {C}, apply the specified aggregation function ({AggregateFunction}) (such as sum, average, maximum, minimum, count, etc.) to the value of their attribute {A}, and return the aggregation result (a single value). (3) Initial query statement of the user question example: "What is the average age of all employees?". (4) Convert to a knowledge query statement (correct variable names): {C}->Person (assuming the employee type is Person); {AggregateFunction}->avg; {A}->age; final query: MATCH (e:Person) RETURN avg(e.age). (5) Letter correspondence: {C}->Person (aggregate target type "employee" / "person"); {AggregateFunction}->avg (aggregate function "average"); {A}->age (aggregate statement attribute "age"). This embodiment does not limit this.
[0075] Step 105: Determine the knowledge graph query statement corresponding to the initial query statement based on the knowledge query statement and the target knowledge graph query template.
[0076] In this step, the knowledge graph query statement is a query statement that has undergone intent type analysis, entity, attribute and inter-entity relationship analysis after the initial query statement.
[0077] Specifically, after obtaining the knowledge query statement, the knowledge query statement is filled into the target knowledge graph query template, thereby determining the knowledge graph query statement corresponding to the initial query statement.
[0078] In one specific implementation, determining the knowledge graph query statement corresponding to the initial query statement based on the knowledge query statement and the target knowledge graph query template includes: determining the target knowledge query statement based on the knowledge query statement and the ontology specification standard; wherein, the ontology specification standard is a pre-defined standard expression containing entities, attributes, and relationships between entities, and the ontology specification standard is a standard used to standardize the knowledge query statement; and determining the knowledge graph query statement corresponding to the initial query statement based on the target knowledge query statement and the target knowledge graph query template.
[0079] Specifically, the target knowledge query statement is determined based on the knowledge query statement and the ontology specification standard. This involves determining the name similarity between the entity names in the knowledge query statement and the entity names in the ontology specification standard, as well as the table alignment of the entity names. This determines the standard expression corresponding to the entity names in the knowledge query statement. Based on the standard expression, the entity names, attributes, and relationships between entities in the knowledge query statement are modified to determine the target knowledge query statement. The modified target knowledge query statement is then filled into the target knowledge graph query template, thus determining the knowledge graph query statement corresponding to the initial query statement.
[0080] Among them, the entity name alignment table is a table used for knowledge fusion in the process of knowledge graph construction to align the names of different expressions describing the same concept. It has a very high accuracy rate for aligning the names of known entities and their respective concepts.
[0081] For entities not in the entity name alignment table, their entity names are used to extract word vectors. These vectors are then compared with the word vectors of entity names in the same concept's lower-level graph in the ontology specification standard using cosine similarity calculation. Entities above a set threshold are aligned. The cosine similarity calculation formula is as follows: .in, This refers to the entity name in a knowledge query statement. This refers to the entity name in the ontology specification standard; this embodiment does not limit this.
[0082] In one specific implementation, determining the target knowledge query statement based on the knowledge query statement and the ontology specification standard includes: determining the initial knowledge query statement based on the knowledge query statement and the ontology specification standard; wherein, the initial knowledge query statement is the result of standardizing the knowledge query statement through the ontology specification standard; and supplementing the initial knowledge query statement with a knowledge reasoning rule base to determine the target knowledge query statement; wherein, the knowledge reasoning rule base is a rule base used to supplement the initial knowledge query statement with inter-entity relationships.
[0083] Specifically, after obtaining the knowledge query statement, the initial knowledge query statement is determined based on the knowledge query statement and the ontology specification standard, and the initial knowledge query statement is supplemented based on the knowledge reasoning rule base to determine the target knowledge query statement.
[0084] For example, when the obtained knowledge query statement contains C1rCn, C1, Cn, C1rCn, where C1 and Cn are concepts defined in the ontology for entities c1 and cn in the knowledge query statement, and r is the relationship between c1 and cn in the user's question, but there is no corresponding concept definition in the ontology, the query path is interrupted between C1 and Cn. Constructing a knowledge graph query statement in this way may lead to inaccurate query results. By checking the knowledge reasoning rule base, if C1R(CiRi) exists... If the inference rule is Cn->C1RCn, and the r in the query path matches the R in this rule, then C1R (CiRi) of this rule can be used. Cn is used to connect C1 and Cn in the query path, making the query path complete and thus obtaining the target knowledge query statement, which further makes the subsequent determined knowledge graph query statement more accurate.
[0085] The advantage of this setup is that it makes the semantics of subsequent knowledge graph query statements more complete and improves query accuracy.
[0086] In one specific implementation, after determining the knowledge graph query statement corresponding to the initial query statement based on the knowledge query statement and the target knowledge graph query template, the method further includes: inputting the knowledge graph query statement into the knowledge graph engine to obtain the statement query result output by the knowledge graph engine; wherein, the knowledge graph engine is a tool used to query and retrieve the knowledge graph query statement to obtain the statement query result corresponding to the knowledge graph query statement.
[0087] In this step, the knowledge graph engine is a tool used to query and retrieve knowledge graph query statements to obtain the query results corresponding to the knowledge graph query statements. This embodiment does not limit this aspect.
[0088] Specifically, after determining the knowledge graph query statement corresponding to the initial query statement based on the knowledge query statement and the target knowledge graph query template, the knowledge graph query statement is input into the knowledge graph engine to obtain the statement query results output by the knowledge graph engine, and the statement query results are fed back to the user.
[0089] The advantage of this setup is that it determines the knowledge graph query statement based on the initial query statement, thereby improving the query accuracy of the knowledge graph engine.
[0090] This invention provides a method, apparatus, device, medium, and product for determining a knowledge graph query statement. The method involves: acquiring an initial query statement, wherein the initial query statement contains the user's intent, entities, attributes, and relationships between entities; inputting the initial query statement into a user intent analysis model to obtain the user intent type output by the model; wherein the user intent analysis model is trained based on user intent query statement samples and is used to analyze the type of intent in the initial query statement; and inputting the initial query statement into a knowledge query statement construction model to obtain the knowledge query statement output by the model; wherein the knowledge query statement construction model is based on... The query statement association sample training model is used to analyze entities, attributes, and relationships between entities in the initial query statement. The target knowledge graph query template is determined based on the user intent type and the knowledge graph query template database. The knowledge graph query template database contains user intent types and their corresponding knowledge graph query templates, with a one-to-one correspondence. The knowledge graph query statement corresponding to the initial query statement is determined based on the knowledge query statement and the target knowledge graph query template. The knowledge graph query statement is the query statement obtained after performing intent type analysis, entity, attribute, and relationship analysis on the initial query statement. Based on the above embodiments, the technical solution of the present invention addresses the shortcomings of existing technologies, such as low query accuracy for simple semantic queries and complex operation and poor reusability due to the need to write template queries for complex statements. The solution analyzes the initial query statement based on a user intent analysis model to obtain the user's intent and corresponding user intent type. Based on the user intent type, a corresponding target knowledge graph query template is determined. Simultaneously, a knowledge query statement construction model analyzes the entities, attributes, and relationships between entities included in the initial query statement to obtain the knowledge query statement. Then, based on the knowledge query statement and the target knowledge graph query template, a knowledge graph query statement corresponding to the initial query statement is determined. This leverages the powerful semantic understanding capabilities of the model to extract the user's retrieval intent from the user's question, expressing it as a combination of entities, attributes, and relationships in the knowledge query statement. Furthermore, a knowledge retrieval statement is constructed based on the user's question intent to obtain the knowledge graph query statement, thereby improving the accuracy of knowledge graph retrieval, reducing operational complexity, and enhancing reusability.
[0091] The apparatus for determining knowledge graph query statements provided by the present invention will be described below. The apparatus for determining knowledge graph query statements described below can be referred to in correspondence with the method for determining knowledge graph query statements described above.
[0092] Figure 2 This is a schematic diagram of the structure of the knowledge graph query statement determination device provided by the present invention, with reference to... Figure 2 As shown, the knowledge graph query statement determination device 200 includes: a statement acquisition module 201, a type output module 202, a statement output module 203, a template determination module 204, and a statement determination module 205.
[0093] The statement acquisition module 201 is used to acquire the initial query statement; wherein, the initial query statement contains the intent of the question that the user needs to query, entities, attributes and relationships between entities.
[0094] The type output module 202 is used to input the initial query statement into the user intent analysis model and obtain the user intent type output by the user intent analysis model; wherein, the user intent analysis model is trained based on the user intent query statement sample and is a model used to analyze the type of intent in the initial query statement.
[0095] The statement output module 203 is used to input the initial query statement into the knowledge query statement construction model and obtain the knowledge query statement output by the knowledge query statement construction model. The knowledge query statement construction model is trained based on the query statement association samples and is used to analyze the entities, attributes and relationships between entities in the initial query statement.
[0096] The template determination module 204 is used to determine the target knowledge graph query template based on the user intent type and the knowledge graph query template database. The knowledge graph query template database is a database containing user intent types and the corresponding knowledge graph query templates, with a one-to-one correspondence between user intent types and knowledge graph query templates.
[0097] The statement determination module 205 is used to determine the knowledge graph query statement corresponding to the initial query statement based on the knowledge query statement and the target knowledge graph query template; wherein, the knowledge graph query statement is the query statement after performing intent type analysis, entity, attribute and inter-entity relationship analysis on the initial query statement.
[0098] In one example embodiment, the device further includes: a first training module. The first training module is configured to: acquire user intent query statement samples; input the user intent query statement samples into a basic intent analysis model to obtain a basic user intent type output by the basic intent analysis model; and optimize the basic intent analysis model based on the basic user intent type and a first optimization function to obtain a user intent analysis model.
[0099] In one example embodiment, the device further includes a second training module. The second training module is configured to: acquire query statement association samples; input the query statement association samples into a basic statement construction model to obtain a basic query statement output by the basic statement construction model; and optimize the basic statement construction model based on the basic query statement and a second optimization function to obtain a knowledge query statement construction model; wherein the first optimization function and the second optimization function are different optimization functions.
[0100] In one example embodiment, the statement determination module 205 is specifically used to: determine the target knowledge query statement based on the knowledge query statement and the ontology specification standard; wherein, the ontology specification standard is a pre-defined standard expression that includes entities, attributes and relationships between entities, and the ontology specification standard is a standard used to standardize the knowledge query statement; and determine the knowledge graph query statement corresponding to the initial query statement based on the target knowledge query statement and the target knowledge graph query template.
[0101] In one example embodiment, the statement determination module 205 determines the target knowledge query statement based on the knowledge query statement and the ontology specification standard. Specifically, it is used to: determine the initial knowledge query statement based on the knowledge query statement and the ontology specification standard; wherein, the initial knowledge query statement is the result of standardizing the knowledge query statement through the ontology specification standard; and supplement the initial knowledge query statement with a knowledge reasoning rule base to determine the target knowledge query statement; wherein, the knowledge reasoning rule base is a rule base used to supplement the initial knowledge query statement with inter-entity relationships.
[0102] In one example embodiment, the device further includes a statement query module. The statement query module is used to, after determining the knowledge graph query statement corresponding to the initial query statement based on the knowledge query statement and the target knowledge graph query template, input the knowledge graph query statement into the knowledge graph engine to obtain the statement query result output by the knowledge graph engine; wherein, the knowledge graph engine is a tool used to query and retrieve the knowledge graph query statement to obtain the statement query result corresponding to the knowledge graph query statement.
[0103] The apparatus of this embodiment can be used to execute the method of any embodiment in the side embodiment of the method for determining knowledge graph query statements. Its specific implementation process and technical effects are similar to those in the side embodiment of the method for determining knowledge graph query statements. For details, please refer to the detailed description in the side embodiment of the method for determining knowledge graph query statements, which will not be repeated here.
[0104] Figure 3 This is a schematic diagram of the structure of the electronic device provided by the present invention, such as... Figure 3As shown, the electronic device may include: a processor 310, a communication interface 320, a memory 330, and a communication bus 340, wherein the processor 310, the communication interface 320, and the memory 330 communicate with each other through the communication bus 340. The processor 310 can call logical instructions in the memory 330 to execute a method for determining a knowledge graph query statement. This method includes: obtaining an initial query statement; wherein the initial query statement contains the user's intent, entities, attributes, and relationships between entities; inputting the initial query statement into a user intent analysis model to obtain the user intent type output by the user intent analysis model; wherein the user intent analysis model is trained based on user intent query statement samples and is a model used to analyze the type of intent in the initial query statement; inputting the initial query statement into a knowledge query statement construction model to obtain the knowledge query statement output by the knowledge query statement construction model; wherein the knowledge query statement construction... The model is trained based on query statement association samples. The knowledge query statement model is used to analyze entities, attributes, and relationships between entities in the initial query statement. The target knowledge graph query template is determined based on the user intent type and the knowledge graph query template database. The knowledge graph query template database contains user intent types and corresponding knowledge graph query templates, with a one-to-one correspondence between user intent types and knowledge graph query templates. The knowledge graph query statement corresponding to the initial query statement is determined based on the knowledge query statement and the target knowledge graph query template. The knowledge graph query statement is the query statement after performing intent type analysis, entity, attribute, and relationship analysis on the initial query statement.
[0105] Furthermore, the logical instructions in the aforementioned memory 330 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0106] On the other hand, the present invention also provides a computer program product, which includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the method for determining the knowledge graph query statement provided by the above methods. The method includes: obtaining an initial query statement; wherein the initial query statement contains the intent, entities, attributes, and relationships between entities of the question that the user needs to query; inputting the initial query statement into a user intent analysis model to obtain the user intent type output by the user intent analysis model; wherein the user intent analysis model is trained based on user intent query statement samples and is a model used to analyze the type of intent in the initial query statement; inputting the initial query statement into a knowledge query statement to construct a model to obtain... The knowledge query statement is output by the knowledge query statement construction model. This model is trained based on associated samples of the query statement and is used to analyze entities, attributes, and relationships between entities in the initial query statement. A target knowledge graph query template is determined based on the user intent type and the knowledge graph query template database. This database contains user intent types and their corresponding query templates, with a one-to-one correspondence. The knowledge graph query statement corresponding to the initial query statement is determined based on the knowledge query statement and the target knowledge graph query template. This knowledge graph query statement is the result of performing intent type analysis, entity, attribute, and relationship analysis on the initial query statement.
[0107] In another aspect, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements a method for determining a knowledge graph query statement provided by the methods described above. This method includes: obtaining an initial query statement; wherein the initial query statement contains the intent, entities, attributes, and relationships between entities of a question that a user needs to query; inputting the initial query statement into a user intent analysis model to obtain the user intent type output by the user intent analysis model; wherein the user intent analysis model is trained based on user intent query statement samples and is a model used to analyze the type of intent in the initial query statement; and inputting the initial query statement into a knowledge query statement construction model to obtain the output of the knowledge query statement construction model. The process involves several steps: First, a knowledge query statement is constructed. The knowledge query statement construction model is trained based on associated samples of the query statement. This model is used to analyze entities, attributes, and relationships between entities in the initial query statement. Second, a target knowledge graph query template is determined based on the user intent type and the knowledge graph query template database. The knowledge graph query template database contains user intent types and corresponding knowledge graph query templates, with a one-to-one correspondence between user intent types and knowledge graph query templates. Third, the knowledge graph query statement corresponding to the initial query statement is determined based on the knowledge query statement and the target knowledge graph query template. Finally, the knowledge graph query statement is the query statement generated after performing intent type analysis, entity, attribute, and relationship analysis on the initial query statement.
[0108] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0109] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0110] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for determining a query statement for a knowledge graph, characterized in that, include: Obtain the initial query statement; wherein, the initial query statement contains the user's intent, entities, attributes, and relationships between entities for the question to be queried; The initial query statement is input into the user intent analysis model to obtain the user intent type output by the user intent analysis model; wherein, the user intent analysis model is trained based on user intent query statement samples, and the user intent analysis model is a model used to analyze the type of intent in the initial query statement; the user intent types mainly include entity query, relationship query, attribute query, path query, list query, statistical query, sorting query, aggregation query, and casual chat; The initial query statement is input into the knowledge query statement construction model to obtain the knowledge query statement output by the knowledge query statement construction model; wherein, the knowledge query statement construction model is trained based on query statement association samples, and the knowledge query statement construction model is used to analyze the entity, the attribute and the relationship between the entity in the initial query statement; The target knowledge graph query template is determined based on the user intent type and the knowledge graph query template database; wherein, the knowledge graph query template database is a database containing the user intent type and the knowledge graph query template corresponding to the user intent type, and the user intent type and the knowledge graph query template correspond one-to-one; The knowledge graph query statement corresponding to the initial query statement is determined based on the knowledge query statement and the target knowledge graph query template; wherein, the knowledge graph query statement is a query statement after performing intent type analysis, entity, attribute, and inter-entity relationship analysis on the initial query statement; the step of determining the knowledge graph query statement corresponding to the initial query statement based on the knowledge query statement and the target knowledge graph query template includes: determining the target knowledge query statement based on the knowledge query statement and the ontology specification standard; wherein, the ontology specification standard is a pre-defined standard expression containing entities, attributes, and inter-entity relationships, and the ontology specification standard is a standard used to standardize the knowledge query statement; and determining the knowledge graph query statement corresponding to the initial query statement based on the target knowledge query statement and the target knowledge graph query template.
2. The method for determining a knowledge graph query statement according to claim 1, characterized in that, The user intent analysis model is trained in the following way: Obtain a sample of the user's intent query statement; Input the user intent query statement sample into the basic intent analysis model to obtain the basic user intent type output by the basic intent analysis model; The basic intent analysis model is optimized based on the basic user intent type and the first optimization function to obtain the user intent analysis model.
3. The method for determining knowledge graph query statements according to claim 2, characterized in that, The knowledge query statement construction model is trained in the following way: Obtain the associated sample of the query statement; Input the associated sample of the query statement into the basic statement construction model to obtain the basic query statement output by the basic statement construction model; The basic query statement and the second optimization function are used to optimize the basic statement construction model to obtain the knowledge query statement construction model; wherein the first optimization function and the second optimization function are different optimization functions.
4. The method for determining a knowledge graph query statement according to claim 1, characterized in that, The step of determining the target knowledge query statement based on the knowledge query statement and the ontology specification standard includes: An initial knowledge query statement is determined based on the knowledge query statement and the ontology specification standard; wherein, the initial knowledge query statement is the result of standardizing the knowledge query statement using the ontology specification standard; The initial knowledge query statement is supplemented according to the knowledge reasoning rule base to determine the target knowledge query statement; wherein, the knowledge reasoning rule base is a rule base used to supplement the inter-entity relationships of the initial knowledge query statement.
5. The method for determining a knowledge graph query statement according to claim 1, characterized in that, After determining the knowledge graph query statement corresponding to the initial query statement based on the knowledge query statement and the target knowledge graph query template, the method further includes: The knowledge graph query statement is input into the knowledge graph engine to obtain the query results output by the knowledge graph engine; wherein, the knowledge graph engine is a tool used to query and retrieve the knowledge graph query statement to obtain the query results corresponding to the knowledge graph query statement.
6. A device for determining a query statement in a knowledge graph, characterized in that, include: The statement acquisition module is used to acquire the initial query statement; wherein, the initial query statement contains the user's intent, entities, attributes and relationships between entities for the question to be queried; The type output module is used to input the initial query statement into the user intent analysis model and obtain the user intent type output by the user intent analysis model; wherein, the user intent analysis model is trained based on user intent query statement samples, and the user intent analysis model is a model used to analyze the type of intent in the initial query statement; the user intent types mainly include entity query, relationship query, attribute query, path query, list query, statistical query, sorting query, aggregation query, and casual chat; The statement output module is used to input the initial query statement into the knowledge query statement construction model to obtain the knowledge query statement output by the knowledge query statement construction model; wherein, the knowledge query statement construction model is trained based on query statement association samples, and the knowledge query statement construction model is used to analyze the entity, the attribute and the relationship between the entity in the initial query statement; The template determination module is used to determine a target knowledge graph query template based on the user intent type and the knowledge graph query template database; wherein, the knowledge graph query template database is a database containing the user intent type and the knowledge graph query template corresponding to the user intent type, and the user intent type and the knowledge graph query template correspond one-to-one; The statement determination module is used to determine the knowledge graph query statement corresponding to the initial query statement based on the knowledge query statement and the target knowledge graph query template; wherein, the knowledge graph query statement is a query statement obtained by performing intent type analysis, entity, attribute, and inter-entity relationship analysis on the initial query statement; the step of determining the knowledge graph query statement corresponding to the initial query statement based on the knowledge query statement and the target knowledge graph query template includes: determining the target knowledge query statement based on the knowledge query statement and the ontology specification standard; wherein, the ontology specification standard is a pre-defined standard expression containing entities, attributes, and inter-entity relationships, and the ontology specification standard is a standard used to standardize the knowledge query statement; and determining the knowledge graph query statement corresponding to the initial query statement based on the target knowledge query statement and the target knowledge graph query template.
7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that, When the processor executes the computer program, it implements the method for determining a knowledge graph query statement as described in any one of claims 1 to 5.
8. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the method for determining the knowledge graph query statement as described in any one of claims 1 to 5.
9. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the method for determining the knowledge graph query statement as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Method and system for quickly adapting to different knowledge maps
CN114881021A
Information query method and device, processor and electronic equipment
CN116578723A