A method and system for constructing a knowledge graph based on a relational database
By constructing a knowledge graph in the context of digital government, the problems of scattered and isolated data tables and insufficient accuracy of user query text in cross-departmental relational databases are solved, enabling efficient cross-departmental data collaboration and accurate retrieval.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- GUANGDONG HUALIANHUI TECH SERVICES CO LTD
- Filing Date
- 2025-11-18
- Publication Date
- 2026-07-03
Smart Images

Figure CN121543683B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of knowledge graph construction technology, and more specifically, to a method and system for constructing knowledge graphs based on relational databases. Background Technology
[0002] Against the backdrop of the continuous deepening of digital government construction and e-government data governance, the core business data of various government departments (such as social security payment records, enterprise registration information, personal tax data, medical insurance reimbursement details, etc.) have long been stored in a structured and standardized manner in their respective relational databases. This has ensured both the stability of data storage and the security of transaction processing, and laid the foundation for subsequent data reuse. At the same time, thanks to the rapid development of e-government network communication technologies (such as cross-departmental dedicated data transmission channels and e-government cloud platforms) and data sharing protocols (such as unified data interface standards and secure encrypted transmission specifications), the relational databases of different departments have broken down physical barriers, enabling cross-departmental data interaction and access, and providing technical support for collaborative applications of e-government data.
[0003] Furthermore, with the continuous upgrading of government service demands such as "one-stop online service" and "cross-provincial service", existing technologies have also trained a mapping model based on the matching relationship between "query text and data table". When users search for different tables, the database server can input query text in natural language form, allowing the mapping model to gradually learn the corresponding association rules, thereby adjusting the output of multiple candidate data tables, and using multiple candidate data tables to construct the corresponding knowledge graph for users to select the required table for viewing.
[0004] However, in the context of digital government, due to the long-standing independence of business operations and autonomy in data construction among various government departments, early data systems were mostly developed in a closed-loop model within each department. The design of data table structures and field naming rules were all independently formulated by each department based on its own business processes and management habits (for example, the Social Security Bureau designed a "Detailed Statement of Enterprise Social Security Payments" around social security payment business, which included exclusive fields such as "Payment Cycle" and "Unit Number"). Moreover, the departments did not form a unified mechanism for disclosing and popularizing table structures (such as not providing users with clear table structure documentation or business-table correspondence guidelines).
[0005] Meanwhile, ordinary users (including business personnel and the general public) only focus on the results of government service processing and do not need to or have the channels to deeply understand the technical architecture details of the databases of various departments. As a result, users are not familiar with the table structure design of the databases of various departments (such as not knowing that "enterprise social security payment data" corresponds to "enterprise social security payment details table" rather than "enterprise social security account opening registration table"), do not understand the standardized classification logic of government data (such as not being able to distinguish that "personal medical insurance reimbursement details" and "personal medical insurance account balance" belong to different data tables), and have difficulty accurately inputting query text that points to the corresponding data table. Problems such as vague query text description, missing keywords or semantic deviation often occur, making users have to repeatedly filter to find the data table they need.
[0006] Incorrect selections (such as mistakenly using "Enterprise Social Security Account Opening Registration Form" as a matching table for "Enterprise Social Security Payment Data") or fuzzy matching (such as selecting a non-target table simply because of similar names) generated during the user screening process will directly create training samples with errors. As a result, after the mapping model is trained, it will be unable to accurately capture the core business relationship between the query text and the data table, and thus output a data table that has no relation to the query requirements. The mapping model trained based on this will output tables that have no business relationship with the query requirements. This will cause the knowledge graph subsequently built based on the table to be filled with semantically fragmented and incorrectly associated entities, failing to truly reflect the collaborative logic of government data, and ultimately losing the core value of data integration and efficient querying.
[0007] In view of this, we propose a method and system for constructing knowledge graphs based on relational databases. Summary of the Invention
[0008] The purpose of this invention is to solve the problems in digital government scenarios, such as scattered and isolated data tables in cross-departmental relational databases, unclear relationships, and insufficient accuracy of query text due to users' unfamiliarity with the table structure, which in turn leads to low data retrieval efficiency and difficulties in cross-departmental data collaboration.
[0009] To achieve the above objectives, this invention provides a method for constructing a knowledge graph based on a relational database, comprising the following steps:
[0010] S1. Establish a network communication channel with the relational database to obtain multiple data tables in each relational database, as well as all attributes of each data table;
[0011] S2. Obtain matching pairs, which include query text and all attributes of multiple data tables corresponding to the query text. All attributes include table names and table header names. Use semantic encoding mapping to convert all attributes and query text into corresponding text semantic vectors and table semantic vectors.
[0012] The mapping model is trained by matching pairs after being converted into semantic vectors. After the mapping model is trained, the text semantic vectors are input into the mapping model, the mapping model outputs table semantic vectors, and the multiple table names corresponding to the table semantic vectors are retrieved. The table names are defined as entities in the knowledge graph.
[0013] S3. Determine the table headers with the same meaning but different names in different data tables, mark the table headers with the same meaning but different names to form marked table headers, establish the mapping relationship between the attribute vectors corresponding to the marked table headers, and adjust the table semantic vector in step S2.
[0014] S4. Receive multiple table names from the knowledge graph construction in step S2 to form a data table set A; receive the same labeled table headers from step S3, retrieve the table names corresponding to the labeled table headers to form a data table set B; use data table set B to adjust data table set A, and remove entities in data table set A that do not have relationships.
[0015] As a further improvement to this technical solution, in step S1, the network address, port number, and authentication information of the relational database are first obtained; based on the network address, port number, and authentication information, a connection request is sent to the database server; after the database server verifies the identity, a network communication channel is established between the database and the relational database.
[0016] As a further improvement to this technical solution, each training sample in S2 includes at least one data table and one query text.
[0017] The query request is sent to the database server through the network channel established in step S1 to query all attributes of each data table in the database server, including all table header names and table names;
[0018] A semantic encoding mapping method is used to convert multiple table header names in each training sample into table semantic vectors and query text into text semantic vectors. The mapping model is trained using table semantic vectors and text semantic vectors. The mapping model is used to learn the relationship between query text and multiple data tables in each training sample.
[0019] As a further improvement to this technical solution, the specific working steps of the semantic encoding mapping method are as follows:
[0020] Step 1: Collect a large amount of business-related text data, extract basic semantic units, and remove duplicates to form a dataset containing... Vocabulary of semantic units ; for vocabulary list Each semantic unit Assign a unique numeric index Establish a mapping relationship between semantic units and numerical indexes;
[0021] Step 2: Receive Text Match the vocabulary according to the longest match principle. The longest semantic unit, split text For multiple smallest semantic units Then, by using the mapping relationship, the numerical index of each smallest semantic unit is retrieved, generating a numerical index sequence. ,in ;
[0022] Step 3: Use an embedding matrix Mapping number index sequence Numeric index in For the initial semantic vector That is, the first in the embedding matrix A vector of rows;
[0023] Step 4: Add location coding To each initial semantic vector This yields the corresponding text vector. ;
[0024] Step 5: Transfer the text The header vector after being split into multiple smallest semantic units According to the text The original order in the text is arranged sequentially to form a semantic vector. .
[0025] As a further improvement to this technical solution, the specific steps for training the mapping model are as follows:
[0026] Step 1: Receive multiple table header names, table semantic vectors corresponding to the table names, and text semantic vectors corresponding to the query text, all analyzed using the semantic encoding mapping method.
[0027] Step 1: Map the text semantic vector to the probability space of all data tables, and output the association probability between each data table and the query text: ,in The total number of data tables, This is the weight matrix. For bias, Indicates the first The probability of association between the data table and the query text;
[0028] Step 2: Set an association threshold and determine if the association threshold > association probability. Then determine the first [item] within the same training sample group. There is a mapping relationship between the data table and the query text;
[0029] Step 3: Calculate the loss between the predicted probability distribution and the true label distribution: The true labels of the training samples are one-hot vectors. ,in Indicates the first If the data table matches the query text, otherwise... ;
[0030] Calculate the predicted probability distribution Distribution of real labels Losses: ;
[0031] The total loss is: ,in The number of training sample groups, For the first The true matching label of the k-th data table in the training samples; For the first The association probability of the k-th data table in each training sample;
[0032] Step 4: Minimize the loss function using gradient descent and update the parameters. ,in, This is the set of parameters for the mapping model, containing all learnable parameters in the mapping model; For learning rate, This represents the gradient of the loss function with respect to the parameters.
[0033] As a further improvement to this technical solution, S3 outputs a query request to the database server again to obtain the data sequence corresponding to each table header; standardizes the data sequence corresponding to each table header, cross-compares the standardized data sequences, and analyzes whether the data sequences are the same. If the lengths of the two data sequences are the same and the corresponding position elements are completely matched, then the two data sequences are determined to be the same.
[0034] As a further improvement to this technical solution, if the data sequence in S3... and data sequence After determining that they are the same, the attribute vectors corresponding to multiple header names in the same data table from step S3 are received and defined as header vectors; if the data sequence and data sequence Corresponding header Table header Bring up the meter header The header vector is Table header The header vector is .
[0035] As a further improvement to this technical solution, if S3 calculates the header vector... and header vector Cosine similarity between If cosine similarity Cosine similarity Then determine the header vector. and header vector There exist table headers that are synonyms with different names.
[0036] As a further improvement to this technical solution, step S4 receives multiple table names corresponding to the knowledge graph construction in step S2, and combines these multiple table names to construct a data table set. ,in For the first Table name;
[0037] Receive the labeled header, establish the relationship between corresponding data tables through the labeled header, and construct a data table set from the table names of the data tables with the relationship. ,in For the first Table name;
[0038] Compare data table set A and data table set B, remove data tables from data table set A that do not belong to data table set B, and define the names of the remaining tables in data table set A as the entity set in the knowledge graph.
[0039] A system for constructing knowledge graphs based on relational databases includes:
[0040] The cross-departmental communication channel establishment module establishes a network communication channel with the relational database, obtains multiple data tables in each relational database, and all attributes of each data table;
[0041] The semantic mapping modeling and graph initialization module obtains matching pairs, which include query text and all attributes of multiple data tables corresponding to the query text. All attributes include table names and table header names. The semantic encoding mapping method is used to transform all attributes and query text into corresponding text semantic vectors and table semantic vectors.
[0042] The mapping model is trained by matching pairs after being converted into semantic vectors. After the mapping model is trained, the text semantic vectors are input into the mapping model, the mapping model outputs table semantic vectors, and the multiple table names corresponding to the table semantic vectors are retrieved. The table names are defined as entities in the knowledge graph.
[0043] The synonym header normalization and vector optimization module identifies synonymous headers with different names in different data tables, marks them to form labeled headers, establishes the mapping relationship between the attribute vectors corresponding to the labeled headers, and adjusts the table semantic vectors in the semantic mapping modeling and graph initialization module.
[0044] The entity set integration module receives multiple table names from the semantic mapping modeling and graph initialization module when constructing the knowledge graph to form a data table set A; it receives identical labeled table headers from the synonym table header normalization and vector optimization module, and retrieves the table names corresponding to the labeled table headers to form a data table set B; it uses data table set B to adjust data table set A, and removes entities in data table set A that do not have relationships.
[0045] In addition to the objectives, features, and advantages described above, the present invention has other objectives, features, and advantages. The invention will now be described in further detail with reference to the figures.
[0046] The beneficial effects of this invention are as follows:
[0047] Firstly, the system obtains matching pairs containing the query text and all attributes of the corresponding data tables. These matching pairs are then used as training samples to further train the mapping model. By learning the deep association between the query text and the data table attributes, the mapping model enables users to construct table names corresponding to the query text after inputting query text into the system. Then, a knowledge graph is constructed based on the table names, allowing users to efficiently obtain related data that highly matches their query needs and avoiding query bias or data omissions caused by semantic confusion of table names.
[0048] Secondly, it is further considered that, before training the mapping model, the conventional method is only based on the text semantic vectors and table semantic vectors corresponding to the data table and query text. However, this invention can identify the existence of table headers with the same name but different names in different data tables and adjust the corresponding table semantic vectors. This allows the mapping model to break through the limitations of surface text features during the training process, accurately capture the core business semantic associations behind the table headers, thereby improving the mapping model's ability to identify tables with the same name but different names and ensuring that the output table names are highly consistent with the query requirements at the business logic level.
[0049] Thirdly, in digital government, since matching pairs come from heterogeneous data sources from multiple departments, they are affected by the independence of departmental business, differences in naming habits, and errors in manual annotation. If there are deviations in the matching pairs, it will lead to the problem that there are entities in the knowledge graph that should be related but are split into unrelated entities during the process of building the knowledge graph based on the table names. This invention introduces synonymous table headers with different names to further adjust the entities in the knowledge graph, so that the entities in the knowledge graph can accurately reflect the real business collaboration relationship of cross-departmental data tables, eliminate entity redundancy and semantic fragmentation, and ultimately improve the structural rationality and data integration value of the knowledge graph. Attached Figure Description
[0050] Figure 1 This is a schematic diagram illustrating the training principle of the mapping model in this invention;
[0051] Figure 2 This is a flowchart illustrating the working principle of the mapping model of the present invention;
[0052] Figure 3 This is a schematic diagram illustrating the working principle of the synonym header judgment in this invention;
[0053] Figure 4 This is a schematic diagram of the knowledge graph in this invention.
[0054] The meanings of the labels in the diagram are as follows:
[0055] 1. Cross-departmental communication channel establishment module; 2. Semantic mapping modeling and graph initial construction module; 3. Synonym header normalization and vector optimization module; 4. Entity set integration module. Detailed Implementation
[0056] The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0057] refer to Figures 1-4 As shown, a method for constructing a knowledge graph based on a relational database includes the following steps:
[0058] S1. Obtain the network address, port number, and authentication information (username and password) of the relational database; based on the network address, port number, and authentication information, output a connection request to the database server. After the database server verifies the identity, it establishes a network communication channel with the relational database, thereby enabling this system to establish connections with relational databases of multiple different departments.
[0059] Although the data tables in the database servers of different departments have been synchronously obtained through the network communication channel in step S1, and the technical interconnection of cross-departmental data has been achieved, in the actual use of the existing digital government system, the interaction mode of user input query text → database server analysis and retrieval of multiple suitable data tables for user selection is usually adopted.
[0060] When users want to query corporate social security contributions, they often encounter difficulties due to unfamiliarity with the table structure design of various departmental databases (not knowing that the query corresponds to "Corporate Social Security Contribution Details Table" rather than "Corporate Social Security Account Registration Table" or "Corporate Social Security Base Verification Table") and a lack of understanding of the standardized classification logic of government data (unable to distinguish that "Corporate Social Security Contribution" belongs to different data tables than "Individual Social Security Contribution" and "Corporate Social Security Account Opening"). This leads to problems such as vague query text (e.g., only entering "Check Corporate Social Security") and missing keywords (e.g., querying "Individual Out-of-Town Medical Insurance Reimbursement" without mentioning "out-of-town"). Consequently, the database server retrieves a large number of irrelevant tables (e.g., querying "Corporate Social Security Contribution" but retrieving tables such as "Corporate Social Security Account Opening" and "Individual Social Security Contribution").
[0061] In response to the aforementioned situation, where users need to repeatedly filter through multiple tables to find the company's social security payment details, this invention addresses the issue of users being unable to retrieve matching data tables after entering their query text. In step S2, the table names scattered across various departmental relational databases are transformed into entities in a knowledge graph. Subsequently, when users enter query text, they do not need to understand complex database table structures or standardized terminology. They can rely on the relationships between data table entities in the knowledge graph to automatically match and accurately retrieve all data tables corresponding to their query needs from different departments. This avoids problems such as inaccurate query text and interference from irrelevant tables due to user cognitive limitations. The specific steps are as follows:
[0062] S2.1. Query the matching pairs of query text and data table in each database server through network communication in step S1, and use multiple sets of matching pairs as training samples. Each set of training samples includes at least one data table and one query text.
[0063] Specifically: The matching pair is the data table that supports each business. The working principle of the matching pair formation in the database server is as follows: the user inputs query text, the relational database retrieves multiple data tables that match the query text for the user to select. Before switching to the next query text, the data table selected by the user and the query text are the matching pair.
[0064] Furthermore, to avoid adaptation discrepancies caused by insufficient automatic database adaptation logic or changes in business scenarios, the existing database system also introduces a feedback mechanism. If the selected data table does not match the query text, the user can provide feedback, and the feedback data table will then be deleted, ultimately forming an accurate matching pair. A specific example is as follows:
[0065] When users query enterprise social security contributions, the system simultaneously recommends data tables such as enterprise social security contribution details table, enterprise social security contribution summary table, enterprise social security base verification table, and individual social security contribution record table.
[0066] If a user selects only the Enterprise Social Security Contribution Details Table, then the Enterprise Social Security Contribution - Enterprise Social Security Contribution Details Table is a matching pair; if both the Enterprise Social Security Contribution Details Table and the Enterprise Social Security Base Verification Table are selected, then the Enterprise Social Security Contribution - Enterprise Social Security Contribution Details Table and the Enterprise Social Security Base Verification Table are matching pairs for Individual Medical Insurance Reimbursement Details.
[0067] S2.2. Convert the matching pairs of the query text and the corresponding data table into corresponding vectors, and output the query request to the database server again through the network channel to query all attributes of each data table in the database server. The attributes include, but are not limited to, all table header names and table names. For example, if the matching pair is "Enterprise Social Security Contribution - Enterprise Social Security Contribution Details Table", the query will obtain the table name "Enterprise Social Security Contribution Details Table", as well as the table header names "Contributing Unit Number", "Contribution Period", "Social Security Type", "Contribution Amount", "Contribution Status", "Application Date", and other attributes.
[0068] The semantic encoding mapping method is used to convert multiple table header names in each training sample into table semantic vectors and query text into text semantic vectors. The mapping model is trained using table semantic vectors and text semantic vectors. The mapping model is used to learn the relationship between query text and multiple data tables in each training sample.
[0069] S2.3 After the mapping model is trained, the text semantic vector is input into the mapping model, and the mapping model outputs the table semantic vector. The model then retrieves the names of multiple tables corresponding to the table semantic vectors and defines the table names as entities in the knowledge graph, thereby completing the construction of the knowledge graph. This solves the pain point of government data being scattered and unclearly related across different departments. Multiple data tables scattered across various relational databases are semantically linked through the knowledge graph, clearly defining the business relationships between multiple data tables. This allows users to directly retrieve multiple data tables from different departments that precisely correspond to the query text by inputting query text, achieving efficient cross-departmental data linkage and accurate retrieval, and further avoiding interference from irrelevant tables.
[0070] The specific working steps of the semantic encoding mapping method in step S2.2 are as follows:
[0071] Step 1: Collect a large amount of business-related text data (such as table header names and query text), extract basic semantic units such as characters, words, and sub-words, and then remove duplicates to form a data structure containing... A vocabulary of semantic units (which can be characters, words, subwords, etc.) ; for vocabulary list Each semantic unit Assign a unique numeric index Establish a mapping relationship between semantic units and numerical indexes;
[0072] Step 2: Receive Text (e.g., table header name, query text), match the vocabulary list according to the longest match principle. The longest semantic unit, thus splitting the text For multiple smallest semantic units (For example, splitting it into "user" and "ID number"), then retrieving the numerical index of each smallest semantic unit through the mapping relationship to generate a numerical index sequence. ,in ;
[0073] Step 3: Use dimension as ( For the vocabulary list The number of internal basic units, Embedding matrix (with vector dimension) Mapping number index sequence Numeric index in For the initial semantic vector That is, the first in the embedding matrix A vector of rows;
[0074] Embedding matrix Used to index a sequence of numbers Converting it into semantic vector form allows computers to compute semantic relationships in a continuous space, for example:
[0075] Embedding matrix:
[0076] ;
[0077] in, For the first semantic units The corresponding semantic vectors are represented by each row of the matrix as a semantic representation of a single unit.
[0078] Taking enterprise social security payment inquiry in government service scenarios as an example:
[0079] set up Vector dimension Embedding matrix:
[0080] ;
[0081] The enterprise social security contribution is split into units “Enterprise (1)”, “Social Security (2)”, and “Contribution (3)”, and the index sequence is as follows. Its corresponding semantic vector is:
[0082] ;
[0083] Step 4: To preserve the text Add positional encoding to the sequence information of semantic units. To each initial semantic vector This yields the corresponding text vector. Position encoding No. The values of each dimension are:
[0084] ;
[0085] in, The position index of the semantic unit in the sequence (starting from 1); Index of the vector dimension (from 1 to d); The dimension of the semantic vector (consistent with the column dimension of the embedding matrix E); This is the scaling factor;
[0086] Step 5: Transfer the text The header vector after being split into multiple smallest semantic units According to the text The original order in the text is arranged sequentially to form a semantic vector. .
[0087] The steps for training the mapping model in step S2.2 are as follows:
[0088] Step 1: Receive the semantic vectors corresponding to multiple table header names and table names, as well as the semantic vectors corresponding to the query text, obtained by analyzing the semantic encoding mapping method. Mapping text semantic vectors The algorithm extends to the probability space of semantic vectors in all tables, outputting the association probability of each text semantic vector to all table semantic vectors. This measure the degree of matching between the query text and the data tables, yielding the association probability. The specific working principle is as follows:
[0089] ;
[0090] in:
[0091] This represents the total number of data tables.
[0092] This is a weight matrix used to perform a linear transformation on the text semantic vector, capturing the semantic association weights between the query text and each data table;
[0093] This is used as a bias to adjust the results of the linear transformation, enhancing the adaptability of the mapping model to different scenarios.
[0094] Used for linear transformation of text semantic vectors This maps the data from d-dimensional space to K-dimensional space (corresponding to the semantic space of K data tables).
[0095] The normalized activation function is used to convert the result of a linear transformation into a probability distribution (where the sum of all elements is 1), thus making the text semantic vector... Each element in the table represents the probability of association between the k-th data table and the query text. , specific ;
[0096] Step 2: Introduce an association threshold as a criterion; if the association probability between the text semantic vector and the data table... >Association threshold, then determine the first There is a mapping relationship between the data table and the query text;
[0097] Step 3: Calculate the loss between the predicted probability distribution and the true label distribution: The true labels of the training samples are one-hot vectors. ,in Indicates the first The data table matches the current query text exactly; otherwise... ;
[0098] Calculate the predicted probability distribution Distribution of real labels The loss is: ,in The number of training sample groups, For the first The true matching label of the k-th data table in the training samples; For the first The association probability of the k-th data table in each training sample;
[0099] Step 4: Minimize the loss function using gradient descent (such as the Adam optimizer) and update the parameters. ,in, This is the set of parameters for the mapping model, containing all learnable parameters in the mapping model, such as weight matrix, bias, etc. For learning rate, This represents the gradient of the loss function with respect to the parameters.
[0100] This invention takes into account that, in digital government, due to the long-standing independence of business operations and autonomy in data construction among various departments, early data systems were mostly closed-loop models within departments. Data standards and header naming rules were formulated by each department according to its own business habits (for example, the social security bureau uses "unit code" to identify enterprises in the enterprise information table, while the tax bureau retains "taxpayer identification number" in the same integrated enterprise information table, both of which actually point to the unique identity of the enterprise), resulting in multiple synonymous header names within the same data table;
[0101] In step S2.2, when training the mapping model, the mapping model learns the relationship between the query text and multiple data tables based on the surface text features of the query text and the data tables (including the keywords of the query text, the name of the data table, and the literal information of the table header text). Although it can learn common text-table correspondence patterns through a large number of labeled samples (for example, "tax clearance certificate" is often associated with "tax clearance certificate application form" and "enterprise tax status table"), and optimize the ability to capture patterns by adjusting the mapping model parameters, the mapping model can output reasonable association results in most common scenarios.
[0102] However, in digital government scenarios, the synonymy of table header names is often strongly tied to specific business rules (e.g., both "Unit Code" and "Taxpayer Identification Number" are used to uniquely identify enterprises, and this association stems from cross-departmental collaborative business norms). If the training data for the mapping model lacks explicit annotations of the business rules corresponding to synonymous table header names (e.g., it is not clearly stated that both refer to the same entity), the mapping model will be unable to learn the hidden business logic from the data and can only rely on textual features to make judgments. Consequently, the mapping model will only distinguish semantics based on the textual differences in the table headers during learning, failing to deeply understand the consistent business meaning and data references behind them. This will lead to misjudging table headers that should be synonymous as having different semantics, ultimately resulting in semantic confusion of table headers (not being able to distinguish that "Unit Code" and "Taxpayer Identification Number" actually refer to the same thing) and matching errors (situations where "Unit Code" is mentioned in the query). To avoid such situations:
[0103] S3. Send the query request to the database server again to obtain the data sequence corresponding to each table header; standardize the data sequence corresponding to each table header, and then cross-compare the standardized data sequences to analyze whether the data sequences are the same. Specifically: if the lengths of the two data sequences are the same and the corresponding elements are completely matched, then the two data sequences are considered the same; receive the standardized data sequences. Data sequence If the data sequence Data sequence Then determine the data sequence and data sequence The same applies; the specific expression is: ,in , Data sequences and data sequence The number of elements;
[0104] Determine the data sequence and data sequence If they are identical, receive the attribute vectors corresponding to multiple header names in the same data table and define them as header vectors; if the data sequence and data sequence Corresponding header Table header Bring up the meter header The header vector is Table header The header vector is ;
[0105] Calculate the header vector and header vector Cosine similarity between If cosine similarity Cosine similarity This indicates that the header vector and header vector While there are differences, they are not entirely contradictory. Therefore, the two table headers are determined to be synonymous but different names. These synonymous but different names are then labeled to form labeled headers, and a mapping relationship is established between them. This allows for the standardization of semantic representations of synonymous headers during the training of the mapping model, preventing the model from learning incorrect associations due to differences in header names. It eliminates semantic ambiguity caused by synonymous but different header names, ensuring consistency in the mapping model's understanding of header semantics. This avoids semantic misjudgments due to textual differences, enabling the mapping model to more accurately capture the association between query text and data tables, thus improving matching accuracy.
[0106] Furthermore, during the analysis of synonymous table names in step S3, in the context of digital government, although the business of each department is independent, the management logic for the same type of entity is collaborative (such as the "Social Security Unit Information Table" of the Social Security Bureau and the "Taxpayer Enterprise Information Table" of the Tax Bureau, both of which are based on the business of enterprise identity identification). Therefore, there is usually a relationship between synonymous table names.
[0107] In step S2, multiple table names corresponding to the semantic vectors of the output tables from the mapping model are defined as entities in the knowledge graph. Since the mapping model relies on query text-data table matching pairs as training samples, if there is a bias in the matching pairs (e.g., irrelevant tables are mistakenly labeled as matching items; because the user selects multiple different data tables when entering query text, but the data tables are not the ones the user needs, and the user does not provide further feedback, resulting in a biased matching pair), the mapping model will learn incorrect association rules. This will cause tables with no business relevance to the target entity to be mixed into the table names corresponding to the output table semantic vectors. Consequently, entities with no association will appear when constructing the knowledge graph in step S2. Therefore, to avoid the above situation:
[0108] S4. Receive the names of multiple tables used in step S2 when constructing the knowledge graph, and combine these multiple table names into a data table set. ,in For the first Table name;
[0109] Receive the labeled header, establish the relationship between corresponding data tables through the labeled header, and construct a data table set from the table names of the data tables with the relationship. ,in For the first Table name;
[0110] Compare data set A and data set B, remove data tables from data set A that are not in data set B, and define the remaining tables in data set A as entity sets in the knowledge graph. This allows for the precise removal of entities from data table set A that have no relation to the entities being adjusted when constructing the knowledge graph. This ensures that all entities in the knowledge graph are built based on real business relationships, thereby improving the accuracy of cross-departmental table associations in the digital government scenario.
[0111] A system for constructing knowledge graphs based on relational databases includes:
[0112] Module 1 for establishing cross-departmental communication channels establishes a network communication channel with a relational database, retrieves multiple data tables from each relational database, and all attributes of each data table;
[0113] Semantic mapping modeling and graph initial construction module 2: Obtain matching pairs, which include query text and all attributes of multiple data tables corresponding to the query text. All attributes include table name and table header name; use semantic encoding mapping method to transform all attributes and query text into corresponding text semantic vectors and table semantic vectors.
[0114] The mapping model is trained by matching pairs after being converted into semantic vectors. After the mapping model is trained, the text semantic vectors are input into the mapping model, the mapping model outputs table semantic vectors, and the multiple table names corresponding to the table semantic vectors are retrieved. The table names are defined as entities in the knowledge graph.
[0115] The synonym header normalization and vector optimization module 3 identifies synonymous headers with different names in different data tables, marks them to form labeled headers, establishes the mapping relationship between the attribute vectors corresponding to the labeled headers, and adjusts the table semantic vectors in the semantic mapping modeling and graph initial construction module 2.
[0116] The entity set integration module 4 receives multiple table names from the semantic mapping modeling and graph initialization module 2 when constructing the knowledge graph to form a data table set A; it receives the same labeled table headers from the synonym table header normalization and vector optimization module 3, and retrieves the table names corresponding to the labeled table headers to form a data table set B; it uses data table set B to adjust data table set A, and removes entities in data table set A that do not have relationships.
[0117] The foregoing has shown and described the basic principles, main features, and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited to the above embodiments. The embodiments and descriptions in the specification are merely preferred examples and are not intended to limit the invention. Various changes and modifications can be made to the invention without departing from its spirit and scope, and all such changes and modifications fall within the scope of the present invention as claimed. The scope of protection of the present invention is defined by the appended claims and their equivalents.
Claims
1. A method for constructing a knowledge graph based on a relational database, characterized in that, Includes the following steps: S1. Establish a network communication channel with the relational database to obtain multiple data tables in each relational database, as well as all attributes of each data table; S2. Obtain matching pairs, which include query text and all attributes of multiple data tables corresponding to the query text. All attributes include table names and table header names. Use semantic encoding mapping to convert all attributes and query text into corresponding text semantic vectors and table semantic vectors. The mapping model is trained by matching pairs after being converted into semantic vectors. After the mapping model is trained, the text semantic vectors are input into the mapping model, the mapping model outputs table semantic vectors, and the multiple table names corresponding to the table semantic vectors are retrieved. The table names are defined as entities in the knowledge graph. The specific steps for training the mapping model are as follows: Step 1: Receive multiple table header names, table semantic vectors corresponding to the table names, and text semantic vectors corresponding to the query text, all analyzed using the semantic encoding mapping method. Step 1: Map the text semantic vector to the probability space of all data tables, and output the association probability between each data table and the query text: ,in The total number of data tables, This is the weight matrix. For bias, Indicates the first The probability of association between the data table and the query text; Step 2: Set an association threshold and determine if the association threshold > association probability. Then determine the first one within the same training sample group. There is a mapping relationship between the data table and the query text; Step 3: Calculate the loss between the predicted probability distribution and the true label distribution: The true labels of the training samples are one-hot vectors. ,in Indicates the first If the data table matches the query text, otherwise... ; Calculate the predicted probability distribution Distribution of real labels Losses: ; The total loss is: ,in The number of training sample groups, For the first The true matching label of the k-th data table in the training samples; For the first The association probability of the k-th data table in each training sample; Step 4: Minimize the loss function using gradient descent and update the parameters. ,in, This is the set of parameters for the mapping model, containing all learnable parameters in the mapping model; For learning rate, This represents the gradient of the loss function with respect to the parameters. S3. Determine the table headers with the same meaning but different names in different data tables, mark the table headers with the same meaning but different names to form marked table headers, establish the mapping relationship between the attribute vectors corresponding to the marked table headers, and adjust the table semantic vector in step S2. S4. Receive multiple table names from the knowledge graph construction in step S2 to form a data table set A; receive the same labeled table headers from step S3, retrieve the table names corresponding to the labeled table headers to form a data table set B; use data table set B to adjust data table set A, and remove entities in data table set A that do not have relationships.
2. The method for constructing a knowledge graph based on a relational database according to claim 1, characterized in that: In step S1, the network address, port number, and authentication information of the relational database are first obtained; a connection request with the authentication information is sent to the database server based on the network address, port number, and authentication information. After the database server verifies the identity, a network communication channel is established between the database and the relational database.
3. The method for constructing a knowledge graph based on a relational database according to claim 1, characterized in that: Each training sample in S2 includes at least one data table and one query text. The query request is sent to the database server through the network channel established in step S1 to query all attributes of each data table in the database server, including all table header names and table names; A semantic encoding mapping method is used to convert multiple table header names in each training sample into table semantic vectors and query text into text semantic vectors. The mapping model is trained using table semantic vectors and text semantic vectors. The mapping model is used to learn the relationship between query text and multiple data tables in each training sample.
4. The method for constructing a knowledge graph based on a relational database according to claim 3, characterized in that: The specific working steps of the semantic encoding mapping method are as follows: Step 1: Collect a large amount of business-related text data, extract basic semantic units, and remove duplicates to form a dataset containing... Vocabulary of semantic units ; for vocabulary list Each semantic unit Assign a unique numeric index Establish a mapping relationship between semantic units and numerical indexes; Step 2: Receive Text Match the vocabulary according to the longest match principle. The longest semantic unit, split text For multiple smallest semantic units Then, by using the mapping relationship, the numerical index of each smallest semantic unit is retrieved, generating a numerical index sequence. ,in ; Step 3: Use an embedding matrix Mapping number index sequence Numeric index in For the initial semantic vector That is, the first in the embedding matrix A vector of rows; Step 4: Add location coding To each initial semantic vector This yields the corresponding text vector. ; Step 5: Transfer the text The header vector after being split into multiple smallest semantic units According to the text The original order in the text is arranged sequentially to form a semantic vector. .
5. The method for constructing a knowledge graph based on a relational database according to claim 1, characterized in that: S3 outputs a query request to the database server again to obtain the data sequence corresponding to each table header; it standardizes the data sequence corresponding to each table header, cross-compares the standardized data sequences, and analyzes whether the data sequences are the same. If the lengths of the two data sequences are the same and the corresponding position elements are completely matched, then the two data sequences are determined to be the same.
6. The method for constructing a knowledge graph based on a relational database according to claim 5, characterized in that: If the data sequence in S3 and data sequence After determining that they are the same, the attribute vectors corresponding to multiple header names in the same data table from step S3 are received and defined as header vectors; if the data sequence and data sequence Corresponding header Table header Bring up the meter header The header vector is Table header The header vector is .
7. The method for constructing a knowledge graph based on a relational database according to claim 6, characterized in that: If S3 calculates the header vector and header vector Cosine similarity between If cosine similarity Cosine similarity Then determine the header vector. and header vector There exist table headers that are synonyms with different names.
8. The method for constructing a knowledge graph based on a relational database according to claim 1, characterized in that: In step S4, multiple table names corresponding to the knowledge graph construction in step S2 are received, and these multiple table names are used to construct a data table set. ,in For the first Table name; Receive the labeled header, establish the relationship between corresponding data tables through the labeled header, and construct a data table set from the table names of the data tables with the relationship. ,in For the first Table name; Compare data table set A and data table set B, remove data tables from data table set A that do not belong to data table set B, and define the names of the remaining tables in data table set A as the entity set in the knowledge graph.
9. A system for constructing a knowledge graph based on a relational database, applied to the method for constructing a knowledge graph based on a relational database as described in any one of claims 1-8, characterized in that, include: Cross-departmental communication channel establishment module (1) establishes a network communication channel with the relational database, obtains multiple data tables in each relational database, and all attributes of each data table; Semantic mapping modeling and graph initial construction module (2) obtain matching pairs, which include query text and all attributes of multiple data tables corresponding to the query text. All attributes include table name and table header name; use semantic encoding mapping method to convert all attributes and query text into corresponding text semantic vectors and table semantic vectors. The mapping model is trained by matching pairs after being converted into semantic vectors. After the mapping model is trained, the text semantic vectors are input into the mapping model, the mapping model outputs table semantic vectors, and the multiple table names corresponding to the table semantic vectors are retrieved. The table names are defined as entities in the knowledge graph. The synonym header normalization and vector optimization module (3) judges the synonyms with different names in different data tables, marks the synonyms with different names to form marked headers, and establishes the mapping relationship between the attribute vectors corresponding to the marked headers, and adjusts the table semantic vectors in the semantic mapping modeling and graph initial construction module (2). The entity set integration module (4) receives multiple table names from the semantic mapping modeling and graph initialization module (2) when constructing the knowledge graph to form a data table set A; it receives the same labeled table header from the synonym table header normalization and vector optimization module (3), and retrieves the table name corresponding to the labeled table header to form a data table set B; it uses the data table set B to adjust the data table set A and removes entities that do not have a relationship in the data table set A.