Method for automatically constructing virtual knowledge graph driven by large language model based on mapping mode
Through the method based on mapping mode and large language model, the virtual knowledge graph is automatically constructed, which solves the mapping accuracy and degree of automation of complex data sources, and realizes efficient ontology expansion and automatic generation of mapping rules, improving the robustness and interpretability of virtual knowledge graphs.
Patent Information
- Application Number
- CN202510590378.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-08
- Publication Date
- 2025-08-19
- Estimated Expiration
- 2045-05-08
AI Technical Summary
Existing virtual knowledge graph construction methods are difficult to achieve reliable automated mapping when dealing with complex data sources, especially when facing the semantic differences and alignment ambiguity between complex and diverse mapping structures and database patterns and ontology concepts, the degree of automation and accuracy are insufficient.
Using a large language model-driven method based on mapping mode, through graph structure construction, mapping mode extraction, semantic coding and generative large language model, the alignment and expansion of the database table structure and the ontology vocabulary are realized, and the virtual knowledge graph is constructed.
It improves the degree of automation and mapping accuracy of virtual knowledge graphs, enhances adaptability to complex scenarios, reduces manual dependence and implementation costs, and improves mapping accuracy under naming ambiguity and structural differences.
Smart Images

Figure CN120509468A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of virtual knowledge graphs, and specifically relates to a method for automatically constructing a virtual knowledge graph driven by a large language model based on a mapping pattern. Background Art
[0002] The core of virtual knowledge graphs lies in building a unified semantic abstraction layer. This layer shields the complexity of the underlying data schema through domain ontologies and utilizes declarative mapping rules to transparently translate SPARQL queries into native data source queries. A key virtualization technology is the SPARQL-to-SQL conversion mechanism. Through semantic mapping and query rewriting algorithms, this mechanism converts the SPARQL query language of the RDF-based knowledge graph into the SQL standard query language of relational databases, enabling semantic access to heterogeneous data sources. This "data-in-place, semantics-first" access mechanism significantly reduces the understanding of the physical storage structure of data for domain experts, making virtual knowledge graphs highly efficient in cross-source data retrieval and knowledge discovery. It has been widely applied in various fields, including petroleum, energy, healthcare, archaeology, surveying and mapping, smart cities, and maritime security. Driven by multi-stakeholder collaboration and technological innovation, virtual knowledge graph technology has shown initial success in integrating heterogeneous data sources and answering knowledge questions. Although existing methods can reduce the construction cost of virtual knowledge graphs to a certain extent, they still have limitations when dealing with complex data sources: (1) The mapping generation mechanism of existing methods is usually based on simple rules and has difficulty in handling complex and diverse mapping structures; (2) Due to the semantic differences and alignment ambiguities between database schemas and ontology concepts, existing methods cannot achieve reliable and automated mapping.
[0003] In order to realize the construction of virtual knowledge graphs in complex scenarios, this work proposes an automatic construction method of virtual knowledge graphs driven by a large language model based on mapping patterns. First, the extraction of mapping patterns for database table structures and constraints is studied. The database is constructed into a graph structure according to its constraints (primary key constraints, foreign key constraints). The subgraph query scheme is constructed according to the characteristics of the mapping pattern, and the mapping pattern is extracted through the subgraph matching method. Secondly, the semantic alignment of the database table structure and the ontology vocabulary is studied. The semantic information in the database and ontology structure is first encoded into feature vectors, and coarse-grained retrieval and matching at the semantic level are performed. Then, a large language model is used for fine-grained matching to construct the alignment relationship between the database structure and the ontology structure. Finally, the graph construction based on the mapping pattern and the semantic alignment results is studied. The construction strategy is designed according to the characteristics of the mapping pattern, and the semantic alignment results are used to construct the virtual knowledge graph. Summary of the Invention
[0004] In order to address the deficiencies in the prior art, the purpose of the present invention is to provide a method for automatically constructing a virtual knowledge graph driven by a large language model based on a mapping pattern.
[0005] The present invention comprises the following steps:
[0006] Step 1: Extract the database table structure metadata and constraint relationships, and convert the database schema into a graph structure based on the RDF standard;
[0007] Given that database table structures and their constraints can be naturally expressed through graph modeling, this method aims to transform mapping pattern extraction into a topological subgraph matching problem driven by topological features. This method transforms mapping pattern extraction into a topological subgraph matching problem guided by conceptual models. The process can be divided into two stages:
[0008] Database structure extraction: Connect to the target database through the JDBC interface, parse and extract table structure metadata (including table name, attribute list) and database constraint relationships (including primary key, foreign key, unique constraint and check constraint).
[0009] Graph structure construction: Construct a database schema graph structure G based on the RDF standard according to the database table structure metadata and constraint relationships. DB =(V,E), where the vertex set V = V t ∪V c By table node V t and column node V c The structure represents the table entity and column entity in the database respectively, and the edge set E=E p ∪E f ∪E c Contains three different edge types: primary key relationship edge Used to mark the relationship between the table and its primary key column, foreign key edge Used to represent the referential constraints between cross-table columns, column member edges Then associate the table with its non-primary key columns.
[0010] Step 2: Convert the mapping pattern into a query statement that conforms to the SPARQL syntax, query the RDF graph structure corresponding to the database pattern, and obtain the extraction results of each mapping pattern.
[0011] Mapping Pattern is a construction scheme used to summarize common database structures and corresponding mappings. A specific mapping pattern consists of a four-tuple Composition, of which is the target conceptual model (e.g. expressed as an ER model fragment), yes A possible database schema expression is, Represents a set of mappings, It is a set of ontological axioms.
[0012] Mapping pattern to SPARQL query: This method converts the target conceptual model of the mapping pattern p into The entities, attributes and relationships in the database are based on the RDF standard database schema graph structure G DB , construct the corresponding SPARQL query statement. The specific construction rules are: The entities in G DB Table node V in t Alignment, The properties in V c Column nodes in align, The primary key in E p The edges of align, The foreign key in E f The edges in the .
[0013] Execute the query: DB Execute SPARQL query statements on the mapping pattern to obtain the mapping pattern extraction results. By parsing the mapping pattern and designing the corresponding extraction plan, all extraction results are merged into the final result set:
[0014]
[0015] Where S represents the database schema, and D represents a database instance that satisfies the constraints of S. Represents a set of recognizable mapping patterns in a dataset structure, represents the initial ontology in the process of constructing the virtual knowledge graph, ∪ represents the set union operation, For all mappings in database instance D, express All corresponding ontological axioms.
[0016] Step 3: Based on the semantic encoding model and the generative large language model, align the database table structure metadata and constraint relationships into the ontology vocabulary, and obtain the database-to-ontology alignment results and alignment confidence. This process can be divided into two stages:
[0017] Coarse-grained alignment: Using a deep semantic encoding model, the database metadata Σ (table name, column name) is aligned with the ontology vocabulary. (class, object attribute, numerical attribute) is embedded in the text representation, and a candidate mapping set is generated through the similarity measurement of high-dimensional vector space and K-nearest neighbor retrieval strategy:
[0018]
[0019] Where R is the alignment candidate between database metadata and ontology, and each element r∈R is a tuple By database element e db and ontology element set composition.
[0020] Fine-grained alignment: Use a generative large language model to further perform semantic disambiguation and logical constraint verification on the candidate set to ensure that the candidate mappings are semantically consistent and comply with logical constraints:
[0021] A=Matcher(R)
[0022] Where A represents the alignment result set, and each element a∈A is a triple (e db ,e on ,d), by the database element e db , ontology elements aligned with database elements e on and the degree of alignment d, which is divided into three levels: high, medium, and low. This stage accurately confirms the correspondence between the database model and the knowledge ontology, and evaluates the degree of alignment between each database element and its corresponding ontology element.
[0023] Step 4: Based on the mapping pattern extraction results and the database-to-ontology alignment results, ontology expansion and virtual knowledge graph mapping construction are performed based on the alignment confidence.
[0024] For high-confidence alignment results, a mapping relationship between the database schema and the target ontology is directly established. For medium-confidence alignment results, a hierarchical ontology refinement strategy is adopted: based on the principle of minimum commitment in ontology modeling, the ontology expression granularity is expanded by adding domain subclasses or sub-attributes while maintaining core semantic consistency. For low-confidence alignment results, new ontology classes or attributes are directly created that are strongly associated with the source database schema features.
[0025]
[0026] Namer is a namer based on a generative large language model, a=(e db ,e on ,d)∈A is the alignment result and confidence of the database to the ontology. In the process of processing the alignment results with medium and low confidence, the database elements cannot be directly aligned with the ontology elements. In order to map the internal data of the database to the ontology as much as possible while ensuring the correctness of the alignment, the ontology structure will be expanded according to the semantic information of the corresponding database elements and related ontology elements. In the ontology structure expansion, different types of appropriate names will be constructed according to the corresponding scenarios, such as class names are nouns and attribute names are verbs. The expanded ontology As the final ontology structure of the virtual knowledge graph. Finally, according to the final ontology Alignment result set A and mapping pattern extraction results As well as the mapping construction scheme of each mapping mode, construct the virtual knowledge graph mapping.
[0027] An electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the method for automatically constructing a virtual knowledge graph driven by a large language model based on a mapping pattern is implemented.
[0028] A computer-readable storage medium stores computer instructions, which, when executed by a processor, implement the method for automatically constructing a virtual knowledge graph driven by a large language model based on a mapping pattern.
[0029] The beneficial effects of the present invention are that, compared with the prior art, the present invention:
[0030] 1. Automated ontology expansion and mapping construction: Based on the large language model and mapping mode, a framework for automatic expansion of virtual knowledge graph ontology and automatic generation of mapping rules is implemented, significantly improving the degree of automation.
[0031] 2. Improving mapping accuracy in complex scenarios: Leveraging the semantic understanding capabilities of large language models, this approach significantly improves mapping accuracy in complex situations such as naming ambiguity and structural differences. It is particularly effective in object attribute and n:1 mapping scenarios, outperforming existing methods.
[0032] 3. Enhanced adaptability to incomplete ontologies: Based on the data source model, the method can automatically complete and generate missing ontology concepts and attributes using a large language model, effectively addressing the problem of incomplete initial ontology and improving the robustness of the method.
[0033] 4. Reduce manual dependency and costs: By automating key construction steps (such as matching decisions and naming generation), the dependency on domain experts and manual configuration is greatly reduced, shortening the construction cycle and reducing implementation costs.
[0034] 5. Standardization and interpretability: Combined with the mapping pattern to guide the application of large language models, the generated ontology extensions and mapping rules are more in line with established specifications and have better structure and interpretability. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 Flowchart for ontology expansion and virtual knowledge graph construction in the present invention. DETAILED DESCRIPTION
[0036] The present application will be further described below in conjunction with the accompanying drawings. The following embodiments are only used to more clearly illustrate the technical solutions of the present invention and are not intended to limit the scope of protection of the present application.
[0037] Example 1: The method for automatically constructing a virtual knowledge graph driven by a large language model based on a mapping pattern of the present invention includes the following steps:
[0038] Step 1: Extract the database table structure metadata and constraint relationships, and convert the database schema into a graph structure based on the RDF standard;
[0039] Given that database table structures and their constraints can be naturally expressed through graph modeling, this method aims to transform mapping pattern extraction into a topological subgraph matching problem driven by topological features. This method transforms mapping pattern extraction into a topological subgraph matching problem guided by conceptual models. The process can be divided into two stages:
[0040] Database structure extraction: Connect to the target database through the JDBC interface, parse and extract table structure metadata (including table name, attribute list) and database constraint relationships (including primary key, foreign key, unique constraint and check constraint).
[0041] Graph structure construction: Construct a database schema graph structure G based on the RDF standard according to the database table structure metadata and constraint relationships. DB =(V,E), where the vertex set V = V t ∪V c By table node V t and column node V c The structure represents the table entity and column entity in the database respectively, and the edge set E=E p ∪E f ∪E c Contains three different edge types: primary key relationship edge Used to mark the relationship between the table and its primary key column, foreign key edge Used to represent the referential constraints between cross-table columns, column member edges Then associate the table with its non-primary key columns.
[0042] Step 2: Convert the mapping pattern into a query statement that conforms to the SPARQL syntax, query the RDF graph structure corresponding to the database pattern, and obtain the extraction results of each mapping pattern.
[0043] Mapping Pattern is a construction scheme used to summarize common database structures and corresponding mappings. A specific mapping pattern consists of a four-tuple Composition, of which is the target conceptual model (e.g. expressed as an ER model fragment), yes A possible database schema expression is, Represents a set of mappings, It is a set of ontological axioms.
[0044] Mapping pattern to SPARQL query: This method converts the target conceptual model of the mapping pattern p into The entities, attributes and relationships in the database are based on the RDF standard database schema graph structure G DB , construct the corresponding SPARQL query statement. The specific construction rules are: The entities in G DB Table node V in t Alignment, The properties in V c Column nodes in align, The primary key in E p The edges of align, The foreign key in E f The edges in the .
[0045] Execute the query: DB Execute SPARQL query statements on the mapping pattern to obtain the mapping pattern extraction results. By parsing the mapping pattern and designing the corresponding extraction plan, all extraction results are merged into the final result set:
[0046]
[0047] Where S represents the database schema, and D represents a database instance that satisfies the constraints of S. Represents a set of recognizable mapping patterns in a dataset structure, represents the initial ontology in the process of constructing the virtual knowledge graph, ∪ represents the set union operation, For all mappings in database instance D, express All corresponding ontological axioms.
[0048] Step 3: Based on the semantic encoding model and the generative large language model, align the database table structure metadata and constraint relationships into the ontology vocabulary, and obtain the database-to-ontology alignment results and alignment confidence. This process can be divided into two stages:
[0049] Coarse-grained alignment: Using a deep semantic encoding model, the database metadata Σ (table name, column name) is aligned with the ontology vocabulary. (class, object attribute, numerical attribute) is embedded in the text representation, and a candidate mapping set is generated through the similarity measurement of high-dimensional vector space and K-nearest neighbor retrieval strategy:
[0050]
[0051] Where R is the alignment candidate between database metadata and ontology, and each element r∈R is a tuple By database element e db and ontology element set composition.
[0052] Fine-grained alignment: Use a generative large language model to further perform semantic disambiguation and logical constraint verification on the candidate set to ensure that the candidate mappings are semantically consistent and comply with logical constraints:
[0053] A=Matcher(R)
[0054] Where A represents the alignment result set, and each element a∈A is a triple (e db ,e on ,d), by the database element e db , ontology elements aligned with database elements e on and the degree of alignment d, which is divided into three levels: high, medium, and low. This stage accurately confirms the correspondence between the database model and the knowledge ontology, and evaluates the degree of alignment between each database element and its corresponding ontology element.
[0055] Step 4: Based on the mapping pattern extraction results and the database-to-ontology alignment results, ontology expansion and virtual knowledge graph mapping construction are performed based on the alignment confidence.
[0056] For high-confidence alignment results, a mapping relationship between the database schema and the target ontology is directly established. For medium-confidence alignment results, a hierarchical ontology refinement strategy is adopted: based on the principle of minimum commitment in ontology modeling, the ontology expression granularity is expanded by adding domain subclasses or sub-attributes while maintaining core semantic consistency. For low-confidence alignment results, new ontology classes or attributes are directly created that are strongly associated with the source database schema features.
[0057]
[0058] Namer is a namer based on a generative large language model, a=(e db ,e on ,d)∈A is the alignment result and confidence of the database to the ontology. In the process of processing the alignment results with medium and low confidence, the database elements cannot be directly aligned with the ontology elements. In order to map the internal data of the database to the ontology as much as possible while ensuring the correctness of the alignment, the ontology structure will be expanded according to the semantic information of the corresponding database elements and related ontology elements. In the ontology structure expansion, different types of appropriate names will be constructed according to the corresponding scenarios, such as class names are nouns and attribute names are verbs. The expanded ontology As the final ontology structure of the virtual knowledge graph. Finally, according to the final ontology Alignment result set A and mapping pattern extraction results As well as the mapping construction scheme of each mapping mode, construct the virtual knowledge graph mapping.
[0059] The applicant of the present invention has made a detailed explanation and description of the implementation examples of the present invention in conjunction with the drawings in the specification. However, those skilled in the art should understand that the above implementation examples are only preferred implementation plans of the present invention, and the detailed description is only to help readers better understand the spirit of the present invention, and is not a limitation on the scope of protection of the present invention. On the contrary, any improvements or modifications based on the inventive spirit of the present invention should fall within the scope of protection of the present invention.
Claims
1. A method for automatically constructing a virtual knowledge graph driven by a large language model based on a mapping pattern, characterized by: The method comprises the following steps: Step 1: Extract the database table structure metadata and constraint relationships, and convert the database schema into a graph structure based on the RDF standard; Step 2: Convert the mapping pattern into a query statement that conforms to the SPARQL syntax, query the RDF graph structure corresponding to the database pattern, and obtain the extraction results of each mapping pattern. Step 3: Based on the semantic encoding model and the generative large language model, align the database table structure metadata and constraint relationships into the ontology vocabulary, and obtain the database-to-ontology alignment results and alignment confidence. Step 4: Based on the mapping pattern extraction results and the database-to-ontology alignment results, ontology expansion and virtual knowledge graph mapping construction are performed based on the alignment confidence.
2. The method for automatically constructing a virtual knowledge graph driven by a large language model based on a mapping pattern according to claim 1 is characterized in that: The details of step 1 are as follows: Given that the database table structure and its constraint mechanism can be naturally expressed through graph modeling, it is proposed to transform mapping pattern extraction into a subgraph matching problem driven by topological features and transform mapping pattern extraction into a topological subgraph matching problem guided by conceptual models. This process is divided into two stages: Database structure extraction: connect to the target database through the JDBC interface, parse and extract table structure metadata (including table name, attribute list) and database constraint relationships (including primary key, foreign key, unique constraint and check constraint), Graph structure construction: Construct a database schema graph structure G based on the RDF standard according to the database table structure metadata and constraint relationships. DB =(V,E), where the vertex set V = V t ∪V c By table node V t and column node V c The structure represents the table entity and column entity in the database respectively, and the edge set E=E p ∪E f ∪E c Contains three different edge types: primary key relationship edge Used to mark the relationship between the table and its primary key column, foreign key edge Used to represent the reference constraints between cross-table columns, column member edges Then associate the table with its non-primary key columns.
3. The method for automatically constructing a virtual knowledge graph driven by a large language model based on a mapping pattern according to claim 1 is characterized in that: The step 2 is as follows: Mapping Pattern is a construction scheme for summarizing common database structures and corresponding mappings. A specific mapping pattern consists of a quadruple Composition, of which is the target conceptual model, yes A possible database schema expression is, Represents a set of mappings, is a set of ontological axioms, Mapping pattern to SPARQL query: According to the target conceptual model of mapping pattern p The entities, attributes and relationships in the database are based on the RDF standard database schema graph structure G DB , construct the corresponding SPARQL query statement, the specific construction rules are: The entities in G DB Table node V in t Alignment, The properties in V c Column nodes in align, The primary key in E p The edges of align, The foreign key in E f The edges in align, Execute the query: DB Execute SPARQL query statements on the source file to obtain the mapping pattern extraction results. By parsing the mapping pattern and designing the corresponding extraction scheme, all extraction results are merged into the final result set: Where S represents the database schema, and D represents a database instance that satisfies the constraints of S. Represents a set of recognizable mapping patterns in a dataset structure, represents the initial ontology in the process of constructing the virtual knowledge graph, ∪ represents the set union operation, For all mappings in database instance D, express All corresponding ontological axioms.
4. The method for automatically constructing a virtual knowledge graph driven by a large language model based on a mapping pattern according to claim 1 is characterized in that: The step 3 is specifically as follows: Coarse-grained alignment: Using a deep semantic encoding model, the database metadata Σ is aligned with the ontology vocabulary Perform text representation embedding and generate a candidate mapping set through similarity measurement in high-dimensional vector space and K-nearest neighbor retrieval strategy: Where R is the alignment candidate between database metadata and ontology, and each element r∈R is a tuple By database element e db and ontology element set composition, Fine-grained alignment: Use a generative large language model to further perform semantic disambiguation and logical constraint verification on the candidate set to ensure that the candidate mappings are semantically consistent and comply with logical constraints: A=Matcher(R) Where A represents the alignment result set, and each element a∈A is a triple (e db ,e on ,d), by the database element e db , ontology elements aligned with database elements e on and the degree of alignment d, which is divided into three levels: high, medium, and low. This stage accurately confirms the correspondence between the database model and the knowledge ontology, and evaluates the degree of alignment between each database element and its corresponding ontology element.
5. The method for automatically constructing a virtual knowledge graph driven by a large language model based on a mapping pattern according to claim 1 is characterized in that: The specific steps of step 4 are as follows: for high-confidence alignment results, a mapping relationship between the database schema and the target ontology is directly established; for medium-confidence alignment results, a hierarchical ontology refinement strategy is adopted: based on the principle of minimum commitment in ontology modeling, domain subclasses or sub-attributes are added to expand the ontology expression granularity while maintaining core semantic consistency; for low-confidence alignment results, new ontology classes or attributes are directly created that are strongly associated with the source database schema features: Namer is a namer based on a generative large language model, a=(e db ,e on ,d)∈A is the alignment result and confidence of the database to the ontology. In the process of processing the alignment results with medium and low confidence, the database elements cannot be directly aligned with the ontology elements. In order to map the internal data of the database to the ontology as much as possible under the premise of ensuring the correctness of the alignment, the ontology structure will be expanded according to the semantic information of the corresponding database elements and related ontology elements. In the ontology structure expansion, different types of appropriate names will be constructed according to the corresponding scenarios, including class names as nouns and attribute names as verbs. The expanded ontology As the final ontology structure of the virtual knowledge graph, finally according to the final ontology Alignment result set A and mapping pattern extraction results As well as the mapping construction scheme of each mapping mode, construct the virtual knowledge graph mapping.
6. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, it implements the automatic construction method of a virtual knowledge graph driven by a large language model based on a mapping pattern as described in any one of claims 1 to 5 above.
7. A computer-readable storage medium having computer instructions stored thereon, characterized in that: When the computer instructions are executed by the processor, the method for automatically constructing a virtual knowledge graph driven by a large language model based on a mapping pattern as described in any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Metadata query method based on knowledge graph
CN119441386A
Drug repositioning method and system fusing multi-source knowledge graph
WO2024138803A1
Cited By
Ontology organization method based on knowledge graph
CN120996163A