Method and system for constructing Neo4j knowledge graph based on LLM natural language

Through the collaborative architecture of LLM natural language processing and Neo4j graph database, the problems of unstructured text processing and cultural adaptation in smart tourism are solved, and efficient and accurate knowledge graph construction and dynamic updating are achieved, ensuring cultural adaptability and query efficiency.

CN120744136APending Publication Date: 2025-10-03SICHUAN UNIV JINCHENG INST

Patent Information

Application Number
CN202511157789.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-19
Publication Date
2025-10-03

AI Technical Summary

Technical Problem

Existing technologies in the field of smart tourism are unable to effectively process unstructured tourism texts and lack cultural adaptation mechanisms, resulting in low efficiency in knowledge graph construction, high cultural risks, and difficulty in achieving dynamic updates and multi-dimensional semantic associations.

Method used

By adopting the LLM-based natural language processing method, combined with the large-scale model collaborative architecture and the localized knowledge constraint mechanism, the automatic conversion of tourism text into Neo4j knowledge graph is realized, including entity recognition, relationship extraction, attribute verification and dynamic update, and a knowledge graph with a directed graph structure is constructed through the Neo4j graph database.

Benefits of technology

It improves the construction efficiency and accuracy of knowledge graphs, reduces redundancy, ensures cultural adaptability and query efficiency, reduces cultural misunderstandings, and realizes an end-to-end automated construction process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120744136A_ABST
    Figure CN120744136A_ABST
Patent Text Reader

Abstract

The invention provides a method and system for constructing a Neo4j knowledge graph based on an LLM natural language, and belongs to the technical field of smart tourism and knowledge graphs. The method comprises the steps that S1, text entities are recognized, and semantics are understood; s2, analyzing an entity relationship and generating a Cypher statement; s3, extracting entity attributes and performing constraint verification; s4, constructing a Neo4j knowledge graph; and S5, performing dynamic updating and quality control. According to the method, the natural language understanding ability of the large language model and the relation modeling advantage of the Neo4j graph database are fused, so that automatic construction, dynamic updating and culture compliance verification of the tourism knowledge graph are realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of smart tourism and knowledge graph technology, and in particular to a method and system for constructing a Neo4j knowledge graph based on LLM natural language. Background Art

[0002] Current knowledge graph construction technology faces two technical bottlenecks in the smart tourism sector. On the one hand, as demonstrated in "A model-based approach for converting CGMES power system models into operational networks" (Memari and Aljamous, 2023) and "Development of a knowledge graph framework to ease and empower translational approaches in plant research: a use-case ongrain legumes" (Imbert et al., 2023), existing technologies rely heavily on structured inputs such as RDF / XML or standard experimental data, making them unable to directly process unstructured tourism texts such as travelogues and local chronicles. This presents a sharp contradiction with the dynamic free-text data required in tourism scenarios. On the other hand, while AIGC technology and the Neo4j graph database have promoted the intelligent transformation of tourism services, existing LLM-generated content, due to its detachment from local knowledge bases, may violate local customs and cultural taboos, exposing a lack of cultural adaptation mechanisms. The closest existing technology is reflected in two dimensions: at the data level, the n10s plug-in used by Memari and Aljamous implements RDF to Neo4j conversion. Although it can process standardized data in the power sector, it cannot cope with the free text in tourism scenarios. At the application level, the existing smart tourism system adopts the architecture of relational database + rule engine. Its flat data structure makes it difficult to express the multi-dimensional semantic relationship between "festivals-attractions-cultural taboos", resulting in the dilemma of service lag and cultural risks.

[0003] Existing technology implementations exhibit "architecture convergence but diverging capabilities." The power knowledge graph architecture proposed by Memari and Aljamous uses an MDA hierarchical model (PIM→PSM) and an APOC plug-in to achieve node merging. While establishing a CGMES XML to Pandapower network conversion pipeline, its original design was solely for standardized power system data and lacks the ability to process unstructured text such as tourist reviews and historical documents in tourism scenarios. While Imbert et al.'s biological cross-species atlas incorporates an isolation forest algorithm to detect anomalous relationships, its batch import mechanism fundamentally conflicts with the real-time updating requirements of festivals and events. Typical implementations of existing smart tourism systems rely on manual entry of route data and storage via SQL. This static processing model not only fails to capture dynamic changes but also lacks the cultural validation layer emphasized in the patent, resulting in potential risks of non-compliant content. These solutions collectively expose a systematic lack of existing technologies in three key capabilities: unstructured text parsing, dynamic learning, and embedding cultural constraints. Summary of the Invention

[0004] The present invention provides a method and system for constructing a Neo4j knowledge graph based on LLM natural language, and realizes the automatic conversion of tourism text into graph structure through a collaborative architecture of large and small models and a localized knowledge constraint mechanism, so as to solve the problems raised in the above background technology.

[0005] To achieve the above object, the present invention adopts the following technical solutions:

[0006] The method for building a Neo4j knowledge graph based on LLM natural language includes the following steps:

[0007] S1. Identify text entities and understand semantics: Collect and preprocess multi-source tourism texts, perform natural language processing using a collaborative architecture of large and small models, identify entities in the text, understand contextual semantics, and obtain entity and contextual semantic information.

[0008] S2. Analyze entity relationships and generate Cypher statements; extract relationships between entities and contextual semantic information to obtain triple relationships between entities; generate corresponding Cypher statements based on the triple relationships and verify them to obtain verified Cypher statements;

[0009] S3. Extract entity attributes and perform constraint verification; extract attribute information related to the entity from the text, perform constraint verification on the attribute information in combination with the localized knowledge base, and obtain the verified entity attribute information;

[0010] S4. Construct a Neo4j knowledge graph. Based on entity and contextual semantic information, validated Cypher statements, and validated entity attribute information, a knowledge graph with a directed graph structure is constructed using the Neo4j graph database to obtain an initial tourism knowledge graph.

[0011] S5. Dynamic update and quality control: Anomaly detection algorithms are used to identify abnormal data in the initial tourism knowledge graph, and data is supplemented in combination with a dynamic update mechanism to obtain an optimized tourism knowledge graph.

[0012] In this specification, the method for constructing a Neo4j knowledge graph based on LLM natural language also includes: S6. Implementing intelligent query and semantic reasoning; performing semantic reasoning and intelligent query processing on the optimized tourism knowledge graph to obtain accurate tourism information service results.

[0013] In this specification, in S1, identifying entities in text is achieved by: annotating the training data using the BIO annotation system, evaluating the model performance using the F1-score, updating the parameters using the gradient descent method during training, and adjusting the learning rate using the learning rate scheduling formula.

[0014] In this specification, in S2, the relationship extraction is achieved by designing a multi-layer prompt word to guide the large model to extract triples from the text, the triples contain entity 1, relationship, entity 2, and the relationship types include location, contain, and belong to; and using dependency syntax analysis to verify the relationship logic.

[0015] In this specification, in S2, a Cypher statement is generated by a fine-tuned small model, and a context verification mechanism is used to calculate the semantic similarity between the generated statement and the original text. When the similarity is lower than a preset threshold, a regeneration mechanism is triggered.

[0016] In this specification, in S3, entity attribute extraction includes: constructing a localized cultural keyword Trie tree, extracting attribute keywords through a prefix matching algorithm, and the time complexity of the prefix matching algorithm is at a linear level corresponding to the length of the query string; using an edit distance algorithm to process entity aliases, and when the edit distance does not exceed 2, it is considered to be the same entity.

[0017] In this specification, in S3, constraint verification is implemented through a rule engine: cultural constraint rules are defined in the rule engine, including taboos and seasonal restrictions. When the attribute information generated by the large language model violates the rules, the rule engine triggers verification and corrects the attribute information.

[0018] In this specification, in S4, the construction of the Neo4j knowledge graph includes: mapping triples into a graph structure, creating nodes and relationships through verified Cypher statements; using a transaction mechanism to batch import data, and submitting a transaction every 500 records; calculating the Pearson correlation coefficient of the relationship frequency, and when the absolute value of the correlation coefficient is greater than 0.8, it is considered a redundant relationship and the high-frequency relationship is retained.

[0019] In this specification, in S5, the dynamic update and quality control include: using the isolation forest algorithm to construct a random binary tree, calculating the path length from the sample point to the root node, and identifying it as abnormal data when the anomaly score exceeds 0.8; using a bidirectional long short-term memory network to predict missing triplets, and completing knowledge through forward and backward hidden state calculations; using an incremental update transaction mechanism for dynamic data, and performing update operations in a check-first-then-change manner.

[0020] A Neo4j knowledge graph system is constructed based on LLM natural language, and any one of the above methods for constructing a Neo4j knowledge graph based on LLM natural language is applied. The method for constructing a Neo4j knowledge graph system based on LLM natural language includes:

[0021] The text entity recognition and semantic understanding module is used to collect and preprocess multi-source tourism texts, perform natural language processing in conjunction with a large and small model collaborative architecture, identify entities in the text, and understand the contextual semantics to obtain entity and contextual semantic information;

[0022] Entity relationship analysis and Cypher statement generation module, used for:

[0023] Extract the relationship between entities and contextual semantic information to obtain the triple relationship between entities; generate the corresponding Cypher statement based on the triple relationship and verify it to obtain the verified Cypher statement;

[0024] The entity attribute extraction and constraint verification module is used to extract attribute information related to the entity from the text, perform constraint verification on the attribute information in combination with the localized knowledge base, and obtain the verified entity attribute information;

[0025] Neo4j knowledge graph construction module, which is used to construct a knowledge graph with a directed graph structure through the Neo4j graph database based on entity and context semantic information, verified Cypher statements, and verified entity attribute information, to obtain the initial tourism knowledge graph;

[0026] The dynamic update and quality control module is used to identify abnormal data in the initial tourism knowledge graph using an anomaly detection algorithm, and supplement the data with a dynamic update mechanism to obtain an optimized tourism knowledge graph;

[0027] The intelligent query and semantic reasoning module is used to perform semantic reasoning and intelligent query processing on the optimized tourism knowledge graph to obtain accurate tourism information service results.

[0028] In summary, the present invention has at least the following beneficial effects:

[0029] Improved construction efficiency: Through the collaborative work of small and large models, this method achieves automated construction from natural language text to the Neo4j knowledge graph. Through a contextual verification mechanism, the relationship accuracy rate reaches 91.5%, effectively reducing logical conflicts and semantic drift, and improving the quality of the knowledge graph. The construction of a localized knowledge base enables the system to accurately identify localized terms, avoiding cultural misinterpretations and aligning with regional cultural characteristics.

[0030] Reducing graph redundancy: The method of the present invention can effectively control the graph redundancy and improve the storage efficiency and query efficiency of the knowledge graph.

[0031] End-to-end graph database creation strategy: A new process was designed that uses a small model as the starting point to generate Neo4j statements, and then fine-tunes and optimizes them using the large model. This fully leverages the flexibility of the small model and the deep learning capabilities of the large model to achieve full-chain automation from raw data to graph database construction, improving construction accuracy and efficiency.

[0032] Automated tool chain: We have developed an automated graph database construction tool chain that can automatically complete the entire process from data preprocessing to entity relationship annotation to Neo4j statement generation, reducing manual intervention to less than 10%, and solving the problem that traditional manual construction is time-consuming, labor-intensive, and error-prone.

[0033] Localized knowledge constraints: Build a localized knowledge base to provide localized knowledge constraints for LLM, avoid cultural misunderstandings such as taboos, promote sustainable tourism, and improve the cultural adaptability and accuracy of the knowledge graph. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0035] Figure 1 This is a schematic diagram of the method for constructing a Neo4j knowledge graph based on LLM natural language involved in the present invention.

[0036] Figure 2 This is a schematic diagram of the Neo4j knowledge graph system based on LLM natural language involved in the present invention. DETAILED DESCRIPTION

[0037] Hereinafter, only certain exemplary embodiments are briefly described. As will be appreciated by those skilled in the art, the described embodiments may be modified in various ways without departing from the spirit or scope of the embodiments of the present invention. Therefore, the drawings and description are to be regarded as illustrative in nature and not restrictive.

[0038] The disclosure below provides many different embodiments or examples for implementing different structures of the embodiments of the present invention. In order to simplify the disclosure of the embodiments of the present invention, the components and configurations of specific examples are described below. Of course, these are merely examples and are not intended to limit the embodiments of the present invention. In addition, the embodiments of the present invention may repeat reference numerals and / or reference letters in different examples. Such repetition is for the purpose of simplicity and clarity and does not in itself indicate the relationship between the various embodiments and / or configurations discussed.

[0039] The embodiments of the present invention are described in detail below with reference to the accompanying drawings.

[0040] like Figure 1 As shown, this embodiment provides a method for constructing a Neo4j knowledge graph based on LLM natural language, including the following steps:

[0041] S1. Identify text entities and understand semantics: Collect and preprocess multi-source tourism texts, perform natural language processing using a collaborative architecture of large and small models, identify entities in the text, understand contextual semantics, and obtain entity and contextual semantic information.

[0042] S2. Analyze entity relationships and generate Cypher statements; extract relationships between entities and contextual semantic information to obtain triple relationships between entities; generate corresponding Cypher statements based on the triple relationships and verify them to obtain verified Cypher statements;

[0043] S3. Extract entity attributes and perform constraint verification; extract attribute information related to the entity from the text, perform constraint verification on the attribute information in combination with the localized knowledge base, and obtain the verified entity attribute information;

[0044] S4. Construct a Neo4j knowledge graph. Based on entity and contextual semantic information, validated Cypher statements, and validated entity attribute information, a knowledge graph with a directed graph structure is constructed using the Neo4j graph database to obtain an initial tourism knowledge graph.

[0045] S5. Dynamic update and quality control: Anomaly detection algorithms are used to identify abnormal data in the initial tourism knowledge graph, and data is supplemented in combination with a dynamic update mechanism to obtain an optimized tourism knowledge graph.

[0046] In some embodiments, the method for constructing a Neo4j knowledge graph based on LLM natural language also includes: S6. realizing intelligent query and semantic reasoning; performing semantic reasoning and intelligent query processing on the optimized tourism knowledge graph to obtain accurate tourism information service results.

[0047] In some embodiments, in S1, identifying entities in text is achieved by: annotating training data using the BIO annotation system, evaluating model performance using F1-score, updating parameters using the gradient descent method during training, and adjusting the learning rate using the learning rate scheduling formula.

[0048] In some embodiments, in S2, relationship extraction is achieved by designing multi-layer prompt words to guide the large model to extract triples from the text, where the triples include entity 1, relationship, and entity 2, and the relationship types include location, inclusion, and belonging; and using dependency syntactic analysis to verify the relationship logic.

[0049] In some embodiments, in S2, a Cypher statement is generated by a fine-tuned small model, and a context verification mechanism is used to calculate the semantic similarity between the generated statement and the original text. When the similarity is lower than a preset threshold, a regeneration mechanism is triggered.

[0050] In some embodiments, in S3, entity attribute extraction includes: constructing a localized cultural keyword Trie tree, extracting attribute keywords through a prefix matching algorithm, and the time complexity of the prefix matching algorithm is a linear level corresponding to the length of the query string; using an edit distance algorithm to process entity aliases, and when the edit distance does not exceed 2, it is considered to be the same entity.

[0051] In some embodiments, in S3, constraint verification is implemented through a rule engine: cultural constraint rules are defined in the rule engine, including taboos and seasonal restrictions. When the attribute information generated by the large language model violates the rules, the rule engine triggers verification and corrects the attribute information.

[0052] In some embodiments, in S4, the Neo4j knowledge graph construction includes: mapping triples into a graph structure, creating nodes and relationships through verified Cypher statements; using a transaction mechanism to batch import data, and submitting a transaction every 500 records; calculating the Pearson correlation coefficient of the relationship frequency, and when the absolute value of the correlation coefficient is greater than 0.8, it is considered a redundant relationship and the high-frequency relationship is retained.

[0053] In some embodiments, in S5, dynamic update and quality control include: using the isolation forest algorithm to construct a random binary tree, calculating the path length from the sample point to the root node, and identifying abnormal data when the anomaly score exceeds 0.8; using a bidirectional long short-term memory network to predict missing triplets, and completing knowledge through forward and backward hidden state calculations; using an incremental update transaction mechanism for dynamic data, and performing update operations in a check-first-then-modify manner.

[0054] The technical ideas of the present invention are as follows:

[0055] In order to overcome the problems of low manual annotation efficiency, delayed dynamic update and insufficient cultural constraints in the construction of knowledge graphs in existing smart tourism systems, the embodiments of the present invention provide a method and system for constructing a Neo4j knowledge graph based on LLM natural language, and realize the automatic conversion of tourism text into graph structure through a collaborative architecture of large and small models and a localized knowledge constraint mechanism.

[0056] The method for building a Neo4j knowledge graph based on LLM natural language includes the following:

[0057] Step S1. Identify text entities and understand semantics

[0058] In a preferred embodiment, in step S1, the text is first preprocessed at multiple levels, and the LoRA fine-tuning technology is combined to adapt the model to tourism data, specifically including the following:

[0059] S1.1 Data cleaning and word segmentation

[0060] Use regular expressions to remove HTML tags and special characters (such as @#$%) from the text. The formula is as follows:

[0061] ;

[0062] Sample input: "

Travel Guide

[0063] Output: "Travel Guide: Ticket price for a certain scenic spot is 200 yuan per person, opening hours are 9:00-17:00".

[0064] We use the Jieba word segmentation tool combined with a custom tourism word list (including 2000+ localized words) to segment words, remove duplicates from the segmentation results, and generate a standardized corpus. The word frequency statistics formula is:

[0065] ;

[0066] in, is the number of times word w appears in the text, The total number of words in the text.

[0067] Create an entity type mapping table, for example:

[0068] Python

[0069] run

[0070] entity_mapping={

[0071] "City": "City",

[0072] "Festival": "Festival",

[0073] "Scenic Spot": "ScenicSpot"

[0074] }.

[0075] S1.2LoRA fine-tuning and word vector mapping

[0076] The LoRA (Low-Rank Adaptation) technology is used to fine-tune the Qwen3-Turbo model, freeze the main parameters of the pre-trained model, and only train the low-rank adapter matrix. The parameter update formula is:

[0077] ;

[0078] Among them, B and A are adapter matrices, is the momentum coefficient, is the parameter update amount, T is the matrix transpose operator, is the parameter update amount of the last training step.

[0079] Use Word2Vec to generate word vectors and calculate two word vectors and The Euclidean distance measures the similarity:

[0080] ;

[0081] in, is the Euclidean distance function, are word vectors x and y, i is the sum index, the closer the distance is to 0, the more similar the word vector semantics are.

[0082] S1.3 Entity Recognition Model Training

[0083] The BIO annotation system (B-Entity, I-Entity, O) is used to annotate the training data, and the F1-score is used to evaluate the model performance:

[0084] ;

[0085] in, is the harmonic mean of precision and recall, is the precision rate, recall is the recall rate, and the gradient descent method is used to update the parameters during training. The learning rate scheduling formula is:

[0086] ;

[0087] in, is the initial learning rate, k is the decay coefficient, T is the total number of iterations, is the learning rate at time t, is the current training step number.

[0088] Using Jieba word segmentation combined with tourism dictionary (containing more than 3000 entries), using BIOES annotation system:

[0089] ;

[0090] Example: "XX Lake is located in XX City" → [B-ScenicSpot, I-ScenicSpot, O, B-Location, I-Location, E-Location].

[0091] S2. Analyze entity relationships and generate Cypher statements

[0092] In a preferred embodiment, in step S2, relation extraction and Cypher statement generation are implemented through a large and small model collaboration mechanism, specifically including the following:

[0093] S2.1 Hint Engineering and Relation Extraction

[0094] Design multi-layer prompts to guide Qwen3-Turbo in extracting relationships. The example prompts are as follows:

[0095] text[System Prompt]: You are a professional tourism knowledge graph construction assistant. You need to extract triples (entity 1, relationship, entity 2) from text. Relation types include location, contains, belongs to, etc.

[0096] [User Prompt]: Text: "XX Lake is located in XX County, XX City, and is one of the three largest lakes."

[0097] Dependency syntactic analysis is used to verify relational logic, for example, triples are generated through the subject-verb-object structure of "located" (XX Lake - located - XX County).

[0098] Large model prompt template:

[0099] text

[0100] Text: "${input_text}".

[0101] Require:

[0102] 1. Extract entity triples (entity 1, relationship, entity 2);

[0103] 2. Relationship types are limited to: held, located in, included, and participated in;

[0104] 3. Output format: [(entity 1, relationship, entity 2)].

[0105] Sample output: [("XX place","held","XX activity"),("XX people","participated","XX activity")].

[0106] S2.2TF-IDF and keyword filtering

[0107] Calculate the inverse document frequency (IDF) to evaluate the importance of words:

[0108] ;

[0109] Where N is the total number of documents in the corpus, is the number of documents containing word w.

[0110] The TF-IDF formula is:

[0111] ;

[0112] in is the TF-IDF weight of word w, is the word frequency, is the inverse document frequency, w is any word,

[0113] The words with the top 10% TF-IDF values ​​are selected as candidate keywords for relationship extraction.

[0114] S2.3Cypher statement generation and verification

[0115] The deepseek-coder model generates Cypher statements after fine-tuning with LoRA. Example of node creation:

[0116] cypherMERGE(s:ScenicSpot{name:'${entity}',type:'${type}'})

[0117] ON CREATE SET s.createTime = timestamp().

[0118] Small model Cypher generation

[0119] Generate a parameterized Cypher template through deepseek - coder fine - tuned by LoRA:

[0120] cypher

[0121] MERGE (e1:${type1} {name: '${entity1}'})

[0122] MERGE (e2:${type2} {name: '${entity2}'})

[0123] MERGE (e1)-[:${relation}]->(e2);

[0124] Example input triple: ("XX place", "held", "XX event");

[0125] Generated statement:

[0126] cypher

[0127] MERGE (e1:Temple {name: 'XX place'})

[0128] MERGE (e2:Festival {name: 'XX event'})

[0129] MERGE (e1)-[:HOLDS]->(e2).

[0130] Adopt a context verification mechanism. First, perform syntax verification. Use the ANTLR parser to verify Cypher syntax: is_valid = CypherParser(cypher_statement) = Error;

[0131] Then, calculate the semantic similarity between the generated statement and the original text (using cosine similarity):

[0132] ;

[0133] where is the sine function of the vector angle, are two vectors,

[0134] semantic_sim = cosine_sim(LLM_embedding(text),embedding(cypher));

[0135] The threshold is set to 0.7. If it is lower, regeneration is triggered.

[0136] Transaction execution strategy

[0137] Using a batch submission mechanism, every 500 Cypher statements constitute a transaction:

[0138] cypher

[0139] BEGIN TRANSACTION

[0140] / / 500 MERGE statements

[0141] COMMIT.

[0142] S2.4 Model Collaboration Process

[0143] Large models parse text to generate triples;

[0144] The triplet is passed to the small model through the API;

[0145] The small model generates a Cypher and returns it;

[0146] The large model verifies the rationality of Cypher semantics.

[0147] S3. Extract entity attributes and perform constraint verification

[0148] In a preferred embodiment, in step S3, semantic constraints are performed on the attributes of tourism entities in combination with the local knowledge base, specifically including the following:

[0149] Trie Index Construction and Keyword Matching: A cultural keyword Trie tree is constructed. A node structure consists of a character, a child node pointer, and an end marker. The process for inserting the string "Lunar New Year" is as follows: root node → 'Lunar' → 'Li' → 'New' → 'Year', marking 'Year' as the end node. The prefix matching algorithm has a time complexity of O(m), where m is the length of the query string.

[0150] The knowledge base is constructed using RDF format to store localized knowledge.

[0151] Build a cultural taboo rule library:

[0152] Taboo rules = {

[0153] "XX place": ["No photography allowed"],

[0154] "Festival": ["Do not participate in or hold certain activities"]

[0155] }.

[0156] The attribute constraint validation rule engine defines cultural constraint rules, for example:

[0157] python run rules = {

[0158] "Taboo": ["shooting"],

[0159] "Seasonal restrictions": {"XX Lake": "No swimming allowed in winter", "Mount Everest": "Closed during rainy season"}

[0160] }.

[0161] When LLM generates the attribute "XX Lake is open for swimming in winter", it triggers the rule engine verification and corrects it to "XX Lake is frozen in winter and swimming is prohibited."

[0162] Verification function logic:

[0163] ```Python

[0164] def validate_property(entity, prop, value):

[0165] if entity.type == "XX place" and prop == "opening hours":

[0166] if "Sunday" in value and entity.name in special list:

[0167] return False, "This place is closed on Sundays"

[0168] return True, "".

[0169] Attribute value disambiguation and standardization uses the Levenshtein distance algorithm to handle entity aliases. For example, the distance calculation between "XX place" and "A place" is:

[0170] When the distance is ≤ 2, it is considered as the same entity, where is the Levenshtein distance, a, b are the input strings, is the absolute value of a, b, is the last character of string a, b, is the minimum function, if is the conditional judgment symbol, is the default branch symbol.

[0171] Cultural conflict detection

[0172] Use semantic similarity calculation to detect potential conflicts:

[0173] conflict_score=sim(input_text,taboo rule text).

[0174] When the similarity exceeds a threshold (such as 0.6), an alert is triggered.

[0175] S4. Build Neo4j knowledge graph

[0176] In a preferred embodiment, in step S4, a tourism knowledge graph is constructed based on the Neo4j graph database, and storage efficiency is improved through index optimization and redundancy detection, which specifically includes the following:

[0177] S4.1 Mapping triples to graph structures, creating nodes and relationships

[0178] Cypher example:

[0179] cypherMERGE (spot:ScenicSpot {name: 'XX'})

[0180] MERGE (city:City {name: 'X city'})

[0181] MERGE (spot)-[:LOCATED_IN {since: '7th century'}]->(city).

[0182] Batch import uses a transaction mechanism, submitting a transaction every 500 records to improve import efficiency.

[0183] S4.2 Pearson correlation coefficient to detect redundant relationships

[0184] Calculate the Pearson correlation coefficient of the relationship frequency using the formula:

[0185] ;

[0186] When |r|>0.8, it is considered as a redundant relationship (such as "located in" and "located in"), and the high-frequency relationship is retained, where r is the Pearson correlation coefficient, i is the data index, and n is the total number of data points. is the value of the i-th data point on the variable x, is the mean of the variable x, is the value of the i-th data point on the variable y, is the mean of the variable y.

[0187] S4.3 Composite Index and Query Optimization

[0188] Create a composite index of entity name and type: cypherCREATE INDEX ON :ScenicSpot(name,type);

[0189] Graph traversal query example (find all scenic spots in XX city): cypherMATCH (s:ScenicSpot)-[:LOCATED_IN]->(c:City {name: 'XX'})

[0190] RETURN s.name, s.feature.

[0191] Furthermore, efficient graph storage and query are implemented based on Neo4j, including:

[0192] 1. Index optimization

[0193] Creating a composite index improves query performance:

[0194] cypher

[0195] CREATE INDEX ON :ScenicSpot(name, type)

[0196] CREATE INDEX ON :Festival(time).

[0197] 2. Relationship Clustering

[0198] Use Louvain algorithm for relationship clustering:

[0199] ;

[0200] in, is the adjacency matrix, is the degree of node i, Assigned to the community of node i, is the degree of node j, is the community assignment of node j, m is the sum of all edge weights in the network, is the Kronecker delta function, which is used to determine whether two nodes belong to the same community.

[0201] 3. Query Optimization

[0202] Use EXPLAIN to analyze the query execution plan:

[0203] cypher

[0204] EXPLAIN MATCH (s:ScenicSpot)-[:HAS_EVENT]->(e:Festival)

[0205] WHERE s.city = 'XX city' RETURN s, e.

[0206] S5. Dynamic Update and Quality Control

[0207] In a preferred embodiment, in step S5, the dynamic maintenance and completion of the graph is achieved through the isolation forest algorithm and the BiLSTM model, which specifically includes the following:

[0208] S5.1 Isolation Forest Anomaly Detection

[0209] Construct a random binary tree and calculate the path length h(x) from the sample point to the root node. The anomaly score formula is:

[0210] ;

[0211] in, is the mean path length, c(n) is the normalization coefficient, and when s(x,n)>0.8), it is identified as an anomaly (such as "Mount Everest is located in Shanghai").

[0212] S5.2 BiLSTM-driven knowledge completion

[0213] A bidirectional long short-term memory network is used to predict missing triplets. The forward hidden state and the backward hidden state are calculated as follows:

[0214] ;

[0215] in is the hidden state vector at time t, LSTM is the long short-term memory network, is the input vector at time t, and the final hidden state is .

[0216] S5.3 Incremental Update Transaction Mechanism

[0217] Update process for dynamic data (such as holiday schedule adjustments): LLM generates update Cypher statements; Neo4j starts a transaction and performs a check-before-update operation: cypherSTART TRANSACTION

[0218] MATCH (f:Festival {name: 'Lunar New Year'})

[0219] SET f.date = '2024-02-10'

[0220] COMMIT.

[0221] S6. Implementing Intelligent Query and Semantic Reasoning

[0222] In a preferred embodiment, in step S6, intelligent reasoning of tourism scenarios is implemented based on graph traversal and vector similarity calculation, specifically including the following:

[0223] S6.1 Query statement vector representation

[0224] Convert natural language queries into dense vectors and use the embedding interface of Qwen3-Turbo to generate 768-dimensional vectors. For example, the vector representation of the query "What are the attractions in XX city" is:

[0225] .

[0226] S6.2 Euclidean distance and weighted search

[0227] Calculate the Euclidean distance between the query vector and the graph node attribute vector:

[0228] ;

[0229] Where n is a vector, representing the total number of dimensions of q and v. is the query vector, is the knowledge graph node vector, the attribute embedding vector of the entity in the graph, is the i-th dimension component of the node vector, To sum the index.

[0230] The query terms are weighted based on the TF-IDF weight. The weight formula is:

[0231] ;

[0232] Where ωi is the normalized weight of the i-th query term, ranging from [0,1], TF-IDF(wi) is the TF-IDF value of term wi, which measures the importance of the term in the query, wi is the i-th term in the query, m is the total number of query terms, the number of word segments entered by the user, and j is the sum index, which traverses the subscript variable from the 1st to the mth term in the query. Final retrieval score , score is the final retrieval score, the higher the value, the more relevant the result is to the query, qi: the embedding vector of the i-th query term, vi is the node attribute vector related to wi.

[0233] S6.3 Multi-hop relation reasoning rules

[0234] Define inference rules (such as "attractions → contains → XX activities") and use Cypher's RECURSIVE MATCH to implement multi-hop queries:

[0235] cypherMATCH (s:ScenicSpot {type: 'Scenic Spot'})

[0236] MATCH path = (s)-[*1..3]->(a:Activity {type: 'XX Activity'})

[0237] RETURN s.name, a.name.

[0238] S6.4 Implementation of Intelligent Question Answering System

[0239] Furthermore, the tourism question-and-answer function is realized based on the constructed knowledge graph, including:

[0240] 1. Query conversion

[0241] Map natural language queries to Cypher:

[0242] text

[0243] User question: "What attractions are near XX?"

[0244] Convert Cypher:

[0245] MATCH (t:Temple)-[:NEARBY]->(c:City {name: 'XX'})

[0246] RETURN t.name, t.description.

[0247] 2. Result Generation

[0248] Generate natural language answers using Qwen3-Turbo:

[0249] Python

[0250] run

[0251] def generate_answer(query_result):

[0252] prompt = f"Please generate a natural language answer based on the following structured data: {query_result}"

[0253] return qwen_api(prompt).

[0254] The formula in this invention is obtained based on a combination of actual data training and theoretical derivation. The model is trained by collecting more than 10,000 text data in the tourism field, and the optimal values ​​of the parameters in the formula are determined through cross-validation.

[0255] Build a Neo4j knowledge graph system based on LLM natural language, and apply any of the above methods for building a Neo4j knowledge graph based on LLM natural language, such as Figure 2 As shown, the Neo4j knowledge graph system based on LLM natural language construction includes:

[0256] The text entity recognition and semantic understanding module is used to collect and preprocess multi-source tourism texts, perform natural language processing in conjunction with a large and small model collaborative architecture, identify entities in the text, and understand the contextual semantics to obtain entity and contextual semantic information;

[0257] Entity relationship analysis and Cypher statement generation module, used for:

[0258] Extract the relationship between entities and contextual semantic information to obtain the triple relationship between entities; generate the corresponding Cypher statement based on the triple relationship and verify it to obtain the verified Cypher statement;

[0259] The entity attribute extraction and constraint verification module is used to extract attribute information related to the entity from the text, perform constraint verification on the attribute information in combination with the localized knowledge base, and obtain the verified entity attribute information;

[0260] Neo4j knowledge graph construction module, which is used to construct a knowledge graph with a directed graph structure through the Neo4j graph database based on entity and context semantic information, verified Cypher statements, and verified entity attribute information, to obtain the initial tourism knowledge graph;

[0261] The dynamic update and quality control module is used to identify abnormal data in the initial tourism knowledge graph using an anomaly detection algorithm, and supplement the data with a dynamic update mechanism to obtain an optimized tourism knowledge graph;

[0262] The intelligent query and semantic reasoning module is used to perform semantic reasoning and intelligent query processing on the optimized tourism knowledge graph to obtain accurate tourism information service results.

[0263] The present invention innovatively proposes:

[0264] LLM-Neo4j collaborative architecture enables end-to-end conversion from unstructured text to graph structures;

[0265] A cultural constraint embedding mechanism ensures that generated content complies with local standards through a knowledge graph validation layer;

[0266] Dynamic relationship learning module automatically captures changes in node relationship attributes.

[0267] The above embodiments are intended to illustrate the present invention, not to limit the present invention. Therefore, changes in illustrative values ​​or substitutions of equivalent components should still fall within the scope of the present invention.

[0268] From the above detailed description, it will be clear to those skilled in the art that the present invention can indeed achieve the aforementioned objectives and is in compliance with the provisions of the Patent Law.

[0269] Although preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they become aware of the basic inventive concepts. Therefore, the appended claims are intended to be interpreted as covering the preferred embodiments and all changes and modifications that fall within the scope of the invention. The foregoing description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. It should be noted that any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention are intended to be included within the scope of protection of the present invention.

[0270] It should be noted that the above description of the relevant processes is for illustration and purpose only and does not limit the scope of application of this specification. For those skilled in the art, various modifications and changes can be made to the processes under the guidance of this specification. However, such modifications and changes are still within the scope of this specification.

[0271] The basic concepts have been described above. It will be apparent to those skilled in the art after reading this application that the above disclosures are merely illustrative and do not constitute limitations on this application. Although not explicitly stated herein, those skilled in the art may make various modifications, improvements, and amendments to this application. Such modifications, improvements, and amendments are suggested in this application and remain within the spirit and scope of the exemplary embodiments of this application.

[0272] At the same time, this application uses specific terms to describe the embodiments of this application. For example, "one embodiment," "an embodiment," and / or "some embodiments" refer to a certain feature, structure, or characteristic related to at least one embodiment of this application. Therefore, it should be emphasized and noted that "one embodiment," "an embodiment," or "an alternative embodiment" mentioned twice or more in different places in this specification does not necessarily refer to the same embodiment. In addition, certain features, structures, or characteristics in one or more embodiments of this application may be appropriately combined.

[0273] Furthermore, those skilled in the art will appreciate that various aspects of the present application may be illustrated and described in terms of a number of patentable categories or situations, including any new and useful process, machine, product, or combination of substances, or any new and useful improvement thereof. Thus, various aspects of the present application may be implemented entirely in hardware, entirely in software (including firmware, resident software, microcode, etc.), or in a combination of hardware and software. Each of the above hardware and software may be referred to as a "unit," "module," or "system." Furthermore, various aspects of the present application may take the form of a computer program product embodied in one or more computer-readable media, with computer-readable program code embodied therein.

[0274] The computer program code required for the operation of each part of this application can be written in any one or more programming languages, including object-oriented programming languages ​​such as Java, Scala, Smalltalk, Eiffel, JADE, Emerald, C++, C#, VB.NET, Python, etc., conventional procedural programming languages ​​such as C programming language, Visual Basic, Fortran2103, Perl, COBOL2102, PHP, ABAP, dynamic programming languages ​​such as Python, Ruby and Groovy, or other programming languages. The program code can be run entirely on the user's computer, or as a standalone software package on the user's computer, or partly on the user's computer and partly on a remote computer, or entirely on a remote computer or server. In the latter case, the remote computer can be connected to the user's computer via any network form, such as a local area network (LAN) or a wide area network (WAN), or connected to an external computer (e.g., via the Internet), or in a cloud computing environment, or used as a service such as software as a service (SaaS).

[0275] In addition, unless expressly stated in the claims, the order of the processing elements and sequences described in this application, the use of alphanumeric characters, or the use of other names are not intended to limit the order of the processes and methods of this application. Although the above disclosure discusses some embodiments of the invention that are currently considered useful through various examples, it should be understood that such details are only for illustrative purposes, and the attached claims are not limited to the disclosed embodiments. On the contrary, the claims are intended to cover all modifications and equivalent combinations that are consistent with the essence and scope of the embodiments of this application. For example, although the implementation of the various components described above can be embodied in a hardware device, it can also be implemented as a pure software solution, for example, installation on an existing server or mobile device.

[0276] Similarly, it should be noted that in order to simplify the presentation of this disclosure and thereby facilitate understanding of one or more of the invention's embodiments, the foregoing descriptions of the embodiments of this disclosure sometimes combine multiple features into a single embodiment, figure, or description thereof. However, this approach should not be interpreted as reflecting an intention that the claimed subject matter requires more features than expressly recited in each claim. Rather, the subject matter of the invention may possess fewer features than the single embodiment described above.

Claims

1. A method for constructing a Neo4j knowledge graph based on LLM natural language, characterized by: The following steps are involved: S1. Identify text entities and understand semantics: Collect and preprocess multi-source tourism texts, perform natural language processing using a collaborative architecture of large and small models, identify entities in the text, understand contextual semantics, and obtain entity and contextual semantic information. S2. Analyze entity relationships and generate Cypher statements; extract relationships between entities and contextual semantic information to obtain triple relationships between entities; generate corresponding Cypher statements based on the triple relationships and verify them to obtain verified Cypher statements; S3. Extract entity attributes and perform constraint verification; extract attribute information related to the entity from the text, perform constraint verification on the attribute information in combination with the localized knowledge base, and obtain the verified entity attribute information; S4. Build Neo4j knowledge graph; Based on entity and contextual semantic information, verified Cypher statements, and verified entity attribute information, a knowledge graph with a directed graph structure is constructed through the Neo4j graph database to obtain the initial tourism knowledge graph. S5. Dynamic update and quality control: Anomaly detection algorithms are used to identify abnormal data in the initial tourism knowledge graph, and data is supplemented in combination with a dynamic update mechanism to obtain an optimized tourism knowledge graph.

2. The method for constructing a Neo4j knowledge graph based on LLM natural language according to claim 1 is characterized in that: Also includes: S6. Implement intelligent query and semantic reasoning; Perform semantic reasoning and intelligent query processing on the optimized tourism knowledge graph to obtain accurate tourism information service results.

3. The method for constructing Neo4j knowledge graph based on LLM natural language according to claim 1 is characterized in that: In S1, identifying entities in text is achieved by: annotating training data using the BIO annotation system, evaluating model performance using the F1-score, updating parameters using the gradient descent method during training, and adjusting the learning rate using the learning rate scheduling formula.

4. The method for constructing Neo4j knowledge graph based on LLM natural language according to claim 1 is characterized in that: In S2, relation extraction is achieved by designing multi-layer prompt words to guide the large model to extract triples from the text. The triples contain entity 1, relationship, and entity 2. The relationship types include location, containment, and belonging. Dependency syntactic analysis is used to verify the relationship logic.

5. The method for constructing Neo4j knowledge graph based on LLM natural language according to claim 1, characterized in that: In S2, a Cypher statement is generated by the fine-tuned small model, and a context verification mechanism is used to calculate the semantic similarity between the generated statement and the original text. When the similarity is lower than a preset threshold, a regeneration mechanism is triggered.

6. The method for constructing Neo4j knowledge graph based on LLM natural language according to claim 1, characterized in that: In the S3, entity attribute extraction includes: constructing a localized cultural keyword Trie tree, extracting attribute keywords through a prefix matching algorithm, and the time complexity of the prefix matching algorithm is at a linear level corresponding to the length of the query string; using an edit distance algorithm to process entity aliases, and when the edit distance does not exceed 2, it is considered to be the same entity.

7. The method for constructing Neo4j knowledge graph based on LLM natural language according to claim 1, characterized in that: In S3, constraint verification is implemented through a rule engine: cultural constraint rules, including taboos and seasonal restrictions, are defined in the rule engine. When the attribute information generated by the large language model violates the rules, the rule engine triggers verification and corrects the attribute information.

8. The method for constructing Neo4j knowledge graph based on LLM natural language according to claim 1, characterized in that: In S4, the construction of the Neo4j knowledge graph includes: mapping triples into a graph structure, creating nodes and relationships through verified Cypher statements; using a transaction mechanism to import data in batches, and submitting a transaction every 500 records; calculating the Pearson correlation coefficient of the relationship frequency, and when the absolute value of the correlation coefficient is greater than 0.8, it is considered a redundant relationship and the high-frequency relationship is retained.

9. The method for constructing Neo4j knowledge graph based on LLM natural language according to claim 1, characterized in that: In S5, dynamic updating and quality control include: using the isolation forest algorithm to construct a random binary tree, calculating the path length from the sample point to the root node, and identifying abnormal data when the anomaly score exceeds 0.8; using a bidirectional long short-term memory network to predict missing triplets, and completing knowledge through forward and backward hidden state calculations; using an incremental update transaction mechanism for dynamic data, and performing update operations in a check-first-then-change manner.

10. Build a Neo4j knowledge graph system based on LLM natural language, characterized by: The method for constructing a Neo4j knowledge graph based on LLM natural language according to any one of claims 1 to 9 is applied, and the system for constructing a Neo4j knowledge graph based on LLM natural language comprises: The text entity recognition and semantic understanding module is used to collect and preprocess multi-source tourism texts, perform natural language processing in conjunction with a large and small model collaborative architecture, identify entities in the text, and understand the contextual semantics to obtain entity and contextual semantic information; Entity relationship analysis and Cypher statement generation module, used for: Extract the relationship between entities and contextual semantic information to obtain the triple relationship between entities; generate the corresponding Cypher statement based on the triple relationship and verify it to obtain the verified Cypher statement; The entity attribute extraction and constraint verification module is used to extract attribute information related to the entity from the text, perform constraint verification on the attribute information in combination with the localized knowledge base, and obtain the verified entity attribute information; Neo4j knowledge graph construction module, which is used to construct a knowledge graph with a directed graph structure through the Neo4j graph database based on entity and context semantic information, verified Cypher statements, and verified entity attribute information, to obtain the initial tourism knowledge graph; The dynamic update and quality control module is used to identify abnormal data in the initial tourism knowledge graph using an anomaly detection algorithm, and supplement the data with a dynamic update mechanism to obtain an optimized tourism knowledge graph; The intelligent query and semantic reasoning module is used to perform semantic reasoning and intelligent query processing on the optimized tourism knowledge graph to obtain accurate tourism information service results.

Citation Information

Patent Citations

  • Data processing method and device and electronic equipment

    CN113868433A

  • Method and system for optimizing knowledge graph based on large language model

    CN117271791A

  • Industrial chain analysis method and system based on knowledge graph

    CN118626811A

  • Power situation awareness system network asset information checking method based on knowledge graph

    CN120218204A

  • Government affair hotline service knowledge graph construction method and system based on large language model

    CN120354923A

Cited By

  • Intelligent property right retrieval and matching system based on knowledge graph

    CN120911573A

  • Dynamic knowledge graph construction and application method and device for financial service analysis, equipment and medium

    CN121638411A

  • Dynamic knowledge graph construction and application method, device and equipment for financial service analysis and medium

    CN121638411B