CN114860894A - Method and device for querying knowledge base, computer equipment and storage medium - Google Patents

Method and device for querying knowledge base, computer equipment and storage medium Download PDF

Info

Publication number
CN114860894A
CN114860894A CN202110076011.8A CN202110076011A CN114860894A CN 114860894 A CN114860894 A CN 114860894A CN 202110076011 A CN202110076011 A CN 202110076011A CN 114860894 A CN114860894 A CN 114860894A
Authority
CN
China
Prior art keywords
entity
graph query
sentence
query statement
original
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110076011.8A
Other languages
Chinese (zh)
Inventor
郭又铭
顾松庠
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Jingdong Technology Holding Co Ltd
Original Assignee
Jingdong Technology Holding Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Jingdong Technology Holding Co Ltd filed Critical Jingdong Technology Holding Co Ltd
Priority to CN202110076011.8A priority Critical patent/CN114860894A/en
Priority to PCT/CN2021/139332 priority patent/WO2022156450A1/en
Publication of CN114860894A publication Critical patent/CN114860894A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/30Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
    • G06F16/33Querying
    • G06F16/3331Query processing
    • G06F16/334Query execution
    • G06F16/3344Query execution using natural language analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/30Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
    • G06F16/33Querying
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/30Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
    • G06F16/33Querying
    • G06F16/332Query formulation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/30Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
    • G06F16/33Querying
    • G06F16/332Query formulation
    • G06F16/3329Natural language query formulation or dialogue systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/205Parsing
    • G06F40/211Syntactic parsing, e.g. based on context-free grammar [CFG] or unification grammars
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/279Recognition of textual entities
    • G06F40/289Phrasal analysis, e.g. finite state techniques or chunking
    • G06F40/295Named entity recognition

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • General Engineering & Computer Science (AREA)
  • Artificial Intelligence (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Health & Medical Sciences (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • General Health & Medical Sciences (AREA)
  • Mathematical Physics (AREA)
  • Human Computer Interaction (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application provides a method and a device for querying a knowledge base, computer equipment and a storage medium, wherein the method comprises the following steps: acquiring an original sentence to be inquired; analyzing the original sentence to obtain a graph query sentence template corresponding to the original sentence; generating a graph query statement according to the original statement and the graph query statement template; and querying the knowledge base by using the graph query statement to obtain a query result corresponding to the original statement. Therefore, the graph query sentence is generated according to the original sentence and the graph query sentence template, and the knowledge base is queried by utilizing the graph query sentence.

Description

Method and device for querying knowledge base, computer equipment and storage medium
Technical Field
The present application relates to the field of natural language processing technologies, and in particular, to a method and an apparatus for querying a knowledge base, a computer device, and a storage medium.
Background
The knowledge base is a structured, easy-to-operate, easy-to-utilize, comprehensive and organized knowledge cluster in knowledge engineering. In the related art, a knowledge base is usually queried based on template classification, specifically, a sentence to be queried is matched with a template, and a query result is obtained based on the matched template.
However, in the knowledge base query method based on template classification, the query result completely depends on the template, and if no template matched with the statement to be queried exists, the query cannot be performed. Moreover, algorithm engineers are required to design a large number of templates from natural languages, and the templates are expanded at any time, so that the labor cost is high, and the time consumption is long.
Disclosure of Invention
The application provides a method and a device for querying a knowledge base, computer equipment and a storage medium.
An embodiment of one aspect of the present application provides a method for querying a knowledge base, including:
acquiring an original sentence to be inquired;
analyzing the original sentence to obtain a graph query sentence template corresponding to the original sentence;
generating a graph query statement according to the original statement and the graph query statement template;
and querying a knowledge base by using the graph query statement to obtain a query result corresponding to the original statement.
Another embodiment of the present application provides an apparatus for querying a knowledge base, including:
the first acquisition module is used for acquiring an original sentence to be inquired;
the second acquisition module is used for analyzing the original sentence to acquire a graph query sentence template corresponding to the original sentence;
the generating module is used for generating the graph query statement according to the original statement and the graph query statement template;
and the query module is used for querying a knowledge base by using the graph query statement to obtain a query result corresponding to the original statement.
Another embodiment of the present application provides a computer device, including a processor and a memory;
wherein the processor executes a program corresponding to the executable program code by reading the executable program code stored in the memory, so as to implement the method for querying a knowledge base according to the embodiment of the aspect.
Another embodiment of the present application proposes a non-transitory computer-readable storage medium, on which a computer program is stored, which when executed by a processor implements a method for querying a knowledge base as described in an embodiment of the above-mentioned aspect.
Another embodiment of the present application provides a computer program product, which includes a computer program, where the computer program, when executed by a processor, implements the method for querying a knowledge base according to the foregoing one embodiment.
According to the method and device for querying the knowledge base, the computer equipment and the storage medium, the original sentence is analyzed by obtaining the primitive to be queried, so that the graph query sentence template corresponding to the original sentence is obtained, the graph query sentence is generated according to the original sentence and the graph query sentence template, and the knowledge base is queried by the graph query sentence, so that the query result corresponding to the original sentence is obtained. Therefore, the graph query sentence is generated according to the original sentence and the graph query sentence template, and the knowledge base is queried by utilizing the graph query sentence.
Additional aspects and advantages of the present application will be set forth in part in the description which follows and, in part, will be obvious from the description, or may be learned by practice of the present application.
Drawings
The foregoing and/or additional aspects and advantages of the present application will become apparent and readily appreciated from the following description of the embodiments, taken in conjunction with the accompanying drawings of which:
fig. 1 is a schematic flowchart of a method for querying a knowledge base according to an embodiment of the present disclosure;
fig. 2 is a schematic flowchart of another method for querying a knowledge base according to an embodiment of the present application;
fig. 3 is a schematic flowchart of another method for querying a knowledge base according to an embodiment of the present application;
fig. 4 is a schematic flowchart of another method for querying a knowledge base according to an embodiment of the present application;
FIG. 5 is a diagram illustrating a knowledge base query according to an embodiment of the present disclosure;
fig. 6 is a schematic structural diagram of an apparatus for querying a knowledge base according to an embodiment of the present disclosure.
Detailed Description
Reference will now be made in detail to embodiments of the present application, examples of which are illustrated in the accompanying drawings, wherein like or similar reference numerals refer to the same or similar elements or elements having the same or similar function throughout. The embodiments described below with reference to the accompanying drawings are illustrative and intended to explain the present application and should not be construed as limiting the present application.
A method, an apparatus, a computer device, and a storage medium for querying a knowledge base according to an embodiment of the present application are described below with reference to the accompanying drawings.
Fig. 1 is a schematic flowchart of a method for querying a knowledge base according to an embodiment of the present disclosure.
The method for querying the knowledge base in the embodiment of the application can be executed by the device for querying the knowledge base provided in the embodiment of the application, and the device can be configured in computer equipment to query the knowledge base by using the graph query statement.
As shown in fig. 1, the query method of the knowledge base includes:
step 101, obtaining an original sentence to be queried.
In the application, the user can input the sentence to be inquired in a text mode, and therefore the computer equipment can obtain the original sentence to be inquired. Or, the user can input the data in a voice form, and the computer device performs voice recognition after acquiring voice data to acquire the original sentence to be queried.
And 102, analyzing the original sentence to obtain a graph query sentence template corresponding to the original sentence.
After the original sentence to be queried is obtained, the original sentence can be analyzed, and a graph query sentence template corresponding to the original sentence is obtained. The knowledge base comprises entities, and the relationship between the entities, namely the entity relationship, and the like, wherein the entities are abstractions of objective individuals, such as names of people, places, names of organizations, and the like. Then, the entity relationship, and the like included in the original sentence can be obtained by analyzing the original sentence, and the graph query sentence template corresponding to the original sentence is obtained according to the obtained entity, entity relationship, and the like.
Optionally, when the original sentence is analyzed, the original sentence may be processed by using a preset neural network model, and a graph query sentence template corresponding to the original sentence is obtained according to a processing result.
The graph query statement template comprises a specified language required by the graph query statement to query the knowledge base. For example, the graph query statement template may be a gremlin query statement template. The gremlin language is a query language for graph databases, and can be used to traverse property graphs.
For example, where the hometown of the original sentence is "a" (the letter a is a specific name, alternative name, etc., such as zhang san), the original sentence is processed by using a preset neural network model, the sentence type of the original sentence is determined to be the query sentence, the entity type of the entity "a" in the original sentence, which is matched with the entity type in the knowledge base, is determined to be "name" and a corresponding attribute condition (has), and the entity relationship "hometown" in the original sentence, which is matched with the edge type in the knowledge base, is determined to be "hometown" and a corresponding edge attribute (out). Then, according to the entity type "name" and the corresponding attribute condition (has), the edge type "home" and the corresponding edge attribute (out), and in combination with the statement type as a query statement, a gremlin query statement template "gt _ nlp _ asm _ kg.v (). has ('name',). out ('home'). order ().by ('stock _ flag', decr). dedup ()" is generated.
And 103, generating a graph query statement according to the original statement and the graph query statement template.
In the application, because the graph query statement template does not contain entities and the like required for knowledge base query, the graph query statement template can be filled according to the original statements to generate the graph query statements.
And 104, querying the knowledge base by using the graph query statement to obtain a query result corresponding to the original statement.
After the graph query statement is obtained, the knowledge base can be queried by using the graph query statement to obtain a query result corresponding to the original statement. For example, the entity may be found in the knowledge base according to the entity included in the graph query statement, and the query result may be found from the entity pointed to by the entity.
According to the method for querying the knowledge base, the primitive to be queried is obtained, the original sentence is analyzed, so that a graph query sentence template corresponding to the original sentence is obtained, a graph query sentence is generated according to the original sentence and the graph query sentence template, and the knowledge base is queried through the graph query sentence, so that a query result corresponding to the original sentence is obtained. Therefore, the graph query sentence is generated according to the original sentence and the graph query sentence template, and the knowledge base is queried by utilizing the graph query sentence.
In one embodiment of the present application, the graph query statement template may be obtained in the manner shown in fig. 2. Fig. 2 is a schematic flowchart of another method for querying a knowledge base according to an embodiment of the present disclosure.
As shown in fig. 2, the parsing the original sentence to obtain the graph query sentence template includes:
step 201, performing type analysis on the original sentence to obtain the sentence type of the original sentence.
In practical application, when a user performs a knowledge base query, an input statement may be a query statement or a judgment statement. For example, the original sentence input by the user is query sentence "where the hometown of A is". For another example, the original sentence input by the user is to determine that the hometown of the sentence "a is m city".
Because different sentence types are different from corresponding to different graph query sentence templates, after the original sentence to be queried is obtained, the type of the original sentence can be analyzed to obtain the sentence type of the original sentence. The statement type may include a query statement, a judgment statement, and the like.
As an implementation manner, word segmentation processing may be performed on an original sentence, each word segmentation included in the original sentence is obtained, and whether a word segmentation matched with a preset word segmentation of each sentence type exists in the word segmentation included in the original sentence is determined. If there is a participle matching with a certain sentence type in the participles included in the original sentence, the sentence type of the original sentence can be considered as the sentence type.
For example, the original sentence is "school where B is graduation," and the preset segmentation of the query sentence may include "what," "where," and so on. After analysis, the original sentence includes the preset word segmentation of the query sentence, and the sentence type of the original sentence can be considered as the query sentence.
As another possible implementation manner, the original sentence may be input into a sentence type recognition model obtained by pre-training, and the sentence type of the original sentence is determined by using the sentence type recognition model. Therefore, the sentence type of the original sentence is determined through the model, and the accuracy of sentence type identification can be improved.
Step 202, performing entity detection on the original sentence to determine whether the original sentence contains an entity matching the specified entity type.
In the application, entity detection can be performed on the original sentence, entities included in the original sentence are obtained, and the matching degree between each entity included in the original sentence and the specified entity type is calculated, so that whether the original sentence includes the entity matched with the specified entity type is determined. The specified entity type refers to the entity type in the knowledge base to be queried. For example, the types of entities included in a knowledge base include "person", "school", "organization", and the like.
If the matching degree between any entity contained in the original sentence and the specified entity type exceeds a preset threshold, determining that the original sentence contains an entity matched with the specified entity type. If the matching degree between the entity contained in the original sentence and each specified entity type is less than or equal to the preset threshold, it can be determined that the entity matched with the specified entity type is not included in the original sentence.
Step 203, under the condition that the original sentence includes an entity matched with any specified entity type, acquiring a graph query sentence template corresponding to the sentence type and any specified entity type.
As a possible implementation manner, when an entity matching any specified entity type is included in the original sentence, it is described that the original sentence includes the entity, and then an operation performed on the entity in the graph query sentence can be determined, and based on the operation and the sentence type of the original sentence, a corresponding graph query sentence template can be generated.
Taking the generation of the gremlin graph query template as an example, if the original sentence contains an entity, it can be determined that the operation performed on the entity is "has" or that the attribute condition used by the original sentence is "has", and a corresponding graph query sentence template can be generated based on the "has" and the sentence type of the original sentence.
In practical application, the attributes of edges between entity types in the knowledge base are different, and the corresponding graph query statements are also different. The edge attributes may include an out edge (out), an in edge (in), an in & out, and the like. As another possible implementation, a graph query statement template library is preset, and each entity type may have a corresponding graph query statement template. For example, the knowledge base has a → B, and the entity type of a corresponds to a graph query statement template containing an entity, a graph query statement template containing an entity and an edge type, a graph query statement template containing two entities and an edge type, and the like.
When the original sentence includes an entity matching any specified entity type, a graph query sentence template corresponding to any specified entity type may be obtained first, and the graph query sentence template corresponding to the sentence type may be screened out.
As another possible implementation manner, a graph query statement template library is preset, where the graph query statement template library may include a large number of graph query statement templates, and the number of entities included in each graph query statement template is different, or the number of types of edges included in each graph query statement template is different, or the edge attributes are different. The edge attributes may include an out edge (out), an in edge (in), an in & out, and the like.
When the graph query statement template is obtained, the entity number of the original statement and the graph query statement template corresponding to the entity relation number can be obtained, the edge attribute of the entity relation is determined according to the entity relation in the original statement, the graph query statement template matched with the edge attribute is screened out, and the graph query statement template corresponding to the statement type is further screened out according to the statement type of the original statement.
In the method for querying a knowledge base according to the embodiment of the application, when the graph query statement template is obtained, the statement type of the original statement is obtained by performing type analysis on the original statement, and the original statement is subjected to entity detection to determine whether the original statement includes an entity matching with a specified entity type, and under the condition that the original statement includes an entity matching with any specified entity type, the graph query statement template corresponding to the statement type and any specified entity type is obtained, and the graph query statement is generated according to the obtained graph query statement template and the original statement. Therefore, the knowledge base is queried by using the acquired graph query sentences, compared with a template-based knowledge base query method, the query sentences are more abundant and diversified, the condition that the query cannot be performed due to the absence of a template matched with the original sentences is avoided, the flexibility of knowledge base query is greatly improved, the accuracy is further improved, and the labor cost and the time are saved.
In practical applications, the original sentence to be queried may further include relationships between entities, i.e., entity relationships. Based on this, in one embodiment of the present application, the graph query statement template can be obtained in the manner shown in fig. 3. Fig. 3 is a schematic flowchart of another method for querying a knowledge base according to an embodiment of the present application. As shown in fig. 3, the parsing the original sentence to obtain the graph query sentence template includes:
step 301, performing type analysis on the original sentence to obtain the sentence type of the original sentence.
Step 302, performing entity detection on the original sentence to determine whether the original sentence contains an entity matching the specified entity type.
In the present application, steps 301 to 302 are similar to steps 201 to 202 described above, and therefore are not described herein again.
Step 303, under the condition that the original sentence includes an entity matching any specified entity type, performing entity relationship detection on the original sentence to determine whether the original sentence includes an entity relationship matching the specified edge type.
In the case that the original sentence includes an entity matching any specified entity type, entity relationship detection may be performed on the original sentence, for example, an entity relationship between two entities may be obtained according to a word segmentation between the two entities in the original sentence, or an entity relationship included in the original sentence may be determined according to a word segmentation after the entity in the original sentence. For example, where the original sentence is "a" hometown ", the entity contained in the original sentence is" a ", and the relationship of the entity contained in the original sentence is" hometown "can be determined according to the participle" located after "a" and "hometown".
After the entity relationship contained in the original sentence is obtained, the matching degree between the entity relationship contained in the original sentence and the specified edge type is calculated. The specified edge type is an edge type contained in a knowledge base to be queried. For example, the edge types included in a knowledge base include "hometown", "graduation", "employment", "publishing".
And if the matching degree between the entity relationship contained in the original sentence and the specified edge type is greater than the threshold value, determining that the entity relationship contained in the original sentence is matched with the specified edge type. If the matching degree between the entity relationship contained in the original sentence and each specified edge type is smaller than the preset threshold value, the fact that the entity relationship matched with the specified edge type is not contained in the original sentence can be determined.
Step 304, under the condition that the original sentence contains an entity relation matched with any specified edge type, acquiring a graph query sentence template corresponding to the sentence type, any specified entity type and any specified edge type.
When the original sentence includes an entity matching any specified entity type, and when the original sentence includes an entity relationship matching any specified edge type, it is described that the original sentence includes an entity matching the specified entity type, and also includes an entity relationship matching the specified edge type.
In the method, the edge attribute of the entity relationship matched with any specified edge type in the original sentence can be obtained by analyzing the original sentence, the query operation on the entity type and the query operation on the opposite side type in the graph query sentence template can be determined according to any specified entity type, any specified edge type matching and the edge attribute, and then the graph query sentence template is generated by combining the sentence type of the original sentence.
For example, the original sentence is "where the hometown of a is", the entity "a" contained in the original sentence is matched with the specified entity type "name", and the entity relationship "hometown" contained in the original sentence is matched with the specified edge type "hometown". Since the original statement contains an entity matching the specified entity type, the graph query statement template contains an operation on the entity as "has", an edge attribute contained in the original statement is an edge (out), the graph query statement template contains an operation on the "hometown" of the edge type, and the graph query statement template can generate a gremlin query statement template "gt _ nlp _ asm _ kg.v (). has ('name',) out ('hometown'). order ().by ('stock _ flag', dec). dedup ()" in combination with the original statement as a query statement.
Optionally, the neural network model may also be used to obtain the graph query statement template. Specifically, the original sentence may be input into a pre-trained neural network model to obtain an operation on the entity type, an edge type and a corresponding edge attribute, and a graph query sentence template is generated in combination with the sentence type of the original sentence. It will be appreciated that the edge attributes correspond to operations on edge types in the graph query statement template.
In the method for querying a knowledge base according to the embodiment of the application, when the graph query statement template corresponding to the statement type and any one of the designated entity types is obtained, entity relationship detection may be performed on the original statement to determine whether the original statement includes an entity relationship matching the designated edge type, and under the condition that the original statement includes an entity relationship matching any one of the designated edge types, the graph query statement template corresponding to the statement type, any one of the designated entity types, and any one of the designated edge types is obtained. Therefore, when the original sentence contains the entity relationship, the graph query sentence template corresponding to the original sentence can be obtained, so that the query sentence is richer and more diversified, and the flexibility and the accuracy of the knowledge base query are improved.
In an embodiment of the present application, the graph query statement template includes an entity to be filled, and a graph query statement may be generated in a 4 manner, and the knowledge base is queried by using the graph query statement. Fig. 4 is a schematic flowchart of another method for querying a knowledge base according to an embodiment of the present application.
As shown in fig. 4, the query method of the knowledge base includes:
step 401, obtaining an original sentence to be queried.
Step 402, analyzing the original sentence to obtain a graph query sentence template corresponding to the original sentence.
In the present application, steps 401 to 402 can refer to the above embodiments, and thus are not described herein again.
Step 403, performing entity extraction on the original sentence to obtain an entity set corresponding to the original sentence.
After the graph query sentence template is obtained, the entity extraction can be performed on the original sentence through a method based on rules and dictionaries or a machine learning method, and the like, so as to obtain the entity contained in the original sentence, and obtain the entity set corresponding to the original sentence according to the entity contained in the original sentence. It is understood that the entity set includes the entities included in the original sentence.
Step 404, entity filling is performed on the graph query statement template by using the entities in the entity set to generate a graph query statement.
Because the graph query statement template contains the entities to be filled, when the graph query statement is generated, the entities in the entity set corresponding to the original statement can be used for filling the entities in the graph query statement template, so that the graph query statement is generated.
In the method and the device, an entity matched with the type of the entity to be filled in the graph query statement template can be determined from the entity set, and the entity matched with the type of the entity to be filled in the graph query statement template is filled in the graph query statement template, so that the graph query statement is generated. Therefore, the entities matched with the types of the entities to be filled are used for filling, the accuracy of the graph query statement is improved, and the accuracy of follow-up knowledge base query is improved.
For example, the type of the entity to be filled in the graph query statement template corresponding to the "where the hometown of the original statement" a is "name", and the entity "a" in the entity set matching the type "name" of the entity to be filled may be filled in the graph query statement template to generate the graph query statement "gt _ nlp _ asm _ kg.v ().has ('name', 'a'). out ('hometown'). order (). by ('stock _ flag', decr). dedup ()".
If there are multiple entities to be filled, the entity set and the entity with the type matching with each entity to be filled in the graph query statement template can be obtained, and the matched entity is filled to the entity position to be filled in the graph query statement template.
In practical applications, the entities extracted from the original sentence may not be consistent with the representation of the entities in the knowledge base. Further, in order to improve the accuracy of the query, before the graph query statement template is filled with entities in the entity set and the graph query statement is generated, each entity in the entity set and an entity in the knowledge base are linked to determine each entity in the knowledge base corresponding to each entity in the entity set, which is called as each target entity for convenience of distinguishing. Thus, the standard representation of the entity extracted from the original sentence in the knowledge base is determined. And when the entities in the entity set are used for carrying out entity filling on the graph query statement template, the entities can be obtained from each target entity to carry out entity filling on the graph query statement template so as to generate the graph query statement. Therefore, the knowledge base is queried by using the graph query statement containing the entity standard representation in the knowledge base, and the query accuracy can be greatly improved.
Step 405, querying the knowledge base by using the graph query statement to obtain a query result corresponding to the original statement.
In the present application, step 405 can refer to the above embodiments, and is not described herein again.
According to the query method of the knowledge base, the graph query statement template comprises the entities to be filled, when the graph query statement is generated according to the original statement and the graph query statement template, the entities corresponding to the original statement are obtained by extracting the entities from the original statement, and the entities in the entity set are used for filling the entities in the graph query statement template to generate the graph query statement. Therefore, the graph query statement template is filled according to the entities in the original statement to generate the graph query statement, so that the graph query statement does not depend on the template of the statement to be queried, and the flexibility of knowledge base query is improved.
In one embodiment of the present application, when entity filling is performed on the graph query statement template by using entities in the entity set to generate the graph query statement, the graph query statement may also be generated by the following method.
In the application, each entity in the entity set can be used to fill the entity to be filled in the graph query statement template, so as to generate a plurality of candidate graph query statements. After obtaining a plurality of candidate graph query sentences, the matching degree of each candidate graph query sentence and the original sentence can be calculated, and the graph query sentences are selected from the candidate graph query sentences according to the matching degree of each candidate graph query sentence and the original sentence.
When the graph query statement is selected, the candidate graph query statement with the highest matching degree may be used as the graph query statement corresponding to the original statement, or a plurality of candidate graph query statements with the highest matching degree may also be selected as the graph query statement corresponding to the original statement, and the like.
For example, the entity set corresponding to the original sentence includes 3 entities, the number of the entities to be filled in the graph query sentence template is 2, the entities to be filled in the graph query sentence template can be filled by using the 3 entities in the entity set respectively to obtain 6 candidate graph query sentences, and the candidate graph query sentence with the highest matching degree can be selected from the 6 candidate graph query sentences as the graph query sentence of the original sentence according to the matching degree of the candidate graph query sentences and the original sentence.
Optionally, when the entity set includes a plurality of entities, the entities in the entity set may also be arranged according to the number of the entities to be filled in the graph query statement template, the matching degree between each arrangement result and the original statement is calculated, a target arrangement result with the highest matching degree is selected from the plurality of arrangement results, and each entity in the target arrangement result is sequentially filled to the position of the entity to be filled in the graph query statement template, so as to obtain the graph query statement.
For example, if the entity set corresponding to the original sentence includes 3 entities and the number of entities to be filled in the graph query sentence template is 2, two entities can be extracted from the entity set and arranged to obtain the entity set
Figure BDA0002907643040000131
And calculating the matching degree of each arrangement result and the original sentence, selecting the arrangement result with the highest matching degree, correspondingly filling each entity in the arrangement result with the highest matching degree to the position of the entity needing to be filled in the graph query sentence template to obtain the graph query sentence, namely filling the 1 st entity in the arrangement result with the highest matching degree to the position of the 1 st entity needing to be filled in the graph query sentence template, and filling the 2 nd entity in the arrangement result to the position of the 2 nd entity needing to be filled in the graph query sentence template.
In the method for querying a knowledge base, when entities in an entity set are used for entity filling of a graph query statement template to generate a graph query statement, the graph query statement template can be filled according to the entities in the entity set to obtain a plurality of candidate graph query statements, and a graph query statement of an original statement is selected from the candidate graph query statements according to the matching degree of each candidate graph query statement and the original statement, so that the generated graph query statement and the original statement have high matching degree, and the query accuracy of the knowledge base is improved.
The following describes a method for querying a knowledge base according to an embodiment of the present application, with reference to fig. 5, by taking an example of converting an original sentence into a gremlin query sentence using a neural network model. Fig. 5 is a schematic diagram of a knowledge base query according to an embodiment of the present application.
As shown in fig. 5, after the original sentence is encoded, three classification tasks need to be completed, wherein the first one is classification of sentence type to determine whether the original sentence is a query or a judgment; the second classification task is the classification of attribute conditions, and comprises 4 classifications of has, in, out and in & out (or a classification of 'null' can be added), wherein has represents the attribute of the entity, in, out and in & out are edge attributes, and the classification task determines which attribute conditions are used in the original sentence; and the third classification task, the classification quantity of which is the same as the quantity of the entity types and the edge types contained in the knowledge base, determines the entity types in the knowledge base corresponding to the entities contained in the original sentence, the edge types in the knowledge base corresponding to the entity relationship and the like through the classification task.
In fig. 5, Roberta is used to encode the original sentence "where the hometown of a is" to obtain a coding vector, and the coding vector is processed to obtain a sentence type of the original sentence as an inquiry sentence, the attribute conditions used in the original sentence are "has" and "out", and an entity type "name" of 6 specified entity types and edge types, which is matched with the entity in the original sentence, and an edge type "hometown", which is matched with the entity relationship in the original sentence. After the three classification results are obtained, fusion can be performed according to the obtained three classification results, and a gremlin query statement is modeled as "gt _ nlp _ asm _ kg.v ().has ('name',). out ('hometown'). order (). by ('stock _ flag', decr). dedup ()".
In fig. 5, "COND _ JUD _ OP" processes the corresponding vector, and obtains a statement type of an original statement as a query statement; the "ASK _ chemically _ OP" is to fuse the result of the second classification task and the result of the third classification task, specifically, to determine the entity and its corresponding attribute condition, edge type and corresponding edge attribute. And then, inquiring the statement according to the entity, the corresponding attribute condition, the edge type, the corresponding edge attribute and the statement type of the original statement to obtain a gremlin inquiry statement template.
After a gremlin query statement template is obtained, the gremlin query statement template and an original statement are decoded, entities of the original statement are extracted, the entities are arranged, an arrangement result with the highest matching degree with the original statement is determined, the gremlin query statement template and the arrangement result with the highest matching degree with the original statement are combined by using GEN _ OP, namely the entities in the arrangement result are filled into corresponding positions in the template, and a gremlin query statement gt _ nlp _ asm _ kg.v ().has ('name', 'A'). out ('hometown'). order () and by ('stock _ flag', decr) 'dedup ()' is generated. After the gremlin query statement is obtained, the knowledge base is queried, and the node corresponding to the exit of the node edge type 'hometown' with the name of A in the knowledge base is obtained as'm city', namely the query result'm city' of the original statement 'where the hometown of A is' is obtained.
In order to implement the above embodiments, an apparatus for querying a knowledge base is further provided in the embodiments of the present application. Fig. 6 is a schematic structural diagram of an apparatus for querying a knowledge base according to an embodiment of the present disclosure.
As shown in fig. 6, the query device 600 of the knowledge base includes: a first obtaining module 610, a second obtaining module 620, a generating module 630 and a querying module 640.
A first obtaining module 610, configured to obtain an original sentence to be queried;
a second obtaining module 620, configured to perform parsing on the original sentence to obtain a graph query sentence template corresponding to the original sentence;
a generating module 630, configured to generate a graph query statement according to the original statement and the graph query statement template;
and the query module 640 is configured to query the knowledge base by using the graph query statement to obtain a query result corresponding to the original statement.
Optionally, the second obtaining module 620 includes:
the analysis unit is used for carrying out type analysis on the original sentence to obtain the sentence type of the original sentence;
the determining unit is used for carrying out entity detection on the original sentence so as to determine whether the original sentence contains an entity matched with the specified entity type;
and the acquisition unit is used for acquiring the graph query statement template corresponding to the statement type and any specified entity type under the condition that the original statement contains an entity matched with any specified entity type.
Optionally, the obtaining unit is configured to:
detecting entity relationship of the original sentence to determine whether the original sentence contains the entity relationship matched with the specified edge type;
and under the condition that the original sentence contains an entity relation matched with any specified edge type, acquiring a graph query sentence template corresponding to the sentence type, any specified entity type and any specified edge type.
Optionally, the graph query statement template includes an entity to be filled, and the generating module 630 includes:
the entity extraction unit is used for performing entity extraction on the original sentence to obtain an entity set corresponding to the original sentence;
and the generating unit is used for filling the entities in the graph query statement template by using the entities in the entity set so as to generate the graph query statement.
Optionally, the generating unit is configured to:
and filling the entities in the entity set, which are matched with the types of the entities to be filled in the graph query statement template, into the graph query statement template so as to generate the graph query statement.
Optionally, the generating unit is configured to:
filling the graph query statement template by respectively utilizing each entity in the entity set to obtain a plurality of candidate graph query statements;
determining the matching degree of each candidate graph query statement and the original statement;
and selecting a graph query statement from the plurality of candidate graph query statements according to the matching degree.
Optionally, the apparatus may further comprise:
the determining module is used for determining each target entity corresponding to each entity in the entity set in the knowledge base;
and the generating unit is also used for carrying out entity filling on the graph query statement template according to each target entity so as to generate the graph query statement.
It should be noted that the above explanation of the embodiment of the method for querying a knowledge base is also applicable to the apparatus for querying a knowledge base in this embodiment, and therefore is not repeated herein.
The query device of the knowledge base in the embodiment of the application analyzes the original sentence by obtaining the primitive to be queried to obtain the graph query sentence template corresponding to the original sentence, generates the graph query sentence according to the original sentence and the graph query sentence template, and queries the knowledge base by using the graph query sentence to obtain the query result corresponding to the original sentence. Therefore, the graph query sentence is generated according to the original sentence and the graph query sentence template, and the knowledge base is queried by utilizing the graph query sentence.
In order to implement the foregoing embodiments, an embodiment of the present application further provides a computer device, including a processor and a memory;
wherein, the processor executes the program corresponding to the executable program code by reading the executable program code stored in the memory, so as to realize the inquiring method of the knowledge base according to the embodiment.
In order to implement the foregoing embodiments, the present application further proposes a non-transitory computer-readable storage medium, on which a computer program is stored, and the computer program, when executed by a processor, implements the method for querying the knowledge base according to the foregoing embodiments.
In order to implement the foregoing embodiments, an embodiment of the present application further provides a computer program product, which includes a computer program, where the computer program is executed by a processor to implement the method for querying a knowledge base according to the foregoing embodiment of an aspect.
In the description of the present specification, the terms "first", "second" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implying any number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one such feature. In the description of the present application, "plurality" means at least two, e.g., two, three, etc., unless explicitly specified otherwise.
Although embodiments of the present application have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present application, and that variations, modifications, substitutions and alterations may be made to the above embodiments by those of ordinary skill in the art within the scope of the present application.

Claims (17)

1. A method for querying a knowledge base is characterized by comprising the following steps:
acquiring an original sentence to be inquired;
analyzing the original sentence to obtain a graph query sentence template corresponding to the original sentence;
generating a graph query statement according to the original statement and the graph query statement template;
and querying a knowledge base by using the graph query statement to obtain a query result corresponding to the original statement.
2. The method of claim 1, wherein the parsing the original sentence to obtain a graph query sentence template comprises:
performing type analysis on the original sentence to obtain the sentence type of the original sentence;
performing entity detection on the original sentence to determine whether the original sentence contains an entity matched with the specified entity type;
and under the condition that the original statement comprises an entity matched with any specified entity type, acquiring a graph query statement template corresponding to the statement type and any specified entity type.
3. The method of claim 2, wherein said obtaining a graph query statement template corresponding to said statement type and said any specified entity type comprises:
detecting entity relationship of the original sentence to determine whether the original sentence contains entity relationship matched with the specified edge type;
and under the condition that the original sentence contains an entity relation matched with any specified edge type, acquiring the graph query sentence template corresponding to the sentence type, any specified entity type and any specified edge type.
4. The method of claim 1, wherein the graph query statement template contains entities to be filled, and wherein generating the graph query statement according to the original statement and the graph query statement template comprises:
performing entity extraction on the original sentence to obtain an entity set corresponding to the original sentence;
and utilizing the entities in the entity set to perform entity filling on the graph query statement template so as to generate the graph query statement.
5. The method of claim 4, wherein the entity populating the graph query statement template with entities in the set of entities to generate the graph query statement, comprises:
and filling the entities in the entity set, which are matched with the types of the entities to be filled in the graph query statement template, into the graph query statement template so as to generate the graph query statement.
6. The method of claim 4, wherein said entity populating the graph query statement template with entities in the entity set to generate the graph query statement comprises:
filling the graph query statement template by respectively utilizing each entity in the entity set to obtain a plurality of candidate graph query statements;
determining the matching degree of each candidate graph query statement and the original statement;
and selecting the graph query statement from the plurality of candidate graph query statements according to the matching degree.
7. The method of claim 4, wherein before the utilizing entities in the set of entities to entity-populate the graph query statement template to generate the graph query statement, further comprising;
determining each target entity in the knowledge base corresponding to each entity in the entity set;
the utilizing the entities in the entity set to perform entity filling on the graph query statement template to generate the graph query statement includes:
and filling the graph query statement template according to each target entity to generate the graph query statement.
8. An apparatus for querying a knowledge base, comprising:
the first acquisition module is used for acquiring an original sentence to be inquired;
the second acquisition module is used for analyzing the original sentence to acquire a graph query sentence template corresponding to the original sentence;
the generating module is used for generating the graph query statement according to the original statement and the graph query statement template;
and the query module is used for querying a knowledge base by using the graph query statement to obtain a query result corresponding to the original statement.
9. The apparatus of claim 8, wherein the second obtaining module comprises:
the analysis unit is used for carrying out type analysis on the original sentence to obtain the sentence type of the original sentence;
a determining unit, configured to perform entity detection on the original sentence to determine whether the original sentence includes an entity matching a specified entity type;
and the obtaining unit is used for obtaining a graph query statement template corresponding to the statement type and any specified entity type under the condition that the original statement comprises an entity matched with any specified entity type.
10. The apparatus of claim 9, wherein the obtaining unit is to:
detecting entity relationship of the original sentence to determine whether the original sentence contains entity relationship matched with the specified edge type;
and under the condition that the original sentence contains an entity relation matched with any specified edge type, acquiring the graph query sentence template corresponding to the sentence type, any specified entity type and any specified edge type.
11. The apparatus of claim 8, wherein the graph query statement template includes entities to be populated, the generation module comprising:
an entity extraction unit, configured to perform entity extraction on the original sentence to obtain an entity set corresponding to the original sentence;
and the generating unit is used for filling the entities in the graph query statement template by using the entities in the entity set so as to generate the graph query statement.
12. The apparatus of claim 11, wherein the generating unit is to:
and filling the entities in the entity set, which are matched with the types of the entities to be filled in the graph query statement template, into the graph query statement template so as to generate the graph query statement.
13. The apparatus of claim 11, wherein the generating unit is to:
filling the graph query statement template by respectively utilizing each entity in the entity set to obtain a plurality of candidate graph query statements;
determining the matching degree of each candidate graph query statement and the original statement;
and selecting the graph query statement from the plurality of candidate graph query statements according to the matching degree.
14. The apparatus of claim 11, wherein the apparatus further comprises:
a determining module, configured to determine each target entity in the knowledge base corresponding to each entity in the entity set;
the generating unit is further configured to perform entity filling on the graph query statement template according to the target entities to generate the graph query statement.
15. A computer device comprising a processor and a memory;
wherein the processor executes a program corresponding to the executable program code by reading the executable program code stored in the memory, for implementing the method of querying the knowledge base according to any one of claims 1 to 7.
16. A non-transitory computer-readable storage medium on which a computer program is stored, the program, when executed by a processor, implementing a method of querying a knowledge base according to any one of claims 1 to 7.
17. A computer program product, comprising a computer program, wherein the computer program, when executed by a processor, implements the method of querying a knowledge base according to any one of claims 1-7.
CN202110076011.8A 2021-01-20 2021-01-20 Method and device for querying knowledge base, computer equipment and storage medium Pending CN114860894A (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202110076011.8A CN114860894A (en) 2021-01-20 2021-01-20 Method and device for querying knowledge base, computer equipment and storage medium
PCT/CN2021/139332 WO2022156450A1 (en) 2021-01-20 2021-12-17 Knowledge base query method and apparatus, computer device, and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110076011.8A CN114860894A (en) 2021-01-20 2021-01-20 Method and device for querying knowledge base, computer equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114860894A true CN114860894A (en) 2022-08-05

Family

ID=82548445

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110076011.8A Pending CN114860894A (en) 2021-01-20 2021-01-20 Method and device for querying knowledge base, computer equipment and storage medium

Country Status (2)

Country Link
CN (1) CN114860894A (en)
WO (1) WO2022156450A1 (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117235211B (en) * 2023-11-15 2024-03-19 暗物智能科技(广州)有限公司 Knowledge question-answering method and system

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104866593B (en) * 2015-05-29 2018-05-22 中国电子科技集团公司第二十八研究所 A kind of database search method of knowledge based collection of illustrative plates
CN105868313B (en) * 2016-03-25 2019-02-12 浙江大学 A kind of knowledge mapping question answering system and method based on template matching technique
CN112753029A (en) * 2018-09-20 2021-05-04 华为技术有限公司 System and method for graph-based query analysis
CN110765256B (en) * 2019-12-24 2020-07-07 杭州实在智能科技有限公司 Method and equipment for generating online legal consultation automatic reply
CN111522934A (en) * 2020-04-23 2020-08-11 华东理工大学 Knowledge question-answering system and method based on chemical knowledge base
CN111782763A (en) * 2020-05-22 2020-10-16 平安科技(深圳)有限公司 Information retrieval method based on voice semantics and related equipment thereof

Also Published As

Publication number Publication date
WO2022156450A1 (en) 2022-07-28

Similar Documents

Publication Publication Date Title
CN110765265B (en) Information classification extraction method and device, computer equipment and storage medium
CN110765235B (en) Training data generation method, device, terminal and readable medium
CN107807968B (en) Question answering device and method based on Bayesian network and storage medium
CN110210038B (en) Core entity determining method, system, server and computer readable medium thereof
CN116719520B (en) Code generation method and device
KR102410715B1 (en) Apparatus and method for analyzing sentiment of text data based on machine learning
CN117390169B (en) Form data question-answering method, device, equipment and storage medium
CN112347271A (en) Auxiliary defect entry method for power distribution Internet of things equipment based on character semantic recognition
CN113255343A (en) Semantic identification method and device for label data, computer equipment and storage medium
CN111400340A (en) Natural language processing method and device, computer equipment and storage medium
CN109960730A (en) A kind of short text classification method, device and equipment based on feature extension
CN114492429A (en) Text theme generation method, device and equipment and storage medium
CN117951249A (en) Knowledge base response method and system based on large language model
CN110795942B (en) Keyword determination method and device based on semantic recognition and storage medium
CN111814476A (en) Method and device for extracting entity relationship
Takamura et al. Discriminative analysis of linguistic features for typological study
CN114860894A (en) Method and device for querying knowledge base, computer equipment and storage medium
CN111523301B (en) Contract document compliance checking method and device
CN116881471B (en) Knowledge graph-based large language model fine tuning method and device
CN114912458A (en) Emotion analysis method and device and computer readable medium
CN112989829A (en) Named entity identification method, device, equipment and storage medium
CN108304366B (en) Hypernym detection method and device
CN113065360B (en) Word semantic model construction method and device, computer equipment and storage medium
CN115203206A (en) Data content searching method and device, computer equipment and readable storage medium
CN114254622A (en) Intention identification method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination