Knowledge graph construction method and device
Patent Information
- Application Number
- CN202310147705.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-20
- Publication Date
- 2026-08-21
- Estimated Expiration
- 2043-02-20
AI Technical Summary
[0003]但在海量数据下,对数据源进行全量抽取进行知识图谱的构建或更新,可能导致大量的几乎不会被搜索的相关知识占用了大量的空间资源,且进行全量抽取需要的时间较长
[0010]In this embodiment, the ontology, extraction rules, and mapping rules corresponding to the target knowledge graph are obtained. The ontology includes the definitions of multiple entities and related information of multiple entities. The extraction rules are rules for extracting data from the source data corresponding to the entity, and the mapping rules are rules for mapping fields in the source data corresponding to the entity to the ontology. A query request is received, which includes a first entity. Based on the query request, it is determined whether the first entity has been constructed in the graph database corresponding to the target knowledge graph. The query request is used to query the first related knowledge of the first entity in the graph database. If the first entity has not been constructed, the source data corresponding to the first entity is extracted according to the ontology, extraction rules, and mapping rules to determine the first related knowledge. The first related knowledge is imported into the graph database to construct the target knowledge graph. As can be seen, compared to directly extracting a large amount of knowledge from massive datasets to construct a knowledge graph, which results in knowledge that is rarely searched occupying a large amount of space resources and is not easy to construct multiple knowledge graphs, this technical solution can extract the source data corresponding to the first entity based on the user's query request. The amount of data extracted is smaller, saving the time of knowledge extraction. Correspondingly, when storing this knowledge, it occupies relatively less space. Moreover, since the ontology, extraction rules, and mapping rules are obtained, the knowledge required for each query request can be extracted using the ontology, extraction rules, and mapping rules, thereby realizing multiple constructions of the knowledge graph (dynamic construction), reducing the time and storage space occupied in constructing a knowledge graph under massive datasets.
Smart Images

Figure CN116127098B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of knowledge graph technology, specifically relating to a method and apparatus for constructing a knowledge graph. Background Technology
[0002] In recent years, knowledge graphs have been widely used in industry and academia. Knowledge graphs use graph data structures to express and store knowledge, and use entities, relationships, and attributes to describe the real world. There are generally two ways to build them: top-down and bottom-up. Regardless of whether it is a top-down or bottom-up approach, the process involves extracting all data from the data source, transforming it, and loading it into the knowledge graph.
[0003] However, with massive amounts of data, extracting all data from the data source to build or update the knowledge graph may result in a large amount of related knowledge that is almost never searched occupying a lot of space resources, and the extraction process takes a long time. Summary of the Invention
[0004] This application provides a method and apparatus for constructing a knowledge graph, which can reduce the time and storage space required for constructing a knowledge graph with massive amounts of data.
[0005] In a first aspect, embodiments of this application provide a method for constructing a knowledge graph. The method includes: obtaining an ontology, extraction rules, and mapping rules corresponding to a target knowledge graph; wherein the ontology includes definitions of multiple entities and related information of the multiple entities; the extraction rules are rules for extracting data from source data corresponding to the entities; and the mapping rules are rules for mapping fields in the source data corresponding to the entities to the ontology; receiving a query request, the query request including a first entity; determining, based on the query request, whether the first entity has been constructed in a graph database corresponding to the target knowledge graph; the query request being used to query first related knowledge of the first entity in the graph database; if the first entity has not been constructed, extracting the source data corresponding to the first entity based on the ontology, the extraction rules, and the mapping rules to determine the first related knowledge; and importing the first related knowledge into the graph database to construct the target knowledge graph.
[0006] Secondly, embodiments of this application provide a knowledge graph construction apparatus, comprising: an ontology pre-setting module, used to acquire an ontology, extraction rules, and mapping rules corresponding to a target knowledge graph; wherein the ontology includes definitions of multiple entities and definitions of related information of the multiple entities, the extraction rules are rules for extracting data from source data corresponding to the entities, and the mapping rules are rules for mapping fields in the source data corresponding to the entities to the ontology; a first determining module, used to receive a query request, the query request including a first entity, and determine whether the first entity has been constructed in the graph database corresponding to the target knowledge graph according to the query request, the query request being used to query first related knowledge of the first entity in the graph database; a second determining module, used to extract the source data corresponding to the first entity according to the ontology, the extraction rules, and the mapping rules when the first entity has not been constructed, and determine the first related knowledge; and a construction module, used to import the first related knowledge into the graph database to construct the target knowledge graph.
[0007] Thirdly, embodiments of this application provide an electronic device including a processor, a memory, and a program or instructions stored in the memory and executable on the processor, wherein the program or instructions, when executed by the processor, implement the steps of the method described in the first aspect.
[0008] Fourthly, embodiments of this application provide a readable storage medium on which a program or instructions are stored, which, when executed by a processor, implement the steps of the method described in the first aspect.
[0009] Fifthly, embodiments of this application provide a chip, the chip including a processor and a communication interface, the communication interface being coupled to the processor, the processor being used to run programs or instructions to implement the method as described in the first aspect.
[0010] In this embodiment, the ontology, extraction rules, and mapping rules corresponding to the target knowledge graph are obtained. The ontology includes the definitions of multiple entities and related information of multiple entities. The extraction rules are rules for extracting data from the source data corresponding to the entity, and the mapping rules are rules for mapping fields in the source data corresponding to the entity to the ontology. A query request is received, which includes a first entity. Based on the query request, it is determined whether the first entity has been constructed in the graph database corresponding to the target knowledge graph. The query request is used to query the first related knowledge of the first entity in the graph database. If the first entity has not been constructed, the source data corresponding to the first entity is extracted according to the ontology, extraction rules, and mapping rules to determine the first related knowledge. The first related knowledge is imported into the graph database to construct the target knowledge graph. As can be seen, compared to directly extracting a large amount of knowledge from massive datasets to construct a knowledge graph, which results in knowledge that is rarely searched occupying a large amount of space resources and is not easy to construct multiple knowledge graphs, this technical solution can extract the source data corresponding to the first entity based on the user's query request. The amount of data extracted is smaller, saving the time of knowledge extraction. Correspondingly, when storing this knowledge, it occupies relatively less space. Moreover, since the ontology, extraction rules, and mapping rules are obtained, the knowledge required for each query request can be extracted using the ontology, extraction rules, and mapping rules, thereby realizing multiple constructions of the knowledge graph (dynamic construction), reducing the time and storage space occupied in constructing a knowledge graph under massive datasets. Attached Figure Description
[0011] Figure 1 This is a flowchart illustrating a method for constructing a knowledge graph according to an embodiment of this application;
[0012] Figure 2 This is a schematic diagram of a target knowledge graph provided in an embodiment of this application;
[0013] Figure 3(a) is a schematic diagram of a Bloom filter provided in another embodiment of this application;
[0014] Figure 3(b) is a schematic diagram of a Bloom filter provided in another embodiment of this application;
[0015] Figure 4 This is a flowchart illustrating another method for constructing a knowledge graph provided in an embodiment of this application;
[0016] Figure 5 This is a schematic diagram of the structure of a knowledge graph construction apparatus provided according to an embodiment of this application;
[0017] Figure 6 This is a schematic diagram of the structure of an electronic device provided according to an embodiment of this application. Detailed Implementation
[0018] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0019] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.
[0020] The knowledge graph construction method and apparatus provided in this application will be described in detail below with reference to the accompanying drawings, through specific embodiments and application scenarios.
[0021] Figure 1 This illustration shows a method for constructing a knowledge graph according to an embodiment of the present invention. This method can be executed by an electronic device, which may include a server and / or a terminal device, wherein the terminal device may be, for example, a mobile phone terminal. In other words, the method can be executed by software or hardware installed on the electronic device, and the method includes the following steps:
[0022] Step 102: Obtain the ontology, extraction rules, and mapping rules corresponding to the target knowledge graph.
[0023] The ontology includes the definitions of multiple entities and related information of multiple entities. The extraction rules are the rules for extracting data from the source data corresponding to the entities, and the mapping rules are the rules for mapping the fields in the source data corresponding to the entities to the ontology.
[0024] The source data corresponding to an entity comes from a database and is structured data. Of course, the source data corresponding to an entity can also come from semi-structured or unstructured data and be transformed to obtain structured data. Structured source data can be stored, for example, in the form of one or more tables.
[0025] In practical applications, an ontology includes the definitions of multiple entities and related information for those entities. This related information may include at least one of the following: entity attributes and relationships between entities. Since the same entity can represent different meanings in different domains, the definitions of that entity and its related information will also differ. Therefore, before actually constructing the knowledge graph, it is necessary to first obtain the definitions of entities and their related information for the domain corresponding to the target knowledge graph, i.e., to obtain the ontology corresponding to the target knowledge graph.
[0026] The definitions of entities and related information in an ontology are based on general concepts defined in domain dictionaries, etc. For example, when defining the entity "dog" in an ontology, a general concept such as "canine" can be used, rather than a definition with individual characteristics such as "has spots" when defining the entity "dog" in an ontology.
[0027] For example, taking a target knowledge graph that includes two entities, "book" and "author," and whose related information includes entity attributes and relationship information, the ontology includes general concepts of "book" and "author" defined according to domain dictionaries, etc. That is, the ontology includes the definitions of the two entities, "book" and "author." The ontology also includes attributes of the book, such as its literary genre; attributes of the author, such as the author's era; and, in addition, the ontology includes relationship information between the book and the author, such as the author creating the book.
[0028] Following the example above, the mapping rule can be a rule that maps fields such as "Journey to the West" and "novel" in the source data corresponding to the entity "book" to the book and the literary genre of the book in the ontology, respectively. In other words, the mapping rule is a rule that maps fields in the source data corresponding to the entity to the ontology.
[0029] Extraction rules are rules for extracting data from the source data corresponding to an entity. These rules can include rules that transform the extracted source data, i.e., transformation functions, which can replace fields in the source data with corresponding storage fields in the graph database. Continuing the example above, the graph database stores data for an entity named "Journey to the West." Since "Journey to the West" is also known as "Journey to the West: The Tale of the Monkey King," extraction rules could include replacing "Journey to the West: The Tale of the Monkey King" with "Journey to the West" when the field "Journey to the West: The Tale of the Monkey King" appears in the source data, and storing that data. Extraction rules can also include rules where, if the literary genre of the entity "Book" in the graph database is stored in the form of m (short story), n (novel), etc., and if the literary genre of the entity "Book" in the source data is a novel, then correspondingly, converting the novel into the form n for storage. Furthermore, when no method for updating the knowledge graph is specified, extraction rules can also include rules for extraction cycles. Electronic devices can extract data according to these extraction cycle rules, thereby updating the knowledge graph.
[0030] It should be noted that the above-mentioned ontology, extraction rules, and mapping rules are obtained to extract knowledge that can be stored in the graph database, but the ontology, extraction rules, and mapping rules are not used to extract the source data in the above process, so as to realize the construction of the knowledge graph.
[0031] Compared to directly constructing a knowledge graph, this embodiment first obtains the ontology, extraction rules, and mapping rules. Subsequently, as needed, the ontology, extraction rules, and mapping rules can be used to extract the source data multiple times, thereby realizing the construction of a dynamic knowledge graph.
[0032] Step 104: Receive a query request, which includes the first entity. Based on the query request, determine whether the first entity has been constructed in the graph database corresponding to the target knowledge graph.
[0033] The query request is used to retrieve the first relevant knowledge of the first entity in the graph database.
[0034] In practical applications, electronic devices can receive query requests input by users. The query request may include a single term or a sentence entered by the user; this embodiment does not limit this. However, when the query request includes a sentence, a corresponding extraction device is needed to extract one or more terms from the sentence. The single term or the extracted terms from the sentence constitute the entity corresponding to the query, i.e., the first entity.
[0035] It should be noted that the first entity, entity, and the second entity mentioned below in this technical solution are different from the entities in the ontology. Entities in the ontology are general concepts, while the first entity, entity, and the second entity mentioned below refer to nouns that have specific meanings or strong referentiality in the text, such as personal names, place names, organization names, and times. For example, the entities in the ontology may include the entity "book," and the first entity, entity, and the second entity mentioned below may be the entity "Journey to the West."
[0036] Based on the query request, the electronic device evaluates the entities in the graph database to determine whether the first entity has already been constructed in the graph database. In practical applications, the electronic device can use a Bloom filter to evaluate the entities in the graph database and determine whether the first entity has already been constructed in the graph database.
[0037] Step 106: If the first entity has not been constructed, extract the source data corresponding to the first entity according to the ontology, extraction rules and mapping rules to determine the first relevant knowledge.
[0038] When the electronic device judges the entities in the graph database and determines that the first entity has not been constructed in the graph database, it uses the ontology, extraction rules and mapping rules obtained in step 102 to extract the source data corresponding to the first entity and determine the first relevant knowledge.
[0039] For example, the source data of multiple entities is shown in Table 1 below, where the first entity is "Wu Cheng'en". The relevant information includes the entity's attributes and the relationship information between entities. For example, the author, the era in which the author lived (the author's attribute), the work (the relationship information with the author entity), and the creation date (the work's attribute) are defined in the ontology.
[0040] Table 1
[0041] Journey to the West Ming Dynasty Wu Cheng'en Ming Dynasty Yu Ding Ji 1500-1582 Wu Cheng'en Ming Dynasty Yangliuqing Ming Dynasty Wu Cheng'en Ming Dynasty Boat trip Ming Dynasty Wu Cheng'en Ming Dynasty Peach Blossom Spring Ming Dynasty Wu Cheng'en Ming Dynasty Mr. Sheyang's manuscripts Ming Dynasty Wu Cheng'en Ming Dynasty The Road is Hard (Three Poems) Tang Dynasty Li Bai Tang Dynasty Spring Night Rain Tang Dynasty Du Fu Tang Dynasty
[0042] Based on the mapping rules and ontology, the columns of the "Works" field in Table 1 (source data of multiple entities) can be mapped to the "Works" entity in the ontology, the columns of the "Creation Year" field in the source data can be mapped to the "Creation Year" in the ontology, the columns of the "Author" field in the source data can be mapped to the "Author" entity in the ontology, and the columns of the "Author's Era" field in the source data can be mapped to the "Author's Era" in the ontology.
[0043] Based on the extraction rules, the source data corresponding to "Wu Cheng'en" (the first entity) can be extracted to determine the first relevant knowledge: "Wu Cheng'en" (author); Ming Dynasty (the author's era); "Wu Cheng'en" created the following works (relationship information between entities): Journey to the West, Ming Dynasty, Yu Ding Ji, 1500-1582, Yang Liu Qing, Ming Dynasty, Zhou Xing, Ming Dynasty, Peach Blossom Spring, Ming Dynasty, Sheyang Xiansheng's manuscript, Ming Dynasty (works and their creation dates). It should be understood that the first relevant knowledge can be represented in the form of tables, etc. The above representation is only for the purpose of showing the content included in the first relevant knowledge. This embodiment does not specifically limit the representation of the first relevant knowledge. Extracting the source data corresponding to the first entity to determine the first relevant knowledge, compared with the full extraction of knowledge in related technologies, extracting the source data corresponding to the first entity results in a smaller amount of data extracted, saving knowledge extraction time.
[0044] Step 108: Import the first relevant knowledge into the graph database to construct the target knowledge graph.
[0045] The constructed target knowledge graph, following the example above, can be found in [reference needed]. Figure 2 As shown, the first related knowledge of the first entity 201 may include the attributes 202 of the first entity, the related entities 203 and the related entities 204 of the first entity, as well as the relationship information between the entities: Wu Cheng'en's creation of Journey to the West, Yu Ding Ji, Yang Liu Qing, Zhou Xing, Peach Blossom Spring, and Sheyang Xiansheng's manuscript.
[0046] The knowledge graph construction method provided in this embodiment of the invention involves obtaining the ontology, extraction rules, and mapping rules corresponding to the target knowledge graph. The ontology includes the definitions of multiple entities and related information of multiple entities. The extraction rules are rules for extracting data from the source data corresponding to the entities, and the mapping rules are rules for mapping fields in the source data corresponding to the entities to the ontology. A query request is received, which includes a first entity. Based on the query request, it is determined whether the first entity has been constructed in the graph database corresponding to the target knowledge graph. The query request is used to query the first related knowledge of the first entity in the graph database. If the first entity has not been constructed, the source data corresponding to the first entity is extracted according to the ontology, extraction rules, and mapping rules to determine the first related knowledge. The first related knowledge is then imported into the graph database to construct the target knowledge graph. As can be seen, compared to directly extracting a large amount of knowledge from massive datasets to construct a knowledge graph, which results in knowledge that is rarely searched occupying a large amount of space resources and is not easy to construct multiple knowledge graphs, this technical solution can extract the source data corresponding to the first entity based on the user's query request. The amount of data extracted is smaller, saving the time of knowledge extraction. Correspondingly, when storing this knowledge, it occupies relatively less space. Moreover, since the ontology, extraction rules, and mapping rules are obtained, the knowledge required for each query request can be extracted using the ontology, extraction rules, and mapping rules, thereby realizing multiple constructions of the knowledge graph (dynamic construction), reducing the time and storage space occupied in constructing a knowledge graph under massive datasets.
[0047] In one implementation, the method further includes the following steps A1-A3:
[0048] Step A1: If the source data corresponding to the second entity is updated, determine whether the second entity has been constructed in the graph database based on the updated source data.
[0049] In practical applications, Bloom filters can be used to determine whether a second entity has already been constructed in a graph database.
[0050] It should be noted that, in order to more accurately determine whether the second entity has been constructed in the graph database, the entity name of the second entity must be consistent with the entity name of the entity in the graph database. If the entity name of the second entity is inconsistent with the entity name of the entity in the graph database, to make the entity names consistent, entity extraction rules can be used to extract the source data corresponding to the second entity, and the entity name of the second entity can be transformed to obtain the entity name used for storage in the graph database, and then it can be determined whether the second entity has been constructed in the graph database. Of course, in order to make the entity name of the second entity consistent with the entity name of the entity in the graph database, normalization processing can also be performed, which is not limited in this embodiment.
[0051] Step A2: With the second entity already constructed, extract the source data corresponding to the second entity based on the ontology, extraction rules, and mapping rules to determine the second relevant knowledge of the second entity.
[0052] Step A3: Import the second relevant knowledge into the graph database to update the knowledge graph.
[0053] Based on the updated source data, if it is determined that the second entity has been constructed in the graph database, the source data corresponding to the second entity is extracted. The source data corresponding to the second entity and the source data corresponding to the first entity come from the same database and are structured data.
[0054] The source data corresponding to the second entity is extracted to determine the second relevant knowledge. Compared to the full extraction of knowledge in related technologies, extracting only the source data corresponding to the second entity results in a smaller amount of data extracted, saving time. This second relevant knowledge is then imported into a graph database to update the target knowledge graph, ensuring that the second relevant knowledge covers the previously constructed, unupdated knowledge of the second entity in the graph database. Compared to the overall knowledge graph update in related technologies, which often leads to poor search results when searching the knowledge graph during the update process, this solution requires less update time and is more likely to find new knowledge, resulting in superior search performance.
[0055] In one implementation, the source data corresponding to the first entity is extracted to determine the first relevant knowledge (i.e., step 106), which can be specifically implemented through the following steps B1-B3:
[0056] Step B1: Obtain an index table constructed from the source data corresponding to multiple entities. The index table includes the entity name and the entity's unique identifier (ID).
[0057] Step B2: Based on the first entity, determine the entity ID corresponding to the entity name by retrieving the entity name from the index table.
[0058] Following the example in step 106 above, when the first entity is "Journey to the West", the entity ID of "Work" can be determined by searching the index table for example "Work" (the entity name of the entity).
[0059] Step B3: Based on the entity ID, determine one or more of the following information corresponding to the first entity: entity attributes, related entities, and relationship information between entities.
[0060] In practical applications, electronic devices acquire an index table constructed from source data corresponding to multiple entities. This index table includes an entity name field and an entity ID field. When an electronic device receives a first entity, it can retrieve the source data corresponding to the first entity by indexing the entity name field and the entity ID field based on the entity name field of the entity corresponding to the first entity. Then, it can extract one or more of the following information from the source data: the attributes of the first entity, related entities, the attributes of the entities related to the first entity, and the relationship information between the first entity and the entities related to the first entity, i.e., the first related knowledge.
[0061] Similarly, extracting the source data corresponding to the second entity and determining the second relevant knowledge of the second entity (i.e., step A2) can also be specifically the processing of the first entity in steps B1-B3 above.
[0062] Since the source data in the database is stored in the form of tables, there may be a large amount of data in the tables, that is, a large number of columns in the tables, or multiple tables. Compared with directly traversing the entire table, this technical solution can improve the speed of extracting the first or second relevant knowledge, thereby reducing the time spent on knowledge extraction.
[0063] In one implementation, after determining whether the first entity has already been constructed in the graph database based on the query request (i.e., step 104), the following steps may also be performed:
[0064] Obtain the first relevant knowledge of the first entity and display the target knowledge graph corresponding to the first relevant knowledge.
[0065] Based on the query request, determine whether the first entity has already been constructed in the graph database, and obtain two possible results:
[0066] In the first scenario, the first entity has already been constructed in the graph database. Accordingly, the electronic device retrieves the first relevant knowledge of the first entity from the graph database and displays the target knowledge graph corresponding to the first relevant knowledge.
[0067] In the second scenario, if the first entity is not constructed in the graph database, the electronic device first constructs the knowledge graph corresponding to the first related knowledge of the first entity, then retrieves the first related knowledge of the first entity from the graph database and displays the target knowledge graph corresponding to the first related knowledge.
[0068] In one implementation, the method further includes the following step C3:
[0069] The Bloom filter is used to determine whether the target entity has already been constructed in the graph database.
[0070] The target entity is either the first entity or the second entity that is determined to have been constructed in the graph database.
[0071] A Bloom filter consists of a binary vector and a hash function. A Bloom filter can be used to determine whether a first entity or a second entity is in the existing set of entities in a graph database, without requiring separate storage of the first entity, the second entity, and the existing entities, thus reducing memory usage compared to other algorithms.
[0072] In one implementation, as shown in Figures 3(a) and (b), determining whether the first or second entity has been constructed in the graph database using a Bloom filter (i.e., step C3) can be performed as follows: D1-D5.
[0073] Step D1: Obtain a bit array of length n, where the value of each bit in the bit array is zero.
[0074] A bit array is a binary vector with two values: 0 and 1.
[0075] Step D2: Obtain k hash functions and the constructed entities, where k is less than n.
[0076] Step D3: Based on the k hash functions, for each constructed entity, determine the k first bit positions and assign them the value one.
[0077] A hash function maps a constructed entity to a first position with a value of 1. Obtaining k hash functions means that each of the k hash functions maps a constructed entity to k first positions with a value of 1.
[0078] Step D4: Determine the k second bit positions for each target entity based on the k hash functions.
[0079] The target entity is either the first entity or the second entity that is determined to have been constructed in the graph database.
[0080] When k is 1, a hash function can map a target entity to a bit position in a bit array (a second position). Since using a single hash function for mapping only requires checking if the value of the second position is 0, it is easier to conclude that the target entity has already been constructed in the graph database when an already constructed entity and the target entity are mapped to the same bit position, i.e., the value of the second position of the target entity is 1. To reduce the possibility of errors caused by judging through a Bloom filter, multiple hash functions can be obtained, where k is greater than 1 and less than n.
[0081] Step D5: Determine whether the target entity has been constructed based on the values of the k second bit positions.
[0082] Based on the values of the k second bit positions, determine whether there is a second bit position with a value of zero. If there is a second bit position with a value of zero, it can be determined that the target entity has not been constructed in the graph database. For example, taking k as 3 and n as 10, one case is shown in Figure 3(a). The constructed entity 310 is mapped to three first bit positions 311, and the target entity 320 is mapped to three second bit positions 321. There are two second bit positions with values of zero, which determines that the target entity has not been constructed in the graph database. If all the values of the second bit positions are 1, there are two cases.
[0083] In the first scenario, the target entity has already been constructed in the graph database. Since the target entity is actually a pre-constructed entity, meaning the second bit position corresponding to the target entity is the first bit position of that pre-constructed entity, the value corresponding to that second bit position is all 1.
[0084] In the second scenario, the target entity is not constructed in the graph database. The target entity should be mapped to a second bit position with a value of zero. However, because a certain second bit position corresponding to the target entity is repeatedly mapped to a certain first bit position of an already constructed entity, and the k second bit positions corresponding to the target entity are completely repeatedly mapped to the first bit positions of the already constructed entities, the values of the second bit positions are all 1. In reality, the target entity is not constructed in the graph database. For example, taking k as 3 and n as 10, one case is shown in Figure 3(b). Because the three second bit positions 321 corresponding to the target entity 320 are repeatedly mapped to the three first bit positions 311 of the already constructed entities, the values of the second bit positions are all 1. In reality, the target entity is not constructed in the graph database.
[0085] The occurrence of the second situation mentioned above is related to k and n. In order to reduce the occurrence of the second situation, k and n need to be set in advance.
[0086] It should be noted that if all k second bit positions of the target entity are 1, the electronic device obtains the first relevant knowledge of the target entity from the graph database. If the first relevant knowledge of the target entity cannot be obtained from the graph database, steps 106 to 108 are executed.
[0087] Because the Bloom filter determines whether the first or second entity is in the existing entity set of the graph database by calculating the value of the hash function mapping position, it requires less time to make the determination compared to using other algorithms.
[0088] Figure 4 This is a schematic flowchart illustrating a method for constructing a knowledge graph according to another embodiment of this application, such as... Figure 4 As shown, the method for constructing a knowledge graph may include the following steps:
[0089] Step 401: Obtain the ontology, extraction rules, and mapping rules corresponding to the target knowledge graph.
[0090] The ontology includes the definitions of multiple entities and related information of multiple entities. The extraction rules are the rules for extracting data from the source data corresponding to the entities, and the mapping rules are the rules for mapping the fields in the source data corresponding to the entities to the ontology.
[0091] Step 402: Receive a query request, which includes the first entity.
[0092] Step 403: Based on the query request, use a Bloom filter to determine whether the first entity has been constructed in the graph database corresponding to the target knowledge graph.
[0093] The query request is used to retrieve the first relevant knowledge of the first entity in the graph database.
[0094] If yes, proceed to step 408; otherwise, proceed to step 404-408.
[0095] Step 404: If the first entity has not been constructed, obtain an index table for the source data corresponding to multiple entities based on the ontology, extraction rules and mapping rules. The index table includes entity name and entity ID.
[0096] Step 405: Based on the first entity, determine the entity ID corresponding to the entity name by retrieving the entity name from the index table.
[0097] Step 406: Based on the entity ID, determine the attributes of the entity corresponding to the first entity, as well as the related entity and the relationship information between entities.
[0098] Step 407: Import the attributes of the entity corresponding to the first entity, as well as related entity and relationship information between entities, into the graph database to construct the target knowledge graph.
[0099] Step 408: If the first entity has been constructed, obtain the first relevant knowledge of the first entity and display the target knowledge graph corresponding to the first relevant knowledge.
[0100] The specific processes from step 401 to step 408 have been described in detail in the above embodiments and will not be repeated here.
[0101] The technical solution of this application involves obtaining the ontology, extraction rules, and mapping rules corresponding to the target knowledge graph. The ontology includes the definitions of multiple entities and related information of multiple entities. The extraction rules are rules for extracting data from the source data corresponding to the entity, and the mapping rules are rules for mapping fields in the source data corresponding to the entity to the ontology. A query request is received, which includes a first entity. Based on the query request, it is determined whether the first entity has been constructed in the graph database corresponding to the target knowledge graph. The query request is used to query the first related knowledge of the first entity in the graph database. If the first entity has not been constructed, the source data corresponding to the first entity is extracted according to the ontology, extraction rules, and mapping rules to determine the first related knowledge. The first related knowledge is imported into the graph database to construct the target knowledge graph. As can be seen, compared to directly extracting a large amount of knowledge from massive datasets to construct a knowledge graph, which results in knowledge that is rarely searched occupying a large amount of space resources and is not easy to construct multiple knowledge graphs, this technical solution can extract the source data corresponding to the first entity based on the user's query request. The amount of data extracted is smaller, saving the time of knowledge extraction. Correspondingly, when storing this knowledge, it occupies relatively less space. Moreover, since the ontology, extraction rules, and mapping rules are obtained, the knowledge required for each query request can be extracted using the ontology, extraction rules, and mapping rules, thereby realizing multiple constructions of the knowledge graph (dynamic construction), reducing the time and storage space occupied in constructing a knowledge graph under massive datasets.
[0102] It should be noted that the knowledge graph construction method provided in this application embodiment can be executed by an electronic device or a control module in the electronic device for executing the knowledge graph construction method. This application embodiment uses an electronic device executing the knowledge graph construction method as an example to illustrate the knowledge graph construction apparatus provided in this application embodiment.
[0103] Figure 5 This is a schematic diagram of the structure of a knowledge graph construction apparatus according to an embodiment of the present invention. Figure 5As shown, the knowledge graph construction device includes: an ontology pre-setting module 510, a first determining module 520, a second determining module 530, and a construction module 540.
[0104] The ontology pre-built module 510 is used to obtain the ontology, extraction rules and mapping rules corresponding to the target knowledge graph. The ontology includes the definition of multiple entities and the definition of related information of multiple entities. The extraction rules are the rules for extracting data from the source data corresponding to the entity. The mapping rules are the rules for mapping the fields in the source data corresponding to the entity to the ontology.
[0105] The first determining module 520 is used to receive a query request, which includes a first entity. Based on the query request, it determines whether the first entity has been constructed in the graph database corresponding to the target knowledge graph. The query request is used to query the first related knowledge of the first entity in the graph database.
[0106] The second determining module 530 is used to extract the source data corresponding to the first entity based on the ontology, extraction rules and mapping rules, and determine the first relevant knowledge when the first entity has not been constructed.
[0107] Module 540 is used to import the first relevant knowledge into the graph database to construct the target knowledge graph.
[0108] In one implementation, the knowledge graph construction apparatus further includes: a third determining module 550, a fourth determining module 560, and an updating module 570.
[0109] The third determining module 550 is used to determine, based on the updated source data, whether the second entity has been constructed in the graph database when the source data corresponding to the second entity is updated.
[0110] The fourth determination module 560 is used to extract the source data corresponding to the second entity based on the ontology, extraction rules and mapping rules, and determine the second related knowledge of the second entity when the second entity has been constructed.
[0111] Update module 570 is used to import the second related knowledge into the graph database to update the target knowledge graph.
[0112] In one implementation, the second determining module 540 is used to obtain an index table constructed from source data corresponding to multiple entities, the index table including entity name and entity ID; based on the first entity, the entity ID corresponding to the entity name is determined by retrieving the entity name in the index table; based on the entity ID, one or more of the following information corresponding to the first entity are determined: entity attributes, related entities, and relationship information between entities.
[0113] In one implementation, the first determining module 520 is further used to obtain the first related knowledge of the first entity and display the target knowledge graph corresponding to the first related knowledge.
[0114] In one implementation, the judgment module 580 is further configured to determine, through a Bloom filter, whether the target entity has already been constructed in the graph database.
[0115] The target entity is either the first entity or the second entity that is determined to have been constructed in the graph database.
[0116] In one implementation, the judgment module 580 is used to obtain a bit array of length n, where the value of each bit in the bit array is zero; obtain k hash functions and the created entities, where k is less than n; based on the k hash functions, for each created entity, determine k first bit positions and assign them the value one; based on the k hash functions, determine k second bit positions for each target entity; and based on the values of the k second bit positions, determine whether the target entity has been constructed.
[0117] The knowledge graph construction apparatus provided in this embodiment of the invention acquires the ontology, extraction rules, and mapping rules corresponding to the target knowledge graph. The ontology includes the definitions of multiple entities and the definitions of related information of multiple entities. The extraction rules are rules for extracting data from the source data corresponding to the entity, and the mapping rules are rules for mapping fields in the source data corresponding to the entity to the ontology. A query request is received, which includes a first entity. Based on the query request, it is determined whether the first entity has been constructed in the graph database corresponding to the target knowledge graph. The query request is used to query the first related knowledge of the first entity in the graph database. If the first entity has not been constructed, the source data corresponding to the first entity is extracted according to the ontology, extraction rules, and mapping rules to determine the first related knowledge. The first related knowledge is imported into the graph database to construct the target knowledge graph. As can be seen, compared to directly extracting a large amount of knowledge from massive datasets to construct a knowledge graph, which results in knowledge that is rarely searched occupying a large amount of space resources and is not easy to construct multiple knowledge graphs, this technical solution can extract the source data corresponding to the first entity based on the user's query request. The amount of data extracted is smaller, saving the time of knowledge extraction. Correspondingly, when storing this knowledge, it occupies relatively less space. Moreover, since the ontology, extraction rules, and mapping rules are obtained, the knowledge required for each query request can be extracted using the ontology, extraction rules, and mapping rules, thereby realizing multiple constructions of the knowledge graph (dynamic construction), reducing the time and storage space occupied in constructing a knowledge graph under massive datasets.
[0118] The knowledge graph construction apparatus in this application embodiment can be a device, or a component, integrated circuit, or chip in a terminal. The device can be a mobile electronic device or a non-mobile electronic device. For example, mobile electronic devices can be mobile phones, tablets, laptops, PDAs, in-vehicle electronic devices, wearable devices, ultra-mobile personal computers (UMPCs), netbooks, or personal digital assistants (PDAs), etc., while non-mobile electronic devices can be servers, network-attached storage (NAS), personal computers (PCs), televisions (TVs), ATMs, or self-service machines, etc. This application embodiment does not impose specific limitations.
[0119] The knowledge graph construction apparatus in this application embodiment can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this application embodiment does not specifically limit the specific operating system used.
[0120] The knowledge graph construction apparatus provided in this application embodiment can achieve Figure 1 To avoid repetition, the various processes implemented in the method embodiment shown in Figure 3 will not be described again here.
[0121] Based on the same technical concept, embodiments of this application also provide an electronic device for executing the above-described knowledge graph construction method. Figure 5 This is a schematic diagram of the structure of an electronic device to implement various embodiments of this application. The electronic device can vary significantly due to differences in configuration or performance, and may include a processor 610, a communications interface 620, a memory 630, and a communication bus 640. The processor 610, communications interface 620, and memory 630 communicate with each other via the communication bus 640. The processor 610 can call a computer program stored in the memory 630 and executable on the processor 610 to perform the following steps:
[0122] The process involves: acquiring the ontology, extraction rules, and mapping rules corresponding to the target knowledge graph; obtaining the ontology, which includes definitions of multiple entities and related information; extracting rules, which are rules for extracting data from the source data corresponding to the entities; and mapping rules, which are rules for mapping fields in the source data corresponding to the entities to the ontology; receiving a query request, which includes a first entity; determining whether the first entity has been constructed in the graph database corresponding to the target knowledge graph; and retrieving the first related knowledge of the first entity from the graph database. If the first entity has not been constructed, extracting the source data corresponding to the first entity based on the ontology, extraction rules, and mapping rules to determine the first related knowledge. Finally, importing the first related knowledge into the graph database to construct the target knowledge graph.
[0123] Using the electronic device provided in this embodiment of the invention, the following steps are taken: First, an ontology, extraction rules, and mapping rules corresponding to a target knowledge graph are obtained. The ontology includes definitions of multiple entities and related information of those entities. The extraction rules are rules for extracting data from source data corresponding to entities. The mapping rules are rules for mapping fields in the source data corresponding to entities to the ontology. A query request is received, including a first entity. Based on the query request, it is determined whether the first entity has been constructed in the graph database corresponding to the target knowledge graph. The query request is used to query the first related knowledge of the first entity in the graph database. If the first entity has not been constructed, the source data corresponding to the first entity is extracted according to the ontology, extraction rules, and mapping rules to determine the first related knowledge. The first related knowledge is then imported into the graph database to construct the target knowledge graph. As can be seen, compared to directly extracting a large amount of knowledge from massive datasets to construct a knowledge graph, which results in knowledge that is rarely searched occupying a large amount of space resources and is not easy to construct multiple knowledge graphs, this technical solution can extract the source data corresponding to the first entity based on the user's query request. The amount of data extracted is smaller, saving the time of knowledge extraction. Correspondingly, when storing this knowledge, it occupies relatively less space. Moreover, since the ontology, extraction rules, and mapping rules are obtained, the knowledge required for each query request can be extracted using the ontology, extraction rules, and mapping rules, thereby realizing multiple constructions of the knowledge graph (dynamic construction), reducing the time and storage space occupied in constructing a knowledge graph under massive datasets.
[0124] The specific execution steps can be found in the various steps of the above knowledge graph construction method embodiment, and can achieve the same technical effect. To avoid repetition, they will not be repeated here.
[0125] It should be noted that the electronic devices in the embodiments of this application include: servers, terminals, or other devices besides terminals.
[0126] The above electronic device structure does not constitute a limitation on the electronic device. An electronic device may include more or fewer components than illustrated, or combine certain components, or arrange them differently. For example, an input unit may include a Graphics Processing Unit (GPU) and a microphone, and a display unit may use a liquid crystal display (LCD), organic light-emitting diode (OLED), or other similar display panels. User input units include at least one of a touch panel and other input devices. A touch panel is also called a touchscreen. Other input devices may include, but are not limited to, physical keyboards, function keys (such as volume control buttons, power buttons, etc.), trackballs, mice, and joysticks, which will not be elaborated further here.
[0127] Memory can be used to store software programs and various data. Memory can primarily include a first storage area for storing programs or instructions and a second storage area for storing data. The first storage area can store the operating system, application programs or instructions required for at least one function (such as sound playback, image playback, etc.). Furthermore, memory can include volatile memory or non-volatile memory, or both. Non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous linked dynamic random access memory (Synchlink DRAM, SLDRAM), and direct memory bus RAM (DRRAM).
[0128] The processor may include one or more processing units; optionally, the processor integrates an application processor and a modem processor, wherein the application processor mainly handles operations related to the operating system, user interface, and applications, while the modem processor mainly handles wireless communication signals, such as a baseband processor. It is understood that the aforementioned modem processor may also not be integrated into the processor.
[0129] This application also provides a readable storage medium storing a program or instructions. When the program or instructions are executed by a processor, they implement the various processes of the above-described knowledge graph construction method embodiments and achieve the same technical effects. To avoid repetition, they will not be described again here.
[0130] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0131] This application embodiment also provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the various processes of the above-described knowledge graph construction method embodiment and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0132] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.
[0133] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.
[0134] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, 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 is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0135] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
Claims
1. A method for constructing a knowledge graph, characterized in that, The method includes: Obtain the ontology, extraction rules, and mapping rules corresponding to the target knowledge graph; wherein, the ontology includes the definitions of multiple entities and the definitions of related information of the multiple entities, the extraction rules are rules for extracting data from the source data corresponding to the entities, and the mapping rules are rules for mapping fields in the source data corresponding to the entities to the ontology. Receive a query request, wherein the query request includes a first entity; Based on the query request, a Bloom filter is used to determine whether the first entity has been constructed in the graph database corresponding to the target knowledge graph. The query request is used to query the first related knowledge of the first entity in the graph database. The first related knowledge of the first entity includes the attributes of the entity corresponding to the first entity, as well as related entities and the relationship information between entities. If the first entity is not constructed, an index table is obtained based on the ontology, the extraction rules and the mapping rules to construct the source data corresponding to multiple entities. The index table includes entity name and entity ID. Based on the first entity, the entity ID corresponding to the entity name is determined by retrieving the entity name from the index table; Based on the entity ID, determine the attributes of the entity corresponding to the first entity, as well as related entity and relationship information between entities; Import the attributes of the entity corresponding to the first entity, as well as related entities and the relationship information between entities, into the graph database to construct the target knowledge graph; Given that the first entity has been constructed, obtain the first relevant knowledge of the first entity and display the target knowledge graph corresponding to the first relevant knowledge.
2. The method for constructing a knowledge graph according to claim 1, characterized in that, The method further includes: If the source data corresponding to the second entity is updated, determine whether the second entity has been constructed in the graph database based on the updated source data; With the second entity already constructed, the source data corresponding to the second entity is extracted according to the ontology, the extraction rules, and the mapping rules to determine the second related knowledge of the second entity; The second relevant knowledge is imported into the graph database to update the target knowledge graph.
3. The method for constructing a knowledge graph according to claim 1, characterized in that, The step of determining whether the first entity has been constructed in the graph database using a Bloom filter includes: Obtain a bit array of length n, wherein the value of each bit in the bit array is zero; Obtain k hash functions and the constructed entities, where k is less than n; Based on the k hash functions, for each constructed entity, determine k first bit positions and assign them the value one; Based on the k hash functions, determine the k second bit positions for each target entity; wherein, the target entity is the entity that is determined to have been constructed in the graph database; Based on the values of the k second bit positions, determine whether the target entity has been constructed.
4. A knowledge graph construction apparatus, characterized in that, include: An ontology pre-configuration module is used to obtain the ontology, extraction rules, and mapping rules corresponding to the target knowledge graph; wherein, the ontology includes the definitions of multiple entities and the definitions of related information of the multiple entities, the extraction rules are rules for extracting data from the source data corresponding to the entities, and the mapping rules are rules for mapping fields in the source data corresponding to the entities to the ontology. The first determining module is used to receive a query request, the query request including a first entity, and determine whether the first entity has been constructed in the graph database corresponding to the target knowledge graph according to the query request. The query request is used to query the first related knowledge of the first entity in the graph database. The first related knowledge of the first entity includes the attributes of the entity corresponding to the first entity, as well as related entities and the relationship information between entities. The second determining module is used to, in the absence of the first entity being constructed, obtain an index table constructed from source data corresponding to multiple entities based on the ontology, the extraction rules, and the mapping rules. The index table includes entity names and entity IDs. Based on the first entity, the module determines the entity ID corresponding to the entity name by retrieving the entity name from the index table. Based on the entity ID, the module determines one or more of the following information corresponding to the first entity: entity attributes, related entities, and relationship information between entities. A construction module is used to import the first relevant knowledge into the graph database to construct the target knowledge graph; The first determining module is also used to obtain the first relevant knowledge of the first entity and display the target knowledge graph corresponding to the first relevant knowledge; The determination module is used to determine whether a target entity has been constructed in the graph database by using a Bloom filter; wherein the target entity is the entity that is determined to have been constructed in the graph database.
5. The apparatus according to claim 4, characterized in that, Also includes: The third determining module is used to determine, based on the updated source data, whether the second entity has been constructed in the graph database when the source data corresponding to the second entity is updated. The fourth determining module is used to extract the source data corresponding to the second entity based on the ontology, the extraction rules and the mapping rules, and determine the second related knowledge of the second entity, when the second entity has been constructed. The update module is used to import the second related knowledge into the graph database to update the target knowledge graph.
6. An electronic device, characterized in that, It includes a processor, a memory, and a program or instructions stored in the memory and executable on the processor, wherein the program or instructions, when executed by the processor, implement the steps of the knowledge graph construction method as described in any one of claims 1-3.
7. A readable storage medium, characterized in that, The readable storage medium stores a program or instructions that, when executed by a processor, implement the steps of the knowledge graph construction method as described in any one of claims 1-3.
Citation Information
Patent Citations
Power failure intelligent question answering method and device based on knowledge graph
CN113051382A
Knowledge graph construction method and device, electronic equipment and computer storage medium
CN114461744A