Intelligent article generation method and system based on codebase understanding
By standardizing the codebase and extracting multi-dimensional semantics, a dynamic knowledge graph of the code is generated. Combined with BERT and a large language model, natural language query and graph path reasoning are performed, which solves the problem of insufficient understanding of the codebase and achieves high-quality, technically consistent article generation.
Patent Information
- Application Number
- CN202610781251.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-02
- Publication Date
- 2026-08-25
AI Technical Summary
Existing technologies lack sufficient understanding of codebases, rely on manual compilation for article generation, and struggle to guarantee the accuracy and technical consistency of content. This results in logical inconsistencies, inconsistent expressions, and errors in technical knowledge points in the generated text, failing to meet the demand for automated, high-quality, and highly reliable technical article generation in complex code scenarios.
By standardizing the codebase and extracting multi-dimensional semantics, a dynamic knowledge graph of the code is generated. Combined with the BERT pre-trained model and the large language model, natural language query and graph path reasoning are performed to generate the target task article content, and logical verification and optimization are carried out.
It achieves a deep understanding of the codebase and automated content output, improving the accuracy and technical consistency of task article generation. The generated articles have rigorous logic, standardized format, and can be directly used for open source project release.
Smart Images

Figure CN122633879A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of intelligent article generation technology, specifically to an intelligent article generation method and system based on code library understanding. Background Technology
[0002] With the increasing demand for collaborative software development and technical documentation, the automatic generation of documentation, technical analysis articles, and task reports based on code repositories is gradually becoming an industry necessity. Existing technologies mostly rely on keyword matching, template filling, or simple text extraction to generate articles, making it difficult to deeply model and understand code structure, call relationships, business logic, and semantic connotations. This often leads to incomplete code semantic analysis and missing knowledge connections. Furthermore, the lack of alignment between domain terminology and code semantics during task requirement analysis results in a disconnect between generated content and actual code logic. The generated text also commonly suffers from logical contradictions, inconsistent expressions, and errors in technical knowledge points, requiring extensive manual proofreading and optimization. This is not only inefficient but also fails to guarantee the consistency, accuracy, and professionalism of the documentation and code, failing to meet the demands for automated, high-quality, and highly reliable technical article generation in complex code scenarios.
[0003] Existing technologies suffer from technical problems such as insufficient understanding of the codebase, reliance on manual compilation for article generation, and difficulty in ensuring the accuracy of content and consistency with technology. Summary of the Invention
[0004] This application provides an intelligent article generation method and system based on code library understanding, which is used to address the technical problems in the prior art, such as insufficient understanding of the code library, reliance on manual compilation for article generation, and difficulty in ensuring the accuracy of content and consistency with technology.
[0005] In view of the above problems, this application provides a method and system for intelligent article generation based on code library understanding.
[0006] The first aspect of this application provides an intelligent article generation method based on codebase understanding, the method comprising: The codebase is normalized and subjected to multi-dimensional semantic extraction to obtain multi-dimensional semantic information. Dynamic knowledge modeling is then performed on the codebase based on this multi-dimensional semantic information to generate a dynamic knowledge graph. A query task requirement is input, and a BERT pre-trained model, combined with a domain dictionary, is used to perform a natural language query on the query task requirement to obtain target task keywords. Based on the dynamic knowledge graph, graph path reasoning is performed on the target task keywords to determine the task code context knowledge set. A large language model is used to generate article-level content from the task code context knowledge set to obtain initial task article content. Logical verification and optimization are then performed on the initial task article content to generate the target task article content.
[0007] A second aspect of this application provides an intelligent article generation system based on codebase understanding, the system comprising: The knowledge graph generation module is used to standardize the code library and extract multi-dimensional semantics to obtain multi-dimensional semantic information of the code. Based on this multi-dimensional semantic information, dynamic knowledge modeling is performed on the code library to generate a dynamic knowledge graph. The task keyword acquisition module is used to input query task requirements, combine a domain dictionary with a BERT pre-trained model to perform natural language queries on the query task requirements, and obtain target task keywords. The context knowledge set determination module is used to perform graph path reasoning on the target task keywords based on the dynamic knowledge graph of the code to determine the task code context knowledge set. The task article content generation module uses a large language model to generate article-level content from the task code context knowledge set, obtaining initial task article content. Logical verification and optimization are performed on the initial task article content to generate the target task article content.
[0008] One or more technical solutions provided in this application have at least the following technical effects or advantages: The codebase undergoes normalization and multi-dimensional semantic extraction to obtain multi-dimensional semantic information. Dynamic knowledge modeling is then performed on the codebase to generate a dynamic knowledge graph. Inputting a query task requirement, a BERT pre-trained model, combined with a domain dictionary, performs a natural language query on the query task requirement to obtain target task keywords. Based on the dynamic knowledge graph, graph path reasoning is performed on the target task keywords to determine the task code context knowledge set. A large language model is then used to generate article-level content from the task code context knowledge set, resulting in initial task article content. Logical verification and optimization are performed on the initial task article content to generate the target task article content. This achieves a deep understanding of the codebase and automated content output, improving the accuracy and technical consistency of task article generation. Attached Figure Description
[0009] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0010] Figure 1 A schematic diagram of the intelligent article generation method based on code library understanding provided in this application embodiment; Figure 2 This is a schematic diagram of the structure of an intelligent article generation system based on code library understanding, provided in an embodiment of this application.
[0011] Figure labeling: Knowledge graph generation module 10, task keyword acquisition module 20, context knowledge set determination module 30, task article content generation module 40. Detailed Implementation
[0012] This application provides an intelligent article generation method and system based on code library understanding, which addresses the technical problems in the prior art, such as insufficient understanding of the code library, reliance on manual compilation for article generation, and difficulty in ensuring the accuracy of content and consistency with technology.
[0013] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application.
[0014] Example 1, as Figure 1 As shown, this application provides an intelligent article generation method based on code library understanding, the method comprising: Step S100: Standardize the code library and extract multidimensional semantics to obtain multidimensional semantic information of the code. Based on the multidimensional semantic information of the code, perform dynamic knowledge modeling on the code library to generate a dynamic knowledge graph of the code.
[0015] Specifically, the process begins by constructing a code preprocessor that includes unified indentation, naming conventions, redundant code removal, and syntax correction. This preprocessor performs static code analysis and standardization on open-source project codebases, resulting in a standardized codebase with a unified format and clear logic. The standardized codebase is then subjected to word segmentation and part-of-speech tagging to obtain lexical information. Based on this lexical information, syntactic rules are parsed, and an abstract syntax tree is constructed. Simultaneously, code element dependency analysis is performed. Multidimensional semantic extraction is then completed from three dimensions: static structure layer, interaction logic layer, and contextual intent layer, yielding multidimensional semantic information that comprehensively represents the code's logic and functionality. Next, a knowledge graph meta-model is defined, including code node types, code edge types, and code semantic attributes. Knowledge is extracted from the codebase according to the multidimensional semantic information to obtain a set of code semantic knowledge content. This content set is mapped to the knowledge graph meta-model to complete knowledge fusion modeling, resulting in a basic code knowledge graph. A dynamic incremental update mechanism is then introduced to iteratively update the basic code knowledge graph in real time, ultimately generating a dynamic code knowledge graph that supports deep code understanding and precise contextual retrieval. This provides structured and reasonable code knowledge support for subsequent tasks such as keyword matching and article content generation.
[0016] Step S200: Input the query task requirements, combine the domain dictionary and use the BERT pre-trained model to perform natural language query on the query task requirements to obtain the target task keywords.
[0017] Specifically, the system receives user input requesting a query task related to generating technical articles from open-source projects. First, the request text is cleaned, segmented, and structurally parsed to obtain standardized query text. The BERT pre-trained model employs a bidirectional contextual representation structure based on a Transformer encoder. Pre-training is completed through masked language modeling and next-sentence prediction tasks. This method combines code development and open-source project domain dictionaries to inject and fine-tune the BERT model, constructing a keyword query network oriented towards code library understanding. This network is used to perform semantic encoding, intent recognition, and keyword extraction on the query text, obtaining a candidate query keyword set. The candidate keyword set is then sorted by importance, deduplicated, and merged to accurately extract target task keywords that represent the core intent of the task and match the code knowledge graph retrieval requirements.
[0018] Step S300: Based on the dynamic knowledge graph of the code, perform graph path reasoning on the target task keywords to determine the task code context knowledge set.
[0019] Specifically, based on the generated dynamic knowledge graph of code, a graph attention network layer is constructed. First, the attention coefficients of each code node and its neighboring nodes in the knowledge graph are calculated and normalized to obtain a set of comparable knowledge node attention coefficients. Based on this set of coefficients, the features of neighboring nodes are weighted and summed to update the aggregated features of the current node, completing the feature aggregation and semantic enhancement of the graph attention network. Then, using the obtained target task keywords as the retrieval starting point, graph path reasoning is performed on the dynamic knowledge graph of code under the drive of the graph attention network. The code nodes, semantic edges and attribute information related to the task intent are traversed to obtain complete task reasoning path information. Finally, according to this path, the associated code structure, dependencies, functional logic, implementation details and other structured knowledge are accurately extracted from the dynamic knowledge graph of code to determine the task code context knowledge set covering the entire context of the task, providing real, accurate and complete code basis for the subsequent generation of large language model articles.
[0020] Step S400: Use a large language model to generate article-level content from the task code context knowledge set to obtain initial task article content. Perform logical verification and optimization on the initial task article content to generate target task article content.
[0021] Specifically, the obtained task code context knowledge set undergoes knowledge fragment layering and prompt word engineering design to form layered knowledge prompt word information adapted to the input of a large language model. This information is then input into the large language model, where a structured content generation process is performed based on the actual code structure, functional logic, implementation details, and contextual relationships provided by the dynamic code knowledge graph. This results in initial task article content that aligns with the actual open-source project and includes code implementation explanations. Subsequently, logical verification and optimization are performed on the initial task article content, including logical consistency verification, content conflict identification, and expression deviation location. A report on logical problems in the article is generated, and based on this report, the structural coherence, technical accuracy, and sentence fluency of the initial article are corrected and improved. At the same time, SEO optimization, sensitive word filtering, and automatic generation rules for images and links are combined to further improve the article quality. Finally, the target task article content is generated that is accurate, logically rigorous, formatted correctly, and can be directly used for the release of open-source projects.
[0022] In one possible implementation, step S100 further includes: Step S110: Construct a code preprocessor, which includes unified indentation, naming conventions, redundant code removal, and syntax correction.
[0023] Step S120: Perform static code analysis and normalization preprocessing on the code library according to the code preprocessing procedure to obtain a normalized code library.
[0024] Step S130: Perform word segmentation and part-of-speech tagging on the standardized code library to obtain code lexical information.
[0025] Step S140: Perform multi-dimensional semantic extraction on the standard code library based on the code lexical information to obtain multi-dimensional semantic information of the code.
[0026] Specifically, a code preprocessor is constructed based on Abstract Syntax Tree (AST) parsing technology and static code analysis algorithms. This program is implemented by integrating four functional modules: First, a code formatting algorithm is used to traverse the syntax tree and unify the indentation level, standardizing the indentation format of all code files to 4 spaces. Second, a semantic regular expression matching and identifier naming convention verification algorithm is used to detect and automatically correct variables, functions, and classes according to camelCase or underscore naming conventions. Third, a duplicate code detection algorithm based on AST hash fingerprinting is used to identify duplicate code, uncalled functions, and invalid blank lines by calculating the hash value of the syntax tree of code fragments and performing removal operations. Fourth, a LR syntax analysis algorithm based on the language standard grammar is used to perform lexical and syntactic verification of the code in conjunction with a syntax rule base, automatically correcting problems such as missing symbols, illegal syntax, and incomplete statements. Finally, a complete code preprocessor is formed, including unified indentation, naming conventions, redundant code removal, and syntax correction.
[0027] According to the constructed code preprocessing program, full static code analysis and automated standardization preprocessing are performed on the target code library. Static code analysis completes code structure scanning, syntax parsing, identifier recognition and redundant fragment detection. Then, the modules for unified indentation, naming conventions, redundant code removal and syntax correction are called in sequence to process the code line by line, file by file and module by module to eliminate format chaos, non-standard naming, redundant invalid code and syntax errors. Finally, a standard code library with valid syntax, unified format, clear structure and complete semantics is obtained.
[0028] A code-specific lexical analyzer driven by a Finite State Automaton (DFA) performs low-level word segmentation on a standard codebase. This algorithm takes a code character stream as input and matches lexical units such as keywords, identifiers, operators, delimiters, constants, and strings through a state transition table. It achieves precise segmentation of the code stream based on the longest match principle. Simultaneously, it constructs a part-of-speech tagging mapping system based on code syntax rule matching algorithms, encompassing programming language keywords, identifiers, operators, and delimiters. Each segmented lexical unit undergoes syntactic attribute determination and type labeling to clarify its syntactic role and semantic features. Finally, it outputs structured code lexical information containing lexical unit sequences, positional information, syntax types, and semantic attributes, providing standardized and parsable underlying data support for subsequent multi-dimensional semantic extraction.
[0029] Based on code lexical information, an Abstract Syntax Tree (AST) traversal algorithm and a code semantic feature aggregation algorithm are used to perform multi-dimensional semantic extraction on the standard code library. First, the standard code library is parsed into tree-structured data using an AST parser. Then, a depth-first search (DFS) algorithm is used to traverse the AST nodes to extract static structural features such as the code's syntax structure, hierarchical relationships, and execution logic. At the same time, a code dependency analysis algorithm is used to parse interactive logic features such as variable references, function calls, and module associations. Finally, a semantic intent recognition algorithm is combined to mine intent-level features of code functions, business goals, and implementation logic. From the three dimensions of static structure layer, interactive logic layer, and contextual intent layer, a full-dimensional semantic aggregation and representation is completed. Finally, multi-dimensional semantic information of the code, including code structure, logical relationships, functional intent, and dependency links, is obtained, providing comprehensive and accurate semantic data support for subsequent dynamic knowledge modeling.
[0030] In one possible implementation, step S140 further includes: Step S141: Based on the lexical information of the code, perform syntactic rule parsing on the standard code library and construct a code abstract syntax tree.
[0031] Step S142: Perform dependency analysis on the specified code library to obtain the dependency relationships of code elements.
[0032] Step S143: Construct a multi-dimensional code semantic analysis system, which includes a static structure layer, an interaction logic layer, and a contextual intent layer.
[0033] Step S144: Perform multi-dimensional semantic extraction on the code abstract syntax tree and code element dependency relationship according to the code semantic analysis to obtain multi-dimensional semantic information of the code.
[0034] Specifically, based on the obtained code lexical information, the LR(1) bottom-up syntactic analysis algorithm is used to perform precise syntactic rule parsing on the standard code library. The algorithm takes the sequence of lexical units as input and completes four types of syntactic operations, namely shift, reduction, acceptance, and error reporting, through the state transition stack, action table, and transition table. It strictly matches the context-free grammar rules of the programming language and automatically filters out non-syntactic valid units such as spaces, comments, and redundant delimiters during the parsing process. At the same time, it aggregates syntactic components level by level according to the grammatical production rules and recursively constructs a tree structure that represents the nested structure, syntactic logic, and execution level of the code. Finally, it generates a complete and standardized code abstract syntax tree (AST), which provides a structured syntactic foundation for subsequent code dependency analysis and multi-dimensional semantic extraction.
[0035] A global symbol table tracing algorithm and a cross-function data flow analysis algorithm are used to perform a full-dimensional code element dependency analysis on the standard codebase. The algorithm takes code lexical information and code abstract syntax tree as input. First, it uses a symbol table construction module to uniformly record the definition location and scope of all code elements such as variables, functions, classes, and interfaces. Then, it uses depth-first traversal (DFS) to traverse the syntax tree nodes, performing cross-file and cross-module symbol reference tracing, function call chain resolution, class inheritance relationship identification, parameter passing link marking, and import dependency matching. Through data flow propagation rules, it accurately extracts the relationships such as variable assignment, function nesting, object instantiation, and module references, and finally forms a complete code element dependency relationship including definition-reference relationship, call dependency relationship, inheritance dependency relationship, and composition dependency relationship, providing accurate logical association data for subsequent multi-level semantic extraction.
[0036] A hierarchical semantic modeling algorithm is employed to construct a multi-dimensional system for code semantic analysis. This algorithm takes the abstract syntax tree (AST) structure features and code element dependency features as input, and achieves standardized construction through three steps: dimension definition, feature classification, and semantic boundary delineation. First, a static structure layer is defined, based on the AST tree structure and syntax rules, classifying physical structural features such as code file organization, function / class distribution, statement nesting levels, and syntax composition types. Second, an interaction logic layer is defined, based on symbolic reference tracing and data flow propagation rules, classifying dynamic execution and dependency flow features such as function call chains, variable assignment and passing, class inheritance, and module imports. Finally, a contextual intent layer is defined, combining a domain dictionary and keyword semantic matching algorithms to identify high-level semantic features such as code functional goals, business logic, implementation objectives, and interface uses. The algorithm completes the boundary delineation and feature binding of the three semantic dimensions through a dimension mapping table, ultimately forming a complete multi-dimensional system for code semantic analysis including the static structure layer, interaction logic layer, and contextual intent layer. This provides a clear analytical framework and execution standard for subsequent unified, hierarchical multi-dimensional semantic extraction.
[0037] This algorithm employs a hierarchical semantic feature extraction algorithm and an AST (Abstract Syntax Tree) depth-first traversal (DFS) algorithm. It strictly adheres to a multi-dimensional code semantic analysis system encompassing static structure, interaction logic, and contextual intent layers. This system performs unified multi-dimensional semantic extraction on the code abstract syntax tree and code element dependencies. The algorithm uses the abstract syntax tree as the traversal carrier, recursively accessing all syntax nodes using a depth-first traversal approach. At the static structure layer, it extracts structural features such as function definitions, class structures, statement types, syntax nesting, and code organization. At the interaction logic layer, it extracts execution flow features such as function call chains, variable reference relationships, parameter passing, class inheritance, and module dependencies by combining code element dependencies. At the contextual intent layer, it extracts high-level intent features such as code function, business objectives, interface usage, and implementation logic through semantic matching and rule reasoning. The algorithm normalizes, encodes, and aggregates these three layers of features, ultimately outputting complete, standardized, and knowledge-modeling-compatible multi-dimensional semantic information of the code, encompassing structural, logical, and intent features.
[0038] In one possible implementation, step S140 further includes: Step S141: Define a knowledge graph metamodel, which includes code node types, code edge types, and code semantic attributes.
[0039] Step S142: Extract knowledge from the code library according to the multidimensional semantic information of the code to obtain a set of code semantic knowledge content.
[0040] Step S143: Map the code semantic knowledge content set to the knowledge graph meta-model to perform knowledge fusion modeling and obtain the basic code knowledge graph.
[0041] Step S144: Introduce a graph update mechanism to dynamically and incrementally update the basic code knowledge graph, generating a dynamic code knowledge graph.
[0042] Specifically, based on the need for structured expression of code knowledge, a unified knowledge graph meta-model is defined. This model consists of three core elements: code node types, which identify various entity objects in the code repository, including independently identifiable code elements such as files, classes, functions, variables, constants, interfaces, and imported modules; code edge types, which define the relationships between nodes, including inclusion relationships, call relationships, inheritance relationships, implementation relationships, dependency relationships, reference relationships, and parameter passing relationships; and code semantic attributes, which describe the features of nodes and relationships, including extended information such as name, type, scope, line number, function description, parameter list, return value, syntax category, and semantic tags. This meta-model provides a standardized and scalable top-level structural specification for subsequent code knowledge extraction, fusion, and graph modeling.
[0043] Based on the extraction of multidimensional semantic information of code, a structured extraction method is used to extract knowledge from the standard code library in all dimensions. Code entities such as files, classes, functions, and variables are parsed from the static structure layer, interaction logic layer, and contextual intent layer. Relationships between entities such as calls, inheritance, dependencies, references, and inclusions are identified. Descriptive attributes such as names, scopes, functions, parameters, return values, and semantic tags are extracted. The above entities, relationships, and attributes are organized and aggregated to form a set of code semantic knowledge content covering the full dimensions of code structure, logic, and intent.
[0044] The code entities, relationships, and semantic attributes in the code semantic knowledge content set are matched and mapped one-to-one according to the code node types, code edge types, and code semantic attributes defined in the knowledge graph meta-model. Knowledge fusion is completed through entity alignment, relationship normalization, attribute filling, and conflict resolution. Then, structured modeling and graph storage are performed with nodes as entities, edges as relationships, and attributes as features. Finally, a basic code knowledge graph that can fully represent the code organization structure, logical dependencies, and functional semantics is constructed.
[0045] A dynamic knowledge graph update mechanism integrating monitoring, parsing, and differential updating is introduced. By monitoring changes such as additions, modifications, and deletions in the code repository in real time, lightweight lexical parsing and semantic extraction are performed on the changed code fragments to generate differential knowledge fragments. Based on these fragments, local addition, deletion, and modification operations are performed on the corresponding nodes, relationships, and attributes in the basic code knowledge graph, avoiding full reconstruction and achieving efficient and accurate dynamic incremental updates. Finally, a dynamic code knowledge graph with real-time synchronization and adaptive iteration capabilities is generated.
[0046] In one possible implementation, step S200 further includes: Step S210: Clean and parse the query task requirements to obtain the query task text.
[0047] Step S220: Inject training and fine-tune the BERT pre-trained model using the domain dictionary to generate a keyword query network.
[0048] Step S230: Perform natural language query on the query task text based on the keyword query network to determine the candidate query keyword set.
[0049] Step S240: Sort the candidate query keyword set by importance and perform deduplication and merging to obtain the target task keywords.
[0050] Specifically, the query task requirements of the original input are processed sequentially through text cleaning, redundancy filtering, and sentence parsing. First, special symbols, meaningless garbled characters, repeated spaces, and irrelevant interference characters are removed. Then, the requirement statement is standardized into sentences according to punctuation marks and semantic boundaries. At the same time, the text format and character encoding are unified, and ambiguous expressions and non-core redundant content are eliminated. Finally, a query task text with a regular format, complete semantics, and no noise interference is obtained, providing standardized input for subsequent keyword extraction.
[0051] A keyword query network is constructed using a domain-adaptive BERT fine-tuning architecture. This model, based on the native BERT-base encoder, comprises a 12-layer Transformer encoder, a 768-dimensional hidden layer, and 12 attention heads, enabling contextual semantic feature extraction and bidirectional language understanding. During construction, a dictionary of code-related technical fields, including function names, class names, interface names, technical terms, and business keywords, is extended to the BERT embedding layer via vocabulary injection, achieving semantic alignment of domain terms. A small learning rate fine-tuning strategy is employed during training, using domain-annotated text as training data. Joint training is conducted through a masked language modeling (MLM) task and a keyword sequence labeling task, allowing the model to learn code-related semantic features and terminology association rules. The underlying general semantic features are frozen, and the top-level classification and matching layers are fine-tuned. This ultimately generates a keyword query network with domain terminology awareness, accurate semantic understanding, and intelligent keyword extraction capabilities, used for subsequent keyword recognition and extraction from query text.
[0052] The cleaned and segmented query text is input into a finely tuned keyword query network. The bidirectional Transformer encoding structure of the BERT model is used to encode the contextual semantics of the text. Semantic features such as domain terms, functional descriptions, and entity objects in the text are extracted through a self-attention mechanism. Then, the relevance weight and extraction probability of each word are calculated by the keyword layering and sequence labeling module at the top of the model. Words and phrases with higher weights are selected based on preset thresholds. At the same time, semantic expansion and association recall are performed by combining dynamic knowledge graphs of the code. Finally, a candidate query keyword set covering the core query intent and containing synonymous related terms is formed.
[0053] First, the candidate query keyword set is ranked by importance using a combination of TF-IDF weight calculation and semantic similarity scoring. Priority is determined based on the weight of words in the query text, their relevance to the query intent, and their entity importance in the code knowledge graph. Then, string exact matching and synonym clustering algorithms are used to remove completely duplicate words, merge synonyms and similar expressions, and filter out low-relevance redundant words. Finally, the target task keywords that are reasonably ranked, non-repeating, and accurately match the query requirements are obtained.
[0054] In one possible implementation, step S300 further includes: Step S310: Construct a graph attention network layer based on the dynamic knowledge graph of the code.
[0055] Step S320: Use the graph attention network layer to perform graph path reasoning on the target task keywords to obtain task reasoning path information.
[0056] Step S330: Extract associated knowledge from the dynamic knowledge graph of the code according to the task reasoning path information to determine the task code context knowledge set.
[0057] Specifically, a graph attention network (GAT) layer adapted to the semantic features of code is constructed using a dynamic knowledge graph of code as the underlying data support. This network layer takes code nodes in the graph, such as files, classes, functions, and variables, as network input nodes and uses relationships such as dependency, call, inheritance, and inclusion between nodes as network connection edges. A multi-head attention mechanism is used to assign differentiated attention weights to different neighboring nodes to achieve feature focus on core related nodes. The network structure includes a node embedding layer, an attention weighting layer, and a feature aggregation layer. Through node vector initialization, adjacency relationship encoding, and self-attention calculation, the graph topology and semantic features are fused and encoded, constructing a graph attention network layer that can accurately perceive the relationships between code nodes and capture contextual semantics, providing an efficient graph feature calculation foundation for subsequent graph path reasoning.
[0058] The target task keywords are accurately mapped to the corresponding code nodes in the dynamic code knowledge graph. Using these as the starting point for reasoning, a multi-head attention-weighted multi-hop path reasoning is performed using the constructed graph attention network layer. This process automatically calculates the semantic association weights between adjacent nodes and the query intent through the attention mechanism. It iterative propagation and semantic matching are performed along high-weight relationship edges such as function calls, data dependencies, inheritance implementations, and module references. The optimal connectivity path from the keyword starting node to related functional nodes, logical nodes, and context nodes is mined in the multi-level graph structure. At the same time, the node order, relationship type, weight score, and jump link are recorded, ultimately forming a complete task reasoning path information that reflects the code execution flow and logical association.
[0059] Based on the node sequence and relationship links determined by the task reasoning path information, various code nodes, relationship edges and corresponding semantic attributes on the path are extracted in the code dynamic knowledge graph. Context-related knowledge such as function definitions, variable structures, call relationships, execution logic, functional descriptions, and parameter attributes are obtained in sequence. The extracted content is then structured, deduplicated and semantically normalized to ultimately form a complete, coherent task code context knowledge set that meets the task requirements.
[0060] In one possible implementation, step S310 further includes: Step S311: Calculate the attention coefficient for each node and its neighboring nodes in the dynamic knowledge graph of the code to obtain the knowledge node attention coefficient set.
[0061] Step S312: Normalize the set of attention coefficients of the knowledge nodes to obtain a set of comparable attention coefficients of knowledge nodes.
[0062] Step S313: Based on the comparable knowledge node attention coefficient set, perform a weighted summation of the feature representations of the neighboring nodes to obtain the current node aggregated features, and update the knowledge node feature representations through the current node aggregated features to construct a graph attention network layer.
[0063] Specifically, using a dynamic knowledge graph of code as the computational object, for each code node in the graph, namely files, classes, functions, variables, etc., and their directly adjacent neighbor nodes, an attention scoring function is constructed based on the node's own feature vector and the feature vectors of neighbor nodes. Through node feature concatenation, linear transformation, and attention score calculation, the strength of the association between each neighbor node and the current central node in terms of structural association, semantic relevance, and logical dependency is quantitatively evaluated. This generates corresponding attention coefficients for each pair of central nodes and neighbor nodes. The sum of the attention coefficients of all nodes yields the knowledge node attention coefficient set.
[0064] The attention coefficient set of knowledge nodes is standardized using the Softmax normalization function. This function maps all unnormalized attention coefficients to a numerical range of 0 to 1, making the sum of the attention coefficients of all neighboring nodes corresponding to the same central node equal to 1. This eliminates the numerical differences and dimensional influences of attention coefficients between different nodes, making the weights of each neighboring node directly comparable. Finally, a comparable set of knowledge node attention coefficients with standardized values, interpretable weights, and suitable for feature weighted calculation is generated.
[0065] Using the comparable knowledge node attention coefficient set as the weighting basis, the feature vectors of all neighboring nodes corresponding to the current central node are weighted and summed. The structural features, semantic features, and logical features of different neighboring nodes are deeply fused according to attention weights to obtain the current node aggregated feature containing global context information. The aggregated feature is used to iteratively update the feature representation of the original knowledge node, enhancing the node's ability to perceive code relationships, functional semantics, and contextual dependencies. By performing the above feature weighting, aggregation, and update process on all graph nodes, the overall construction of the graph attention network layer with adaptive weight allocation and enhanced contextual features is finally completed.
[0066] In one possible implementation, step S400 further includes: Step S410: Perform knowledge fragment layering and prompt word design on the task code context knowledge set to obtain layered knowledge prompt word information.
[0067] Step S420: Using a large language model, generate article-level content for the task code context knowledge set based on the hierarchical knowledge prompt information to obtain the initial task article content.
[0068] Specifically, the node information, relationship links, and semantic attributes in the task code context knowledge set are first divided into knowledge fragments according to the levels of background description, structural definition, execution flow, functional logic, and parameter description. Then, corresponding generation prompt rules are designed for each level of knowledge content, clarifying the level theme, expression style, content length, and logical order. The layered knowledge fragments are then bound and integrated with customized prompt words one by one, ultimately forming layered knowledge prompt word information that is clear in its hierarchy, well-defined in its constraints, and can be directly used for model generation.
[0069] The hierarchical knowledge prompts and the task code context knowledge set are input into the pre-trained large language model. Based on the hierarchical structure, semantic constraints and generation requirements in the prompts, the model logically connects the scattered code knowledge, polishes the sentences and organizes the paragraphs. It automatically generates coherent and complete chapter content according to the preset writing style, and finally outputs the initial task article content with a clear structure and content that meets the task requirements.
[0070] In one possible implementation, step S400 further includes: Step S430: Perform logical consistency verification and problem identification and location on the content of the initial task article to obtain a report on logical problems in the article.
[0071] Step S440: Optimize the logical structure of the initial task article content based on the article logic problem content report to generate the target task article content.
[0072] Specifically, an end-to-end algorithm of preprocessing-model training-real-time verification-localization output is adopted. The overall algorithm is a hybrid model architecture combining supervised and unsupervised learning, and the specific implementation is as follows: First, the initial task article content is fully preprocessed. Regular expressions and sequence labeling algorithms are used to split the article content into paragraphs, sentences, and extract keywords. The article text is structured and split into three levels: paragraphs, sentences, and words. At the same time, the corresponding task code context knowledge set, code knowledge graph nodes, and relational data are extracted as the input basis for the verification algorithm. The verification algorithm adopts a complete structure of preprocessing-training-inference-localization. The core algorithm architecture is divided into four core modules: input layer, encoding training layer, logic verification layer, and localization output layer. The functions, usage, and training process of each module are clearly traceable. The input layer receives the initial task article content, the corresponding code context knowledge set, and knowledge graph data. It cleans the input text by removing invalid characters, standardizing terminology, and normalizing sentence structure. After text standardization, it segments the text into sentences, generating sentence sequences and position indices that can be directly used as model input. The encoding training layer uses a pre-trained BERT-base model as its foundation and fine-tunes it through transfer learning. The training dataset consists of article texts from similar tasks, code knowledge graph data, and corresponding logically labeled samples. The training process is divided into three stages: the first stage is pre-training adaptation, which fuses the BERT model with pre-trained word vectors from the code domain, freezes the underlying parameters, and trains only the top semantic mapping layer to achieve initial alignment between text and code knowledge; the second stage... The first stage is supervised training, which involves constructing a labeled dataset with four categories of labels: logical consistency / inconsistency, correct / inverted chronology, terminology matching / conflict, and logical discontinuity / coherence. Labeled samples are input into the encoding layer, and the model is trained using the cross-entropy loss function and F1-score evaluation metric to adapt its semantic encoding and logical discrimination capabilities. The text encoding employs a bidirectional Transformer structure to capture features within sentences that depend on contextual relationships, while semantic alignment uses an attention mechanism to achieve accurate matching between article content and code knowledge. The third stage is generalization training, which introduces noisy data, such as simulated samples with terminology errors, chronological inversions, and logical discontinuities, for adversarial training. This improves the model's ability to identify low-confidence problems and implicit logical flaws. Finally, the model training is completed, and the model's hyperparameters and thresholds are determined.During the verification and recognition process, the algorithm adopts a four-level architecture of encoding-alignment-discrimination-localization. First, the initial task text content is split into paragraphs and sentences. Using a pre-trained text encoding model, based on BERT fine-tuning, each sentence is semantically encoded to generate sentence-level feature vectors, completing the text semantic representation. Then, an attention alignment algorithm is used to match the sentence features with the corresponding code knowledge graph and task context knowledge, constructing a semantic association matrix to achieve accurate alignment between the text content and code logic. Finally, the trained logic discrimination model is activated; this model is based on Transformer... The encoder is constructed using a Multilayer Perceptron (MLP) and includes three parallel modules: a logical temporal discrimination branch, a terminology consistency discrimination branch, and a semantic implication discrimination branch. These modules are responsible for verifying whether the article content contains issues such as temporal inversion, terminology conflicts, logical breaks, semantic contradictions, and misaligned relationships. The temporal discrimination module uses LSTM temporal modeling, the terminology conflict module uses entity linking and string matching algorithms, and the logical break module uses path search and node association verification algorithms. The problem confidence scores output by each module are weighted and fused to obtain the final judgment result. Finally, the BiLSTM-CRF sequence labeling algorithm is used to accurately locate the identified logical problems, labeling the sentence index and paragraph interval where the problem occurs, and clarifying the problem type, such as temporal errors, terminology conflicts, logical breaks, and missing associations. The system integrates confidence levels and corresponding references, along with semantic association rules and localization mapping relationships learned during model training. It structurally integrates problem type, confidence level, localization information, and references to generate a comprehensive report on the article's logical problem content. This report includes a detailed description of the problem, accurate localization, clear type, and sufficient evidence. All algorithm modules are implemented in Python, with the core training framework using PyTorch. Model training is completed using a stochastic gradient descent (SGD) optimizer and a cross-entropy loss function. Five-fold cross-validation and confusion matrix evaluation are employed during training to ensure the algorithm's generalization ability and localization accuracy. The entire process, through model training and real-time inference, achieves comprehensive logical consistency verification, problem identification, and accurate localization of the initial task's article content, ultimately outputting a complete report on the article's logical problem content.
[0073] Based on the problem location, error type, confidence level, and optimization suggestions in the article's logical problem content report, a four-level algorithm architecture of problem matching, strategy generation, optimization execution, and verification feedback is adopted to optimize the logical structure of the initial task article content throughout the entire process, and finally generate the target task article content. The core of this algorithm adopts a hybrid model that combines reinforcement learning and sequence editing. The overall structure is divided into an input parsing layer, a policy decision layer, an optimization execution layer, and a verification feedback layer. Each module works collaboratively and the usage process is clear and traceable. The input parsing layer receives the article's logical problem report and the initial task article content. Through text segmentation and sentence encoding, it uses a pre-trained BERT fine-tuned model, reusing the encoding weights trained with S430, eliminating the need for retraining. It maps the problem type and position index in the problem report to the original sentence features, generating a problem-to-original-text matching matrix to clarify the corresponding original paragraph, sentence, and optimization direction for each logical flaw. The policy decision layer constructs a text editing policy network based on reinforcement learning DQN, using maximum logical coherence, maximum knowledge consistency, and maximum original text retention as reward functions. It takes the problem-to-original-text matching matrix and sentence feature vectors as input and outputs targeted optimization actions, including word order adjustment, semantic completion, contradiction correction, terminology unification, logical connection, and gap filling. Simultaneously, it combines a sequence editing algorithm, namely the Seq2Seq model, to semantically reconstruct sentences requiring rewriting, ensuring that optimization actions conform to technical text specifications. The optimization execution layer then executes the policy decision... The optimization actions output by the strategy layer optimize the initial task article content sentence by sentence and paragraph by paragraph. For the issue of reversed time sequence, the LSTM time sequence sorting algorithm is used to adjust the sentence order, ensuring consistency between the code execution flow and the article's expression. For the issue of terminology conflicts, an entity linking algorithm is used to associate the code knowledge graph and unify terminology. For the issues of logical gaps and semantic contradictions, an attention fusion algorithm is used to supplement connecting sentences and correct conflicting content, while preserving the core technical knowledge points and the overall structure of the original text. The verification and feedback layer reuses the logical consistency verification model trained by S430 to perform real-time verification of the optimized content, determining whether logical problems have been completely corrected. If there are uncorrected problems or newly generated logical defects, feedback is sent to the strategy decision layer for iterative optimization until all logical problems are corrected and logical coherence and knowledge consistency reach a preset threshold. Finally, the target task article content is generated, which is logically rigorous, structurally sound, semantically consistent, and expresses itself in a standardized manner, meeting the task requirements and code knowledge.
[0074] Example 2 is based on the same inventive concept as the intelligent article generation method based on code library understanding in the previous examples, such as... Figure 2 As shown, this application provides an intelligent article generation system based on code library understanding. The system and method embodiments in this application are based on the same inventive concept. The system includes: The knowledge graph generation module 10 is used to perform normalization processing and multi-dimensional semantic extraction on the code library to obtain multi-dimensional semantic information of the code, and to perform dynamic knowledge modeling on the code library according to the multi-dimensional semantic information of the code to generate a dynamic knowledge graph of the code.
[0075] The task keyword acquisition module 20 is used to input the query task requirements, combine the domain dictionary, and use the BERT pre-trained model to perform natural language query on the query task requirements to obtain the target task keywords.
[0076] The context knowledge set determination module 30 is used to perform graph path reasoning on the target task keywords based on the code dynamic knowledge graph to determine the task code context knowledge set.
[0077] The task article content generation module 40 is used to generate article-level content from the task code context knowledge set using a large language model to obtain initial task article content, and to perform logical verification and optimization on the initial task article content to generate target task article content.
[0078] Furthermore, the system is also used to implement the following functions: A code preprocessor is constructed, which includes unified indentation, naming conventions, redundant code removal, and syntax correction. Static code analysis and standardization preprocessing are performed on the code library according to the code preprocessor to obtain a standardized code library. Word segmentation and part-of-speech tagging are performed on the standardized code library to obtain code lexical information. Multidimensional semantic extraction is performed on the standardized code library based on the code lexical information to obtain multidimensional semantic information of the code.
[0079] Furthermore, the system is also used to implement the following functions: Based on the lexical information of the code, the syntactic rules of the standard code library are parsed to construct an abstract syntax tree (AST). Dependency analysis is performed on the standard code library to obtain the dependency relationships of code elements. A multi-dimensional code semantic analysis is constructed, which includes a static structure layer, an interaction logic layer, and a contextual intent layer. Multi-dimensional semantic extraction is performed on the abstract syntax tree and the dependency relationships of code elements according to the multi-dimensional code semantic analysis to obtain multi-dimensional semantic information of the code.
[0080] Furthermore, the system is also used to implement the following functions: Define a knowledge graph metamodel, which includes code node types, code edge types, and code semantic attributes; extract knowledge from the code library according to the multi-dimensional semantic information of the code to obtain a code semantic knowledge content set; map the code semantic knowledge content set to the knowledge graph metamodel for knowledge fusion modeling to obtain a basic code knowledge graph; introduce a graph update mechanism to dynamically and incrementally update the basic code knowledge graph to generate a dynamic code knowledge graph.
[0081] Furthermore, the system is also used to implement the following functions: The query task requirements are cleaned, segmented, and parsed to obtain the query task text; the BERT pre-trained model is injected and fine-tuned using the domain dictionary to generate a keyword query network; the query task text is then queried using natural language based on the keyword query network to determine a set of candidate query keywords; the candidate query keyword set is then sorted by importance and deduplicated to obtain the target task keywords.
[0082] Furthermore, the system is also used to implement the following functions: Based on the dynamic knowledge graph of the code, a graph attention network layer is constructed; the graph attention network layer is used to perform graph path reasoning on the target task keywords to obtain task reasoning path information; according to the task reasoning path information, the dynamic knowledge graph of the code is used to extract associated knowledge to determine the task code context knowledge set.
[0083] Furthermore, the system is also used to implement the following functions: Attention coefficients are calculated for each node and its neighboring nodes in the dynamic knowledge graph of the code to obtain a set of attention coefficients for knowledge nodes; the set of attention coefficients for knowledge nodes is normalized to obtain a set of comparable attention coefficients for knowledge nodes; the feature representations of the neighboring nodes are weighted and summed based on the set of comparable attention coefficients for knowledge nodes to obtain the aggregated features of the current node, and the feature representations of the knowledge nodes are updated through the aggregated features of the current node to construct a graph attention network layer.
[0084] Furthermore, the system is also used to implement the following functions: The task code context knowledge set is hierarchically structured into knowledge fragments and designed with prompt words to obtain hierarchical knowledge prompt word information. A large language model is then used to generate article-level content for the task code context knowledge set based on the hierarchical knowledge prompt word information, resulting in initial task article content.
[0085] Furthermore, the system is also used to implement the following functions: The initial task article content is subjected to logical consistency verification and problem identification and location to obtain an article logical problem content report; based on the article logical problem content report, the logical structure of the initial task article content is optimized to generate the target task article content.
[0086] It should be noted that the order of the embodiments described above is for descriptive purposes only and does not represent the superiority or inferiority of the embodiments. Specific embodiments of this specification have been described above. Furthermore, the processes depicted in the accompanying drawings do not necessarily require a specific or sequential order to achieve the desired results. In some embodiments, multitasking and parallel processing are possible or may be advantageous.
[0087] The above description is only a preferred embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
[0088] This specification and accompanying drawings are merely illustrative examples of this application and are intended to cover any and all modifications, variations, combinations, or equivalents within the scope of this application. Clearly, those skilled in the art can make various alterations and modifications to this application without departing from its scope. Therefore, if such modifications and variations fall within the scope of this application and its equivalents, this application intends to include such modifications and variations.
Claims
1. A method for intelligent article generation based on code library understanding, characterized in that, The method includes: The code library is normalized and multidimensional semantics are extracted to obtain multidimensional semantic information of the code. Dynamic knowledge modeling is performed on the code library according to the multidimensional semantic information of the code to generate a dynamic knowledge graph of the code. Input the query task requirements, combine the domain dictionary, and use the BERT pre-trained model to perform natural language query on the query task requirements to obtain the target task keywords; Based on the dynamic knowledge graph of the code, graph path reasoning is performed on the keywords of the target task to determine the task code context knowledge set; A large language model is used to generate article-level content from the task code context knowledge set to obtain initial task article content. Logical verification and optimization are then performed on the initial task article content to generate target task article content.
2. The intelligent article generation method based on code library understanding as described in claim 1, characterized in that, The codebase is normalized and subjected to multi-dimensional semantic extraction to obtain multi-dimensional semantic information, including: A code preprocessor is constructed, which includes unified indentation, naming conventions, removal of redundant code, and syntax correction. The code library is subjected to static code analysis and normalization preprocessing according to the code preprocessing procedure to obtain a normalized code library; The standardized code library is segmented and part-of-speech tagged to obtain code lexical information; Based on the lexical information of the code, multidimensional semantic extraction is performed on the standard code library to obtain multidimensional semantic information of the code.
3. The intelligent article generation method based on code library understanding as described in claim 2, characterized in that, Based on the lexical information of the code, multidimensional semantic extraction is performed on the canonical code library to obtain multidimensional semantic information of the code, including: Based on the lexical information of the code, the syntactic rules of the standard code library are parsed to construct an abstract syntax tree for the code. Dependency analysis is performed on the aforementioned codebase to obtain the dependency relationships of code elements; Construct a multi-dimensional code semantic analysis system, which includes a static structure layer, an interaction logic layer, and a contextual intent layer. Based on the aforementioned code semantic analysis, multidimensional semantic extraction is performed on the code abstract syntax tree and code element dependency relationships to obtain multidimensional semantic information of the code.
4. The intelligent article generation method based on code library understanding as described in claim 1, characterized in that, Dynamic knowledge modeling is performed on the code library based on the multidimensional semantic information of the code, generating a dynamic knowledge graph of the code, including: Define a knowledge graph metamodel, which includes code node type, code edge type, and code semantic attributes; Knowledge extraction is performed on the code library based on the multidimensional semantic information of the code to obtain a set of code semantic knowledge content; The code semantic knowledge content set is mapped to the knowledge graph meta-model for knowledge fusion modeling to obtain the basic code knowledge graph; A graph update mechanism is introduced to dynamically and incrementally update the basic code knowledge graph, generating a dynamic code knowledge graph.
5. The intelligent article generation method based on code library understanding as described in claim 1, characterized in that, Combining a domain dictionary with a BERT pre-trained model, a natural language query is performed on the query task requirements to obtain target task keywords, including: The query task requirements are cleaned, segmented, and parsed to obtain the query task text; The BERT pre-trained model is injected with the domain dictionary for fine-tuning and training to generate a keyword query network; Based on the keyword query network, natural language query is performed on the query task text to determine a set of candidate query keywords; The candidate query keyword set is sorted by importance and deduplicated to obtain the target task keywords.
6. The intelligent article generation method based on code library understanding as described in claim 1, characterized in that, Based on the dynamic knowledge graph of the code, graph path reasoning is performed on the keywords of the target task to determine the task code context knowledge set, including: Based on the dynamic knowledge graph of the code, a graph attention network layer is constructed. The graph attention network layer is used to perform graph path reasoning on the target task keywords to obtain task reasoning path information; Based on the task reasoning path information, the dynamic knowledge graph of the code is used to extract related knowledge to determine the task code context knowledge set.
7. The intelligent article generation method based on code library understanding as described in claim 6, characterized in that, Based on the dynamic knowledge graph of the code, a graph attention network layer is constructed, including: The attention coefficients of each node and its neighboring nodes in the dynamic knowledge graph of the code are calculated to obtain the knowledge node attention coefficient set. The attention coefficient set of the knowledge nodes is normalized to obtain a comparable attention coefficient set of knowledge nodes; The feature representations of neighboring nodes are weighted and summed based on the comparable knowledge node attention coefficient set to obtain the current node aggregate feature. The knowledge node feature representation is then updated using the current node aggregate feature to construct a graph attention network layer.
8. The intelligent article generation method based on code library understanding as described in claim 1, characterized in that, A large language model is used to generate article-level content from the task code context knowledge set, resulting in initial task article content, including: The task code context knowledge set is hierarchically structured into knowledge fragments and prompt words are designed to obtain hierarchical knowledge prompt word information; The large language model is used to generate article-level content based on the hierarchical knowledge prompt word information of the task code context knowledge set, so as to obtain the initial task article content.
9. The intelligent article generation method based on code library understanding as described in claim 1, characterized in that, The initial task article content is logically validated and optimized to generate the target task article content, including: The initial task article content is subjected to logical consistency verification and problem identification and location to obtain an article logical problem content report; Based on the article's logical problem content report, the logical structure of the initial task article content is optimized to generate the target task article content.
10. An intelligent article generation system based on code library understanding, characterized in that, The system is used to implement the intelligent article generation method based on code library understanding as described in any one of claims 1-9, and the system comprises: The knowledge graph generation module is used to perform normalization processing and multi-dimensional semantic extraction on the code library to obtain multi-dimensional semantic information of the code. Based on the multi-dimensional semantic information of the code, the module performs dynamic knowledge modeling on the code library to generate a dynamic knowledge graph of the code. The task keyword acquisition module is used to input the query task requirements, combine the domain dictionary, and use the BERT pre-trained model to perform natural language query on the query task requirements to obtain the target task keywords. The context knowledge set determination module is used to perform graph path reasoning on the target task keywords based on the code dynamic knowledge graph to determine the task code context knowledge set; The task article content generation module is used to generate article-level content from the task code context knowledge set using a large language model to obtain initial task article content, and to perform logical verification and optimization on the initial task article content to generate target task article content.