File generation method and device based on knowledge base, equipment and storage medium
Through the knowledge base-based file generation method, semantic feature extraction and knowledge base matching technology are used to solve the problems of low code reuse and insufficient generation accuracy in software engineering, and fast and accurate software code or document generation is achieved, improving development efficiency.
Patent Information
- Application Number
- CN202411882834.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-19
- Publication Date
- 2025-04-11
AI Technical Summary
In software engineering, due to the independent development of each source code module, the code reuse decreases and the increase in redundant code, hindering the development and maintenance efficiency. The existing technology uses large language models to generate code or documents, but the generation results are relatively accurate and fail to effectively improve development efficiency.
Using a knowledge base-based file generation method, software code or documents are quickly and accurately generated through semantic feature extraction, knowledge base matching and entity attribute data search. The method includes responding to file generation instructions, extracting the semantic features of the target file, matching the preset knowledge semantic feature library, searching for the knowledge graph database, and generating the target file based on the matching results.
It realizes the rapid and accurate generation of software code or documents, improves the software development efficiency of developers, and ensures the authenticity and accuracy of generated files.
Smart Images

Figure CN119808783A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of computer technology, and in particular, relates to a knowledge base-based file generation method, device, equipment and storage medium. Background Art
[0002] As software engineering projects become increasingly large, software development is often implemented in the form of teamwork. However, since each module of the source code is developed independently by developers, even if there is already code in the source code that can achieve the same function, the developers will rewrite the code to implement it, resulting in a decrease in code reuse and an increase in redundant code, which is not conducive to subsequent development and maintenance. In addition, the increasing number of codes and documents in software engineering has led to an increasingly complex logical structure of the software source code, hindering seamless collaboration and knowledge transfer between developers. It is becoming increasingly difficult for developers to understand the existing source code, which further leads to low software development efficiency.
[0003] In the prior art, there are also solutions that use large language models to generate files such as code or development documents in order to improve software development efficiency. However, the code or development documents generated in this way are often divorced from actual software engineering projects and have low accuracy, which is not effective in improving the development efficiency of developers. Summary of the invention
[0004] The present application provides a knowledge base-based file generation method, apparatus, device and storage medium, which can quickly and accurately generate code files such as software code or software documents, effectively improving the software development efficiency of developers.
[0005] On the one hand, an embodiment of the present application provides a method for generating a file based on a knowledge base, the method comprising:
[0006] In response to the file generation instruction, performing semantic feature extraction processing on the target file description text carried in the file generation instruction to obtain the semantic features of the target file;
[0007] Matching a target entity identifier corresponding to the semantic feature of the target file from a preset knowledge semantic feature library; the preset knowledge semantic feature library stores a first mapping relationship between preset entity semantic features and preset entity identifiers;
[0008] Finding a target knowledge node corresponding to the target entity identifier from a preset knowledge graph database, and obtaining target entity attribute data stored in the target knowledge node; the preset knowledge graph database stores a second mapping relationship between the preset knowledge node and the preset entity identifier; the preset knowledge node represents a preset knowledge entity; the preset knowledge node stores preset entity attribute data of the preset knowledge entity;
[0009] According to the file generation instruction and the target entity attribute data, a target file corresponding to the file generation instruction is generated.
[0010] In an exemplary embodiment, the method further comprises:
[0011] Get software source code;
[0012] Performing lexical analysis on the software source code to generate a sequence of grammatical elements;
[0013] Performing syntax analysis on the syntax element sequence to generate an abstract syntax tree; the syntax nodes of the abstract syntax tree represent syntax elements of the software source code;
[0014] Traversing the syntax nodes, extracting syntax elements corresponding to the traversed syntax nodes as the preset knowledge entities and acquiring the preset entity attribute data corresponding to the preset knowledge entities;
[0015] Determining the preset entity identifier corresponding to the preset knowledge entity according to the traversal order of the abstract syntax tree;
[0016] The preset knowledge graph database is constructed according to the preset entity identifier, the preset knowledge entity and the preset entity attribute data.
[0017] In an exemplary embodiment, there are multiple preset knowledge entities; constructing the preset knowledge graph database according to the preset entity identifier, the preset knowledge entity and the preset entity attribute data includes:
[0018] For each of the preset knowledge entities, determining the preset knowledge entity as the preset knowledge node in the preset knowledge graph database, and determining a second mapping relationship between the preset knowledge node and the preset entity identifier;
[0019] Inputting the preset entity attribute data corresponding to the preset knowledge entity into the large language model to perform entity attribute data description processing to generate a preset entity description sentence;
[0020] According to the second mapping relationship, storing the preset entity description statement and the preset entity attribute data in the preset knowledge node;
[0021] Determining a node association relationship between a plurality of the preset knowledge nodes according to a data association relationship between the preset entity attribute data;
[0022] The preset knowledge graph database is constructed according to the plurality of preset knowledge nodes and the node association relationships.
[0023] In an exemplary embodiment, the method further comprises:
[0024] Performing semantic feature extraction processing on the preset entity description sentence corresponding to the preset knowledge entity to obtain the preset entity semantic feature;
[0025] The preset knowledge semantic feature library is constructed according to the first mapping relationship between the preset entity identifier and the preset entity semantic feature corresponding to the same preset knowledge entity.
[0026] In an exemplary embodiment, the preset knowledge entity includes a directory knowledge entity and a code knowledge entity, and the inputting of the preset entity attribute data corresponding to the preset knowledge entity into a large language model for entity attribute data description processing to generate a preset entity description sentence includes:
[0027] Input the directory entity attribute data corresponding to the directory knowledge entity into the large language model for directory entity attribute data description processing to generate a directory entity description statement; the directory entity description statement includes the code module to which the directory knowledge entity belongs, the function description statement of the directory knowledge entity, the directory level of the directory knowledge entity, the code module to which the file contained in the directory knowledge entity belongs, the function description statement of the file, the code class description contained in the file and the interface function description statement;
[0028] Inputting the code entity attribute data corresponding to the code knowledge entity into the large language model to perform code entity attribute data description processing to generate a code entity description statement; the code entity description statement includes a function description statement of a function code;
[0029] The directory entity description statement and the code entity description statement are determined as the entity description statement.
[0030] In an exemplary embodiment, when the file generation instruction is a software document generation instruction, generating a target file corresponding to the file generation instruction according to the file generation instruction and the target entity attribute data includes:
[0031] Parsing the target file description text to obtain document content configuration information;
[0032] Generate a target software architecture diagram according to the document content configuration information and the target entity attribute data;
[0033] Inputting the software document generation instruction and the text information corresponding to the target software architecture diagram into the large language model for document generation processing to generate a target software document corresponding to the software document generation instruction;
[0034] When the file generation instruction is a software code generation instruction, generating a target file corresponding to the file generation instruction according to the file generation instruction and the target entity attribute data includes:
[0035] The software code generation instruction and the target entity attribute data are input into the large language model for code generation processing to generate target code corresponding to the software code generation instruction.
[0036] In an exemplary embodiment, the step of inputting the software document generation instruction and the text information corresponding to the target software architecture diagram into the large language model for document generation processing to generate a target software document corresponding to the software document generation instruction includes:
[0037] Obtaining a document generation template corresponding to the document content configuration information;
[0038] Inputting the software document generation instruction and the text information corresponding to the target software architecture diagram into the large language model to obtain the target software document sentence;
[0039] The target software document statements, the target software architecture diagram and the target entity attribute data are generated according to the document generation template to generate the target software document.
[0040] On the other hand, the present application also provides a knowledge base-based file generation device, the device comprising:
[0041] An instruction semantic feature extraction module is used to perform semantic feature extraction processing on a target file description text carried in the file generation instruction in response to the file generation instruction to obtain a semantic feature of the target file;
[0042] A knowledge semantic feature library matching module, used to match a target entity identifier corresponding to the semantic feature of the target file from a preset knowledge semantic feature library; the preset knowledge semantic feature library stores a first mapping relationship between preset entity semantic features and preset entity identifiers;
[0043] A knowledge graph database search module, used to search for a target knowledge node corresponding to the target entity identifier from a preset knowledge graph database, and obtain the target entity attribute data stored in the target knowledge node; the preset knowledge graph database stores a second mapping relationship between the preset knowledge node and the preset entity identifier; the preset knowledge node represents a preset knowledge entity; the preset knowledge node stores preset entity attribute data of the preset knowledge entity;
[0044] The target file generation module is used to generate a target file corresponding to the file generation instruction according to the file generation instruction and the target entity attribute data.
[0045] On the other hand, the present application also provides an electronic device, comprising a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or the at least one program is loaded and executed by the processor to implement the knowledge base-based file generation method as described above.
[0046] On the other hand, the present application also provides a computer storage medium, which stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by a processor to implement the knowledge base-based file generation method as described above.
[0047] On the other hand, the present application also provides a computer program product or a computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes to implement the knowledge base-based file generation method as described above.
[0048] The knowledge base-based document generation method provided in this application has the following technical effects:
[0049] The knowledge base in the embodiment of the present application includes a preset knowledge semantic feature library and a preset knowledge graph database, so as to quickly and accurately generate the required target file according to the developer's instructions. Specifically, the present application responds to the file generation instruction, performs semantic feature extraction processing on the target file description text carried in the file generation instruction, and obtains the target file semantic feature; matches the target entity identifier corresponding to the target file semantic feature from the preset knowledge semantic feature library; then, finds the target knowledge node corresponding to the target entity identifier from the preset knowledge graph database, and obtains the target entity attribute data stored in the target knowledge node; the present application first extracts the semantic feature of the target file description text, and through semantic feature matching, the accuracy and efficiency of matching can be improved, and then uses the target entity identifier obtained by matching to find the target entity attribute data related to the target file description text from the preset knowledge graph database, thereby improving the search efficiency. Then, according to the file generation instruction and the target entity attribute data, the target file is generated, so that the generation process of the target file can always be based on the data in the real knowledge base, effectively improving the accuracy of file generation. Therefore, the method provided in the embodiment of the present application can quickly and accurately generate code files such as software code or software documents, effectively improving the software development efficiency of developers. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0051] Figure 1 It is an application environment diagram of the knowledge base-based file generation method provided in an embodiment of the present application;
[0052] Figure 2 It is a schematic diagram of a knowledge base-based document generation process provided in an embodiment of the present application;
[0053] Figure 3 It is a schematic diagram of the process of building a preset knowledge graph database provided in an embodiment of the present application;
[0054] Figure 4 It is a schematic diagram of a process for constructing a preset knowledge semantic feature library provided in an embodiment of the present application;
[0055] Figure 5 It is a schematic diagram of the process of generating a target file provided by an embodiment of the present application;
[0056] Figure 6 It is an overall flow chart of the knowledge base-based file generation method provided in an embodiment of the present application;
[0057] Figure 7 It is a structural schematic diagram of a knowledge base-based file generation device provided in an embodiment of the present application;
[0058] Figure 8 It is a hardware structure block diagram of a server of a knowledge base-based file generation method provided in an embodiment of the present application. DETAILED DESCRIPTION
[0059] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0060] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or server that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0061] Figure 1 It is an application environment diagram of the knowledge base-based file generation method provided in an embodiment of the present application.
[0062] like Figure 1 As shown, the application environment may at least include a server 01 and a terminal device 02 .
[0063] In an optional embodiment, the server 01 can be used to perform file generation processing in response to a file generation instruction issued by the terminal device 02. The server 01 can store a pre-built preset knowledge semantic feature library and a preset knowledge graph database for semantic feature matching and entity attribute data search. The server 01 can be an independent physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server that provides cloud computing services.
[0064] In an optional embodiment, the terminal device 02 can be used to write files such as software code or software documents. Developers can initiate file generation instructions based on the terminal device 02. Specifically, the terminal device 02 may include but is not limited to smart phones, desktop computers, tablet computers, laptops, smart speakers, digital assistants, augmented reality (AR) / virtual reality (VR) devices, smart wearable devices, vehicle terminals, smart TVs and other types of electronic devices; it can also be software running on the above electronic devices, such as applications, applets, etc. The operating system running on the electronic device in the embodiment of the present application may include but is not limited to Android system, IOS system, Linux, Windows, etc.
[0065] Figure 2 It is a schematic diagram of the knowledge base-based file generation process provided in an embodiment of the present application.
[0066] S201: In response to a file generation instruction, a semantic feature extraction process is performed on a target file description text carried in the file generation instruction to obtain a semantic feature of the target file.
[0067] File generation instructions can be given by developers in Figure 1 The target file description text is input on the terminal device 02 shown to initiate. The file generation instruction carries the target file description text. The target file description text is a natural language text, which is used to reflect the file generation needs of the developer. For example, the target file description text can be "a function that implements the following functions: copy continuous data of a specified size in the memory from the memory space to the user space, and return whether the copy is successful or failed", etc. Based on the target file description text, the corresponding file generation instruction can be generated. In the above example, the type of the file generation instruction is the code generation instruction. In addition, the type of the file generation instruction can also include a software document generation instruction, or other types of generation instructions. This application does not limit the specific content of the target file description text and the specific type of the file generation instruction.
[0068] The semantic feature extraction process may be to vectorize the target file description text, for example, to form a 1024-dimensional vector. The present application does not limit the specific method of semantic feature extraction.
[0069] S203: matching a target entity identifier corresponding to the semantic feature of the target file from a preset knowledge semantic feature library;
[0070] The preset knowledge semantic feature library stores a first mapping relationship between preset entity semantic features and preset entity identifiers.
[0071] The preset entity identifier can represent the uniqueness of the preset entity semantic feature, and can also represent the uniqueness of the preset knowledge entity corresponding to the preset entity semantic feature. For example, the preset entity identifier corresponding to the preset entity semantic feature aa of the preset knowledge entity A can be 1, and the preset entity identifier corresponding to the preset entity semantic feature bb of the preset knowledge entity B can be 2, etc. The preset knowledge entity includes but is not limited to directory structure, package definition, class definition, macro definition, type definition, global variable, function definition, etc.
[0072] It should be noted that the preset knowledge semantic feature library is pre-built. In the application stage, the semantic features of the target file are directly matched with the preset entity semantic features stored in the preset knowledge semantic feature library, so as to determine the preset entity semantic features with the highest matching degree, and determine the preset entity identifier corresponding to the preset entity semantic features as the target entity identifier. Among them, the matching degree can be understood as the similarity. By calculating the similarity between the semantic features of the target file and each preset entity semantic feature in the preset knowledge semantic feature library, and then determining the preset entity semantic features whose similarity meets the preset matching conditions as the target entity semantic features, and obtaining the target entity identifier corresponding to the target entity semantic features, the target entity semantic features corresponding to the target file description text and the corresponding target entity identifier can be screened out. Still taking the example of step S201 as an example, assuming that the preset entity semantic features representing the function of copying memory are stored in the preset knowledge semantic feature library, the preset entity semantic features can be screened out as the target entity semantic features after the above matching process, and the target entity identifier is obtained according to the first mapping relationship in the preset knowledge semantic feature library.
[0073] S205: Finding a target knowledge node corresponding to the target entity identifier from a preset knowledge graph database, and obtaining target entity attribute data stored in the target knowledge node;
[0074] Among them, the preset knowledge graph database stores a second mapping relationship between preset knowledge nodes and preset entity identifiers; the preset knowledge nodes represent preset knowledge entities; and the preset knowledge nodes store preset entity attribute data of the preset knowledge entities.
[0075] It should be noted that the preset knowledge graph database is pre-built. Among them, the preset entity identifiers in the preset knowledge graph database correspond to the preset entity identifiers in the preset knowledge semantic feature library. Since the preset entity identifier can also represent the uniqueness of the preset knowledge entity corresponding to the preset entity semantic feature, the preset knowledge entity in the preset knowledge graph database and the corresponding preset knowledge entity in the preset knowledge semantic feature library also correspond to the same.
[0076] The preset entity attribute data is the attributes of the preset knowledge entity, including but not limited to the directory hierarchy, whether it is a root directory, whether it is a leaf directory, the package name, the dependent packages corresponding to the package, class member variables, class methods, the scope of macro definitions, the original type and scope of type definitions, the type and scope of global variables, function parameters and types, return value type, dependent macro definitions and global variables, etc.
[0077] The preset knowledge graph database can be understood as a knowledge graph, in which each preset knowledge node represents a preset knowledge entity, and the association between the preset knowledge nodes represents the association between the preset knowledge entities, which can be attributes or relationships. For example, if preset knowledge entity A contains preset knowledge entity B, a triple such as preset knowledge entity A-contains-preset knowledge entity B can be formed, thereby forming a knowledge graph database.
[0078] By further searching according to the target entity identifier, all information of the target knowledge node and related nodes associated with the target knowledge node can be obtained.
[0079] Compared with the traditional solution of searching for target entity attribute data corresponding to the target file description text based on text fuzzy search, this application uses semantic feature matching to perform queries. First, the target entity identifier is obtained, and then the preset knowledge graph database is queried. The query speed is faster and the accuracy is higher.
[0080] S207: Generate a target file corresponding to the file generation instruction according to the file generation instruction and the target entity attribute data.
[0081] The target entity attribute data found can provide data support for generating the target file, thereby ensuring the authenticity and accuracy of the target file.
[0082] The knowledge base in the embodiment of the present application includes a preset knowledge semantic feature library and a preset knowledge graph database, so as to quickly and accurately generate the required target file according to the developer's instructions. Specifically, the present application responds to the file generation instruction, performs semantic feature extraction processing on the target file description text carried in the file generation instruction, and obtains the target file semantic feature; matches the target entity identifier corresponding to the target file semantic feature from the preset knowledge semantic feature library; then, finds the target knowledge node corresponding to the target entity identifier from the preset knowledge graph database, and obtains the target entity attribute data stored in the target knowledge node; the present application first extracts the semantic feature of the target file description text, and through semantic feature matching, the accuracy and efficiency of matching can be improved, and then uses the target entity identifier obtained by matching to find the target entity attribute data related to the target file description text from the preset knowledge graph database, thereby improving the search efficiency. Then, according to the file generation instruction and the target entity attribute data, the target file is generated, so that the generation process of the target file can always be based on the data in the real knowledge base, effectively improving the accuracy of file generation. Therefore, the method provided in the embodiment of the present application can quickly and accurately generate code files such as software code or software documents, effectively improving the software development efficiency of developers.
[0083] Figure 3Schematic diagram of the process of constructing a preset knowledge graph database provided in the embodiment of the present application. Figure 3 As shown, the method includes:
[0084] S301: Obtain software source code;
[0085] The software source code can be the source code of a completed software engineering project, or it can be the existing source code in a software engineering project under development.
[0086] S303: Performing lexical analysis on the software source code to generate a grammatical element sequence;
[0087] Lexical analysis reads the software source code character stream and then merges it into tokens according to predetermined rules. At the same time, whitespace, comments, etc. are removed to form a sequence of grammatical elements. For example, the source code "const a=5;" can be converted into a sequence of grammatical elements such as "[{value:'const',type:'keyword'},{value:'a',type:'identifier'},...]" through this method.
[0088] S305: Performing syntax analysis on the syntax element sequence to generate an abstract syntax tree;
[0089] Wherein, the syntax nodes of the abstract syntax tree represent syntax elements of the software source code;
[0090] Next, the basic syntax structure of the source code is analyzed according to the syntax rules of the analyzed language, and converted into a tree form to form an abstract syntax tree. Each syntax node of the abstract syntax tree represents a structure in the source code, including but not limited to methods, variables, expressions and other components that make up the software source code.
[0091] S307: traversing the syntax nodes, extracting syntax elements corresponding to the traversed syntax nodes as the preset knowledge entities and acquiring the preset entity attribute data corresponding to the preset knowledge entities;
[0092] Since the abstract syntax tree is structural and contains all the information of the software source code, it is traversed and, during the traversal process, extraction operations are performed on each syntax node, such as collecting variable names, function calls, type information, etc., so that the syntax elements in the software source code can be extracted as knowledge entities. The knowledge entities include but are not limited to directory structure, package definition, class definition, macro definition, type definition, global variables, and function definition; and entity attribute data corresponding to the knowledge entities are obtained, including but not limited to directory hierarchy, whether it is a root directory, whether it is a leaf directory, package name, dependent packages corresponding to the package, class member variables, class methods, scope of macro definition, original type and scope of type definition, type and scope of global variables, function parameters and types, return value type, dependent macro definitions and global variables, etc.
[0093] It should be noted that, since the amount of software source code is often very large, it will be organized into different files and placed in different folders for easy management. Therefore, the software source code will also form a hierarchical directory structure, for example, the root directory contains folder A and file B, and folder A contains file A1 and file A2. Therefore, when constructing the abstract syntax tree, this application also constructs the hierarchical structure of directories and files, so that directories and files can be extracted as knowledge entities during traversal, and the hierarchical relationship between directories and files is used as the entity attribute data of the corresponding knowledge entity.
[0094] S309: Determine the preset entity identifier corresponding to the preset knowledge entity according to the traversal order of the abstract syntax tree;
[0095] It should be noted that the preset entity identifier is used to characterize the uniqueness of the preset knowledge entity. In one implementation, the traversal order of the abstract syntax tree can be used as the preset entity identifier of each preset knowledge entity. This application does not limit the specific traversal order of the abstract syntax tree.
[0096] S311: Constructing the preset knowledge graph database according to the preset entity identifier, the preset knowledge entity and the preset entity attribute data.
[0097] There is a one-to-one correspondence between the preset entity identifier and the preset knowledge entity, and the preset knowledge entity also corresponds one-to-one to the preset entity attribute data. In addition, there are association relationships such as inclusion and calling between different preset knowledge entities. Therefore, a preset knowledge graph database can be constructed based on the preset entity identifier, preset knowledge entity and preset entity attribute data.
[0098] The embodiment of the present application performs lexical analysis and syntactic analysis on the software source code to form an abstract syntax tree corresponding to the software source code, and extracts the corresponding preset knowledge entities and preset entity attribute data in the software source code by traversing the abstract syntax tree, so that the constructed preset knowledge graph database can be more complete and accurate, avoiding the omission of preset knowledge entities.
[0099] It should be noted that there are multiple preset knowledge entities; in one embodiment, constructing the preset knowledge graph database according to the preset entity identifier, the preset knowledge entity and the preset entity attribute data may include:
[0100] For each of the preset knowledge entities, determining the preset knowledge entity as the preset knowledge node in the preset knowledge graph database, and determining a second mapping relationship between the preset knowledge node and the preset entity identifier;
[0101] Inputting the preset entity attribute data corresponding to the preset knowledge entity into the large language model to perform entity attribute data description processing to generate a preset entity description sentence;
[0102] Large Language Model (LLM), also known as large language model, is an artificial intelligence language model designed to understand and generate human language. They are trained on a large amount of text data and can perform a wide range of tasks. The large language model in this application can be a trained general large language model, or it can be obtained by fine-tuning the trained general large language model using training data. Among them, the training data can be information such as knowledge entities and entity description statements in the knowledge base of other software engineering projects that have been established, such as a knowledge base established for the Linux operating system.
[0103] By inputting the preset entity attribute data corresponding to the preset knowledge entity into the large language model and combining it with a guide word (prompt), a natural language description text of the preset entity attribute data, namely, a preset entity description sentence, is output.
[0104] According to the second mapping relationship, storing the preset entity description statement and the preset entity attribute data in the preset knowledge node;
[0105] Since the preset entity description statement and the preset entity attribute data both correspond to the preset knowledge entity, according to the second mapping relationship, a mapping relationship can be established between the preset entity identifier and the preset entity description statement of the preset knowledge entity and the preset entity attribute data, so as to facilitate the search for entity attribute data according to the target entity identifier in the subsequent application stage.
[0106] Determining a node association relationship between a plurality of the preset knowledge nodes according to a data association relationship between the preset entity attribute data;
[0107] Since the preset entity attribute data can reflect the attributes or relationships of the preset knowledge entity, the node association relationship between the preset knowledge nodes can be determined based on the preset entity attribute data. For example, based on the parent-child relationship of the directory, the files contained in the directory, which directory the file belongs to, which packages, classes, macros, global variables, and function definitions are in the file, in which file or package the class, macro, global variable, and function are defined, which class objects are used in the function, the calling relationship between functions, etc., the node association relationship between the preset knowledge nodes can be determined.
[0108] The preset knowledge graph database is constructed according to the plurality of preset knowledge nodes and the node association relationships.
[0109] Through the above-mentioned node association relationship, the triplet of "entity-relationship-entity" can be determined, thereby obtaining a network relationship graph, which is the preset knowledge graph database in this application.
[0110] The embodiment of the present application outputs the natural language description text of entity attribute data through a large language model and stores it in the corresponding preset knowledge node, thereby enriching the storage content of the preset knowledge graph database, so as to provide developers with richer and easier to understand source code knowledge in the future, which is conducive to improving development efficiency.
[0111] Figure 4 Schematic diagram of the process of constructing a preset knowledge semantic feature library provided by the embodiment of the present application. Figure 4 As shown, the method includes:
[0112] S401: performing semantic feature extraction processing on the preset entity description sentence corresponding to the preset knowledge entity to obtain the preset entity semantic feature;
[0113] Semantic feature extraction may be text vectorization of the preset entity description sentence. It should be noted that the semantic feature extraction method in step S401 is the same as that in step S201, so as to ensure the accuracy of semantic matching.
[0114] S403: constructing the preset knowledge semantic feature library according to the first mapping relationship between the preset entity identifier and the preset entity semantic feature corresponding to the same preset knowledge entity.
[0115] Since the preset entity description statement corresponds to the preset knowledge entity, the preset entity semantic feature also corresponds to the preset knowledge entity. Then, based on the correspondence between the preset knowledge entity and the preset entity identifier, a mapping relationship between the preset entity identifier and the preset entity semantic feature is established, that is, the first mapping relationship, to obtain a preset knowledge semantic feature library.
[0116] It should be noted that semantic features may also be extracted from the function source code and comments, and the obtained semantic feature extraction results may be saved in correspondence with the preset entity identifier corresponding to the function (preset knowledge entity).
[0117] The embodiment of the present application realizes the construction of a preset knowledge semantic feature library by saving preset entity semantic features corresponding to preset knowledge entities, so as to facilitate subsequent feature matching and improve matching accuracy and matching speed.
[0118] It should be noted that the preset knowledge entity includes a directory knowledge entity and a code knowledge entity, and the inputting of the preset entity attribute data corresponding to the preset knowledge entity into the large language model for entity attribute data description processing to generate a preset entity description statement includes:
[0119] Input the directory entity attribute data corresponding to the directory knowledge entity into the large language model for directory entity attribute data description processing to generate a directory entity description statement; the directory entity description statement includes the code module to which the directory knowledge entity belongs, the function description statement of the directory knowledge entity, the directory level of the directory knowledge entity, the code module to which the file contained in the directory knowledge entity belongs, the function description statement of the file, the code class description contained in the file and the interface function description statement;
[0120] In this application, the attribute data of the directory path, directory name and file content contained in the directory of the directory knowledge entity are input into the large language model, and the large language model is guided by the guide words to generate a text description of the directory knowledge entity.
[0121] Inputting the code entity attribute data corresponding to the code knowledge entity into the large language model to perform code entity attribute data description processing to generate a code entity description statement; the code entity description statement includes a function description statement of a function code;
[0122] In this application, for the code knowledge entity of function, the attribute data such as function source code and function annotation corresponding to the function are input into the large language model, and the guide words are used to guide the large language model to generate a functional text description of the code knowledge entity.
[0123] The directory entity description statement and the code entity description statement are determined as the entity description statement.
[0124] The embodiment of the present application uses a large language model to output corresponding text descriptions for directory knowledge entities and code knowledge entities respectively, thereby enriching the storage content of the preset knowledge graph database and providing a corpus basis for constructing a preset knowledge semantic feature library.
[0125] It should be noted that in this application, when an update of the software source code is detected, including code and document modification, deletion, and addition operations, the preset knowledge semantic feature library and the preset knowledge graph database are triggered to perform update operations to ensure the real-time nature of the knowledge base. In addition, the preset knowledge semantic feature library and the preset knowledge graph database can also be updated regularly according to a preset time period to ensure the real-time nature of the knowledge base.
[0126] After the knowledge base is built, the information in the knowledge base can be obtained through matching, and the knowledge in the knowledge base can be inferred according to the developer's demand instructions to dig out deeper connections, thereby generating files corresponding to the demand instructions.
[0127] Figure 5 : is a flow chart of generating a target file provided by an embodiment of the present application. It should be noted that the file generation instruction can be multiple types of instructions for realizing the generation of different types of files. For example, when the file generation instruction is a software document generation instruction, the target file can include a target software document; when the file generation instruction is a software code generation instruction, the target file can include a target code. The file generation instruction can also be other types, which can be determined according to the actual needs of the developer.
[0128] In one embodiment, Figure 5 As shown, when the file generation instruction is a software document generation instruction, generating a target file corresponding to the file generation instruction according to the file generation instruction and the target entity attribute data may include:
[0129] S511: Parse the target file description text to obtain document content configuration information;
[0130] The document content configuration information can describe the scope of the document content that developers need to generate, for example, generating the overall architecture design document of the software source code, the memory module design document, the display module description document, etc.
[0131] In one implementation, the document content configuration information may be manually input by a developer. In another implementation, the developer may select a content range to be generated through a visual interface to obtain the document content configuration information.
[0132] S513: Generate a target software architecture diagram according to the document content configuration information and the target entity attribute data;
[0133] Through the attribute data query process of the above embodiment, the target entity attribute data corresponding to the software document generation instruction can be obtained, and then the target software architecture diagram can be output using a visualization tool. It should be noted that the target software architecture diagram in this application is output according to the document content configuration information, and the target software architecture diagram includes but is not limited to an engineering architecture diagram, a flow chart, an activity diagram, a package diagram, etc. In an example, assuming that the developer needs to view the memory management module of the software source code, the memory management module can be selected in the visualization interface, and all functions, classes, macro definitions, global variables contained in the memory management module are output according to the queried target entity attribute data, as well as the call, inclusion, use, modification and other relationships between these target knowledge nodes to obtain the target software architecture diagram. The target software architecture diagram can assist developers in having a simpler and clearer understanding of the code architecture and control flow.
[0134] S515: Input the software document generation instruction and the text information corresponding to the target software architecture diagram into the large language model for document generation processing, and generate a target software document corresponding to the software document generation instruction.
[0135] The target software documents include but are not limited to software architecture design, software detailed design specifications, etc., and are determined based on actual software document generation instructions.
[0136] In one embodiment, the step of inputting the software document generation instruction and the text information corresponding to the target software architecture diagram into the large language model for document generation processing to generate a target software document corresponding to the software document generation instruction may include:
[0137] Obtaining a document generation template corresponding to the document content configuration information;
[0138] In one implementation, the document generation template may be pre-set and have a corresponding relationship with the document content configuration information, thereby facilitating the rapid determination of the document generation template. In another implementation, the document generation template may also be specified by the developer in the document generation instruction.
[0139] The software document generation instructions and the text information corresponding to the target software architecture diagram are input into the large language model to obtain the target software document statements; the target software document statements can be understood as natural text descriptions of the overall process, modules, and modules.
[0140] In one implementation, the target entity attribute data and the text information corresponding to the target software architecture diagram can be obtained through the query interface and returned to the large language model in JavaScript Object Notation (JSON) data format. JSON is an open standard file format and data exchange format that is easy to read and write, and is also easy to machine parse and generate.
[0141] The target software document statements, the target software architecture diagram and the target entity attribute data are generated according to the document generation template to generate the target software document.
[0142] The target software document statements generated by the large language model can be filled in the corresponding positions in the document generation template. At the same time, the target entity attribute data queried from the knowledge base, that is, the attribute information of the directory, file, and function, can be filled in the corresponding positions in the document generation template, and the generated target software architecture diagram can be filled in the corresponding positions in the document generation template to obtain the target software document.
[0143] The embodiment of the present application queries the target entity attribute data from the knowledge base, establishes the target software architecture diagram, and inputs it into the large language model together with the software document generation instructions, thereby assisting the large language model to generate software documents with higher accuracy.
[0144] In one embodiment, Figure 5 As shown, when the file generation instruction is a software code generation instruction, generating a target file corresponding to the file generation instruction according to the file generation instruction and the target entity attribute data may include:
[0145] S521: Input the software code generation instruction and the target entity attribute data into the large language model for code generation processing to generate target code corresponding to the software code generation instruction.
[0146] The target entity attribute data can provide a real reference for the large language model when generating code, thereby improving the accuracy of the target code, reducing the errors and defects of the target code, which is beneficial to the stability and reliability of the target code, and also helps developers improve development efficiency and quality.
[0147] The target entity attribute data provided by the knowledge base in the embodiment of the present application can provide professional knowledge and actual data to the large language model, and assist the large language model to accurately generate the target file corresponding to the file generation instruction. Through this fusion, the large language model can better understand and handle complex code problems, and improve the accuracy and efficiency of code-related file generation. In addition, the present application further distinguishes between document generation instructions and software code generation instructions, so as to generate target software documents and target codes respectively according to requirements. And further, when generating the target software document, a visual target software architecture diagram is introduced, so that the content of the target software document is richer, which is conducive to intuitively displaying the structure of the software source code, and is convenient for developers to quickly understand the source code, thereby improving development efficiency.
[0148] Figure 6 is an overall flow chart of the knowledge base-based file generation method provided in the embodiment of the present application. Figure 6 As shown in the figure, the source code and documents of software engineering are used as input data, the knowledge entities in the code and documents are extracted, and the attributes and relationships of each node are constructed into a graph database; this process can be regarded as Figure 3 A specific example of the embodiment shown in the figure; the corresponding semantics of knowledge entities are generated through a large language model and stored in the nodes of the graph database. Then, the text semantics of functions, files, and folders are vectorized through text embedding and stored in the vector database; this process can be regarded as Figure 4 A specific example of the illustrated embodiment. The graph database and the vector database are associated through the unique identifier (ID) of the knowledge entity; thereby forming a code knowledge base. Developers can form instructions by inputting the requirement description, which is vectorized and matched with the existing data in the vector database. According to the unique identifier of the data with the highest matching degree, all information of the knowledge node and related nodes can be obtained from the graph database, thereby achieving accurate matching and breadth relationship of the query information. After that, the queried information can be used as the input of the large language model, and the corresponding software code, software document and other target files can be generated according to the specific requirement description of the instruction. In addition, the queried information can also be used as the query library of the visualization tool to generate a software code structure diagram, thereby assisting developers in understanding the code and embedding it into the target software document.
[0149] In addition, based on the constructed code knowledge base, in addition to the above-mentioned code generation and document generation, code similarity search, code assistance, code completion and other functions can also be performed to help developers improve software development efficiency. Through the code knowledge base, developers can build logical relationships and potential connections between key resources such as project code, documents, and test scripts, and achieve seamless collaboration and knowledge transfer between developers. In addition, the large language model can obtain rich code-related knowledge and experience from the code knowledge base, thereby improving its accuracy and efficiency in processing code-related natural language tasks.
[0150] Figure 7 It is a structural diagram of a knowledge base-based file generation device provided in an embodiment of the present application.
[0151] like Figure 7 As shown, the device 700 includes:
[0152] The instruction semantic feature extraction module 701 is used to perform semantic feature extraction processing on the target file description text carried in the file generation instruction in response to the file generation instruction to obtain the semantic features of the target file;
[0153] The knowledge semantic feature library matching module 702 is used to match the target entity identifier corresponding to the semantic feature of the target file from the preset knowledge semantic feature library; the preset knowledge semantic feature library stores a first mapping relationship between the preset entity semantic feature and the preset entity identifier;
[0154] The knowledge graph database search module 703 is used to search for a target knowledge node corresponding to the target entity identifier from a preset knowledge graph database, and obtain the target entity attribute data stored in the target knowledge node; the preset knowledge graph database stores a second mapping relationship between the preset knowledge node and the preset entity identifier; the preset knowledge node represents a preset knowledge entity; the preset knowledge node stores preset entity attribute data of the preset knowledge entity;
[0155] The target file generation module 704 is used to generate a target file corresponding to the file generation instruction according to the file generation instruction and the target entity attribute data.
[0156] In some embodiments, the apparatus 700 may further include:
[0157] Code acquisition module, used to obtain software source code;
[0158] A lexical analysis module, used for performing lexical analysis on the software source code to generate a sequence of grammatical elements;
[0159] A syntax analysis module, used for performing syntax analysis on the syntax element sequence to generate an abstract syntax tree; the syntax nodes of the abstract syntax tree represent the syntax elements of the software source code;
[0160] An entity extraction module, used for traversing the syntax nodes, extracting syntax elements corresponding to the traversed syntax nodes as the preset knowledge entities and obtaining the preset entity attribute data corresponding to the preset knowledge entities;
[0161] An identifier determination module, used to determine the preset entity identifier corresponding to the preset knowledge entity according to the traversal order of the abstract syntax tree;
[0162] The knowledge graph database construction module is used to construct the preset knowledge graph database according to the preset entity identifier, the preset knowledge entity and the preset entity attribute data.
[0163] In some embodiments, there are multiple preset knowledge entities; the knowledge graph database construction module may include:
[0164] A node determination submodule, for determining, for each of the preset knowledge entities, the preset knowledge entity as the preset knowledge node in the preset knowledge graph database, and determining a second mapping relationship between the preset knowledge node and the preset entity identifier;
[0165] An entity description statement generation submodule, used for inputting the preset entity attribute data corresponding to the preset knowledge entity into the large language model to perform entity attribute data description processing and generate a preset entity description statement;
[0166] A data storage submodule, configured to store the preset entity description statement and the preset entity attribute data in the preset knowledge node according to the second mapping relationship;
[0167] A node association relationship determination submodule, used to determine the node association relationship between the plurality of preset knowledge nodes according to the data association relationship between the preset entity attribute data;
[0168] The knowledge graph database construction submodule is used to construct the preset knowledge graph database based on multiple preset knowledge nodes and the node association relationships.
[0169] In some embodiments, the apparatus may further include:
[0170] An entity semantic feature extraction module is used to perform semantic feature extraction processing on the preset entity description sentence corresponding to the preset knowledge entity to obtain the preset entity semantic feature;
[0171] The knowledge semantic feature library construction module is used to construct the preset knowledge semantic feature library according to the first mapping relationship between the preset entity identifier and the preset entity semantic feature corresponding to the same preset knowledge entity.
[0172] In some embodiments, the preset knowledge entity includes a directory knowledge entity and a code knowledge entity, and the entity description statement generation submodule may include:
[0173] A directory entity description statement generating unit, used for inputting directory entity attribute data corresponding to the directory knowledge entity into the large language model to perform directory entity attribute data description processing, and generating a directory entity description statement; the directory entity description statement includes a code module to which the directory knowledge entity belongs, a function description statement of the directory knowledge entity, a directory level of the directory knowledge entity, a code module to which a file contained in the directory knowledge entity belongs, a function description statement of the file, a code class description contained in the file, and an interface function description statement;
[0174] A code entity description statement generating unit, used for inputting the code entity attribute data corresponding to the code knowledge entity into the large language model to perform code entity attribute data description processing and generate a code entity description statement; the code entity description statement includes a function description statement of a function code;
[0175] The entity description statement determining unit is used to determine the directory entity description statement and the code entity description statement as the entity description statement.
[0176] In some embodiments, the target file generation module may include:
[0177] A text parsing submodule, used to parse the target file description text to obtain document content configuration information;
[0178] A software architecture diagram generation submodule, used to generate a target software architecture diagram according to the document content configuration information and the target entity attribute data;
[0179] A document generation submodule, used for inputting the software document generation instruction and the text information corresponding to the target software architecture diagram into the large language model for document generation processing, and generating a target software document corresponding to the software document generation instruction;
[0180] In some embodiments, the target file generation module may further include:
[0181] The code generation submodule is used to input the software code generation instruction and the target entity attribute data into the large language model for code generation processing, and generate target code corresponding to the software code generation instruction.
[0182] In some embodiments, the document generation submodule may include:
[0183] A document generation template acquisition unit, used to acquire a document generation template corresponding to the document content configuration information;
[0184] A target software document statement generating unit, used for inputting the software document generating instruction and the text information corresponding to the target software architecture diagram into the large language model to obtain a target software document statement;
[0185] The target software document generation unit is used to generate the target software document according to the target software document statement, the target software architecture diagram and the target entity attribute data according to the document generation template.
[0186] The device and method embodiments in the described device embodiments are based on the same inventive concept.
[0187] An embodiment of the present application provides an electronic device, which includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by the processor to implement the method provided in the above method embodiment.
[0188] An embodiment of the present application also provides a computer storage medium, which can be set in a terminal to store at least one instruction or at least one program related to a method provided in the above method embodiment for implementing a method embodiment, and the at least one instruction or at least one program is loaded and executed by the processor to implement the method provided in the above method embodiment.
[0189] The embodiments of the present application also provide a computer program product or a computer program, which includes computer instructions stored in a computer-readable storage medium. The processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes to implement the method provided in the above method embodiment.
[0190] Optionally, in the embodiment of the present application, the storage medium may be located in at least one of the multiple network servers of the computer network. Optionally, in the present embodiment, the storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store program codes.
[0191] The memory described in the embodiment of the present application can be used to store software programs and modules, and the processor executes various functional applications and data processing by running the software programs and modules stored in the memory. The memory may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, application programs required for functions, etc.; the data storage area may store data created according to the use of the device, etc. In addition, the memory may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage device. Accordingly, the memory may also include a memory controller to provide the processor with access to the memory.
[0192] The method provided in the embodiment of the present application can be executed in a mobile terminal, a computer terminal, a server or a similar computing device. Taking running on a server as an example, Figure 8 1 is a hardware structure block diagram of a server of a knowledge base-based file generation method provided in an embodiment of the present application. Figure 8 As shown, the server 800 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPU) 810 (the central processing unit 810 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 830 for storing data, and one or more storage media 820 (such as one or more mass storage devices) for storing application programs 823 or data 822. Among them, the memory 830 and the storage medium 820 can be short-term storage or permanent storage. The program stored in the storage medium 820 may include one or more modules, each of which may include a series of instruction operations on the server. Furthermore, the central processing unit 810 can be configured to communicate with the storage medium 820 and execute a series of instruction operations in the storage medium 820 on the server 800. The server 800 may also include one or more power supplies 860, one or more wired or wireless network interfaces 850, one or more input and output interfaces 840, and / or one or more operating systems 821, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, etc.
[0193] The input / output interface 840 may be used to receive or send data via a network. The specific example of the network may include a wireless network provided by a communication provider of the server 800. In one example, the input / output interface 840 includes a network adapter (Network Interface Controller, NIC), which may be connected to other network devices via a base station so as to communicate with the Internet. In one example, the input / output interface 840 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0194] It can be understood by those skilled in the art that Figure 8 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 8 More or fewer components as shown, or with Figure 8 Different configurations are shown.
[0195] It can be seen from the embodiments of the file generation method, device, equipment and storage medium based on the knowledge base provided by the above-mentioned application that the knowledge base in the embodiment of the present application includes a preset knowledge semantic feature library and a preset knowledge graph database, so as to quickly and accurately generate the required target file according to the instructions of the developer. Specifically, in response to the file generation instruction, the present application performs semantic feature extraction processing on the target file description text carried in the file generation instruction to obtain the target file semantic feature; matches the target entity identifier corresponding to the target file semantic feature from the preset knowledge semantic feature library; then, finds the target knowledge node corresponding to the target entity identifier from the preset knowledge graph database, and obtains the target entity attribute data stored in the target knowledge node; the present application first extracts the semantic feature of the target file description text, and through semantic feature matching, the accuracy and efficiency of matching can be improved, and then the target entity identifier obtained by matching is used to find the target entity attribute data related to the target file description text from the preset knowledge graph database, thereby improving the search efficiency. Then, according to the file generation instruction and the target entity attribute data, the target file is generated, so that the generation process of the target file can always be based on the data in the real knowledge base, effectively improving the accuracy of file generation. Therefore, the method provided in the embodiment of the present application can quickly and accurately generate code files such as software code or software documents, effectively improving the software development efficiency of developers.
[0196] It should be noted that the above-mentioned sequence of the embodiments of the present application is for description only and does not represent the advantages and disadvantages of the embodiments. The above-mentioned specific embodiments of this specification are described. Other embodiments are within the scope of the attached claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0197] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device, equipment, and storage medium embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0198] A person skilled in the art will appreciate that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, and the program may be stored in a computer storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.
[0199] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the protection scope of the present application.
Claims
1. A document generation method based on a knowledge base, characterized in that: The method comprises: In response to the file generation instruction, performing semantic feature extraction processing on the target file description text carried in the file generation instruction to obtain the semantic features of the target file; Matching a target entity identifier corresponding to the semantic feature of the target file from a preset knowledge semantic feature library; the preset knowledge semantic feature library stores a first mapping relationship between preset entity semantic features and preset entity identifiers; Finding a target knowledge node corresponding to the target entity identifier from a preset knowledge graph database, and obtaining target entity attribute data stored in the target knowledge node; the preset knowledge graph database stores a second mapping relationship between the preset knowledge node and the preset entity identifier; the preset knowledge node represents a preset knowledge entity; the preset knowledge node stores preset entity attribute data of the preset knowledge entity; According to the file generation instruction and the target entity attribute data, a target file corresponding to the file generation instruction is generated.
2. The method according to claim 1, characterized in that The method further comprises: Get software source code; Performing lexical analysis on the software source code to generate a sequence of grammatical elements; Performing syntax analysis on the syntax element sequence to generate an abstract syntax tree; the syntax nodes of the abstract syntax tree represent syntax elements of the software source code; Traversing the syntax nodes, extracting syntax elements corresponding to the traversed syntax nodes as the preset knowledge entities and acquiring the preset entity attribute data corresponding to the preset knowledge entities; Determining the preset entity identifier corresponding to the preset knowledge entity according to the traversal order of the abstract syntax tree; The preset knowledge graph database is constructed according to the preset entity identifier, the preset knowledge entity and the preset entity attribute data.
3. The method according to claim 2, characterized in that There are multiple preset knowledge entities; constructing the preset knowledge graph database according to the preset entity identifier, the preset knowledge entity and the preset entity attribute data includes: For each of the preset knowledge entities, determining the preset knowledge entity as the preset knowledge node in the preset knowledge graph database, and determining a second mapping relationship between the preset knowledge node and the preset entity identifier; Inputting the preset entity attribute data corresponding to the preset knowledge entity into the large language model to perform entity attribute data description processing to generate a preset entity description sentence; According to the second mapping relationship, storing the preset entity description statement and the preset entity attribute data in the preset knowledge node; Determining a node association relationship between a plurality of the preset knowledge nodes according to a data association relationship between the preset entity attribute data; The preset knowledge graph database is constructed according to the plurality of preset knowledge nodes and the node association relationships.
4. The method according to claim 3, characterized in that The method further comprises: Performing semantic feature extraction processing on the preset entity description sentence corresponding to the preset knowledge entity to obtain the preset entity semantic feature; The preset knowledge semantic feature library is constructed according to the first mapping relationship between the preset entity identifier and the preset entity semantic feature corresponding to the same preset knowledge entity.
5. The method according to claim 3, characterized in that: The preset knowledge entity includes a directory knowledge entity and a code knowledge entity. The preset entity attribute data corresponding to the preset knowledge entity is input into a large language model for entity attribute data description processing to generate a preset entity description statement, including: Input the directory entity attribute data corresponding to the directory knowledge entity into the large language model for directory entity attribute data description processing to generate a directory entity description statement; the directory entity description statement includes the code module to which the directory knowledge entity belongs, the function description statement of the directory knowledge entity, the directory level of the directory knowledge entity, the code module to which the file contained in the directory knowledge entity belongs, the function description statement of the file, the code class description contained in the file and the interface function description statement; Inputting the code entity attribute data corresponding to the code knowledge entity into the large language model to perform code entity attribute data description processing to generate a code entity description statement; the code entity description statement includes a function description statement of a function code; The directory entity description statement and the code entity description statement are determined as the entity description statement.
6. The method according to claim 1, characterized in that When the file generation instruction is a software document generation instruction, generating a target file corresponding to the file generation instruction according to the file generation instruction and the target entity attribute data includes: Parsing the target file description text to obtain document content configuration information; Generate a target software architecture diagram according to the document content configuration information and the target entity attribute data; Inputting the software document generation instruction and the text information corresponding to the target software architecture diagram into the large language model for document generation processing to generate a target software document corresponding to the software document generation instruction; When the file generation instruction is a software code generation instruction, generating a target file corresponding to the file generation instruction according to the file generation instruction and the target entity attribute data includes: The software code generation instruction and the target entity attribute data are input into the large language model for code generation processing to generate target code corresponding to the software code generation instruction.
7. The method according to claim 6, characterized in that The step of inputting the software document generation instruction and the text information corresponding to the target software architecture diagram into the large language model for document generation processing to generate a target software document corresponding to the software document generation instruction includes: Obtaining a document generation template corresponding to the document content configuration information; Inputting the software document generation instruction and the text information corresponding to the target software architecture diagram into the large language model to obtain the target software document sentence; The target software document statements, the target software architecture diagram and the target entity attribute data are generated according to the document generation template to generate the target software document.
8. A document generation device based on a knowledge base, characterized in that: The device comprises: An instruction semantic feature extraction module is used to perform semantic feature extraction processing on a target file description text carried in the file generation instruction in response to the file generation instruction to obtain a semantic feature of the target file; A knowledge semantic feature library matching module, used to match a target entity identifier corresponding to the semantic feature of the target file from a preset knowledge semantic feature library; the preset knowledge semantic feature library stores a first mapping relationship between preset entity semantic features and preset entity identifiers; A knowledge graph database search module, used to search for a target knowledge node corresponding to the target entity identifier from a preset knowledge graph database, and obtain the target entity attribute data stored in the target knowledge node; the preset knowledge graph database stores a second mapping relationship between the preset knowledge node and the preset entity identifier; the preset knowledge node represents a preset knowledge entity; the preset knowledge node stores preset entity attribute data of the preset knowledge entity; The target file generation module is used to generate a target file corresponding to the file generation instruction according to the file generation instruction and the target entity attribute data.
9. An electronic device, characterized in that: The electronic device comprises: a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by the processor to implement the knowledge base-based file generation method as described in any one of claims 1-7.
10. A computer storage medium, characterized in that: The computer storage medium stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by a processor to implement the knowledge base-based file generation method according to any one of claims 1 to 7.
Citation Information
Cited By
Code query method and device, electronic equipment and storage medium
CN121524211A