Method and device for automatically generating software document, electronic equipment and medium

By obtaining and parsing source code, using natural language processing models for semantic analysis and structural integration, the problem of lack of deep understanding when generating API documents by existing tools is solved, and high-quality documents are generated.

CN119292656APending Publication Date: 2025-01-10HUBEI YINGKU TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411193012.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-28
Publication Date
2025-01-10

AI Technical Summary

Technical Problem

Existing automation tools lack deep understanding of code semantics when generating API documents, resulting in the lack of accuracy and completeness of generated documents and cannot meet the needs of high-quality documents.

Method used

By obtaining the source code, parsing and preprocessing, semantic analysis and structural analysis are performed using natural language processing models, key information and structural information are integrated to generate high-quality software documents.

Benefits of technology

Improves the understanding of the deep semantics of the source code and significantly improves the accuracy and completeness of the generated documents.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119292656A_ABST
    Figure CN119292656A_ABST
Patent Text Reader

Abstract

The invention relates to a method and device for automatically generating a software document, electronic equipment and a medium, and belongs to the technical field of computers.The method comprises the steps that source codes are obtained and analyzed, and analyzed data are obtained; the analyzed data are preprocessed, and preprocessed data are obtained; performing semantic analysis on the preprocessed data based on a preset first natural language processing model to obtain key information; analyzing the structure of the source code to obtain structure information; and integrating the key information and the structure information based on a preset second natural language processing model to obtain a software document corresponding to the source code. According to the invention, the accuracy and integrity of the generated document are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method, device, electronic equipment and medium for automatically generating software documents. Background Art

[0002] API (Application Programming Interface) documentation is an important tool for software development, use and maintenance. API documentation usually needs to elaborate on the hierarchical relationship between the functional modules of the software, express the functions and logic of each module in a hierarchical manner, and explain the input, output, and important intermediate variables.

[0003] The traditional API documentation process is usually manual, which is time-consuming and error-prone, especially when dealing with large software projects. Although automated tools can generate documentation from code comments, these tools usually cannot understand the context and complexity of the code.

[0004] Most existing automated document generation tools rely on surface-level code comment parsing and lack an understanding of the deep semantics of the code, which results in the generated documents often lacking accuracy and completeness and failing to meet the requirements of high-quality documentation. Summary of the invention

[0005] In view of this, it is necessary to provide a method, device, electronic device and medium for automatically generating software documentation to solve the problem in the prior art of lack of understanding of the deep semantics of the code, resulting in the lack of accuracy and completeness of the generated documents.

[0006] In order to solve the above problem, the present invention provides a method for automatically generating software documentation, comprising: Obtaining source code and parsing the source code to obtain parsed data; Preprocessing the parsed data to obtain preprocessed data; Performing semantic analysis on the preprocessed data based on a preset first natural language processing model to obtain key information; Parsing the structure of the source code to obtain structural information; The key information and the structural information are integrated based on a preset second natural language processing model to obtain a software document corresponding to the source code.

[0007] In a possible implementation, the parsed data includes function annotations, interface annotations, and annotations on the mutual calling relationships between functions.

[0008] In a possible implementation, preprocessing the parsed data to obtain preprocessed data includes: clearing invalid or obsolete comments from the parsed data; Eliminate redundant or irrelevant functions or classes in the code in the parsed data.

[0009] In a possible implementation, parsing the structure of the source code to obtain structure information includes: Analyze the inheritance relationship, association relationship and dependency relationship between classes and methods in the source code; Based on the inheritance relationship, the association relationship and the dependency relationship, structural information is obtained.

[0010] In a possible implementation, parsing the inheritance relationship, association relationship, and dependency relationship between classes and methods in the source code includes: Parsing the source code into a tree structure based on the ast module parser in Python; Traversing each node of the tree structure, when the node is a class node, obtaining class node data, the class node data including the class name, base class, methods within the class, and attributes in the class; When the node is a method node, method node data is obtained, wherein the method node data includes a method name, a parameter list, a return type, and a method return body; When the node is an attribute node, attribute node data is obtained, wherein the attribute node data includes an attribute name and type, an initial value, and a class structure description corresponding to the attribute node; The inheritance relationship, association relationship and dependency relationship among the classes, methods and attributes in the source code are obtained based on the class node data, method node data and attribute node data.

[0011] In a possible implementation, the key information and the structural information are integrated based on a preset second natural language processing model to obtain a software document corresponding to the source code, including: Converting the key information into a first formatted text that can be processed by natural language; Converting the structural information into a second formatted text that can be processed by natural language; The first formatted text and the second formatted text are input into a preset second natural language processing model to obtain a software document corresponding to the source code.

[0012] In a possible implementation manner, the method further includes: dividing the software document into chapters and paragraphs based on a clustering algorithm.

[0013] On the other hand, the present invention also provides a device for automatically generating software documentation, comprising: A data parsing module, used to obtain source code and parse the source code to obtain parsed data; A data preprocessing module, used to preprocess the parsed data to obtain preprocessed data; A key information acquisition module, used to perform semantic analysis on the preprocessed data based on a preset first natural language processing model to obtain key information; A structure information acquisition module, used for parsing the structure of the source code to obtain structure information; The software document generation module is used to integrate the key information and the structural information based on a preset second natural language processing model to obtain the software document corresponding to the source code.

[0014] On the other hand, the present invention also provides an electronic device, including a memory and a processor, wherein: The memory is used to store programs; The processor is coupled to the memory and is used to execute the program stored in the memory to implement the steps in a method for automatically generating software documentation described in any one of the above implementations.

[0015] On the other hand, the present invention also provides a computer-readable storage medium for storing computer-readable programs or instructions, which, when executed by a processor, can implement the steps in a method for automatically generating software documentation described in any of the above-mentioned implementations.

[0016] The beneficial effects of the present invention are as follows: the present invention provides a method for automatically generating software documents, firstly obtaining source code and parsing the source code to obtain parsed data, then preprocessing the parsed data to obtain preprocessed data, further semantically analyzing the preprocessed data based on a preset first natural language processing model to obtain key information, further parsing the structure of the source code to obtain structural information, further integrating the key information and structural information based on a preset second natural language processing model to obtain a software document corresponding to the source code. The present invention semantically analyzes the preprocessed data based on a preset first natural language processing model to obtain key information, parses the structure of the source code to obtain structural information, and finally integrates the key information and structural information based on a preset second natural language processing model, thereby improving the understanding of the deep semantics of the source code and improving the accuracy and completeness of the generated document. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] Figure 1 A method flow chart of an embodiment of a method for automatically generating software documentation provided by the present invention; Figure 2 For the present invention Figure 1 A schematic flow chart of an embodiment of S102; Figure 3 For the present invention Figure 1 A schematic flow chart of an embodiment of S104; Figure 4 For the present invention Figure 1 A schematic flow chart of an embodiment of S105; Figure 5 A schematic diagram of the structure of an embodiment of a device for automatically generating software documents provided by the present invention; Figure 6 A schematic structural diagram of an embodiment of an electronic device provided by the present invention. DETAILED DESCRIPTION

[0018] The preferred embodiments of the present invention are described in detail below in conjunction with the accompanying drawings, wherein the accompanying drawings constitute a part of this application and are used together with the embodiments of the present invention to illustrate the principles of the present invention, but are not used to limit the scope of the present invention.

[0019] The present invention provides a method, device, electronic device and medium for automatically generating software documents, which are described below respectively.

[0020] Figure 1 A flow chart of an embodiment of the method for automatically generating software documentation provided by the present invention is as follows: Figure 1 As shown, the method for automatically generating software documentation includes: S101, obtaining source code and parsing the source code to obtain parsed data; S102, preprocessing the parsed data to obtain preprocessed data; S103, performing semantic analysis on the preprocessed data based on a preset first natural language processing model to obtain key information; S104, parsing the structure of the source code to obtain structural information; S105. Integrate the key information and the structural information based on a preset second natural language processing model to obtain a software document corresponding to the source code.

[0021] Compared with the prior art, the method for automatically generating software documents provided in this embodiment first obtains source code and parses the source code to obtain parsed data, then preprocesses the parsed data to obtain preprocessed data, further performs semantic analysis on the preprocessed data based on a preset first natural language processing model to obtain key information, further parses the structure of the source code to obtain structural information, and further integrates the key information and structural information based on a preset second natural language processing model to obtain a software document corresponding to the source code. The present invention performs semantic analysis on the preprocessed data based on a preset first natural language processing model to obtain key information, parses the structure of the source code to obtain structural information, and finally integrates the key information and structural information based on a preset second natural language processing model, thereby improving the understanding of the deep semantics of the source code and improving the accuracy and completeness of the generated document.

[0022] In some embodiments of the present invention, the parsed data includes function annotations, interface annotations, and annotations on the mutual calling relationships between functions.

[0023] In a specific embodiment of the present invention, an advanced code parsing tool, such as ANTLR or Roslyn, is used to parse the source code to accurately extract functions, classes, interfaces and their related comments.

[0024] In some embodiments of the present invention, Figure 2 As shown, in step S102, the parsed data is preprocessed to obtain preprocessed data, including: S201, clearing invalid or outdated comments in the parsed data; S202: Eliminate redundant or irrelevant functions or classes in the code in the parsed data.

[0025] In a specific embodiment of the present invention, machine learning techniques, such as classification algorithms, are used to evaluate the quality of annotations, filter out low-quality or irrelevant annotations, and ensure that only meaningful data is processed.

[0026] Feature extraction First, a set of features need to be extracted from the annotation text, which will be used to train the machine learning model. These features mainly include: Length feature: the number of words or characters in the comment. Comments that are too short or too long may not have sufficient information value.

[0027] Keyword density: How often specific technical keywords appear in the annotations. A high frequency of technical words may indicate a high-quality annotation.

[0028] Code reference frequency: The frequency with which code elements (such as variable names and function names) are mentioned in comments. Comments that frequently reference code elements are likely to be closely related to the code.

[0029] Sentence structure complexity: Sentence structure analysis based on natural language processing, average sentence length, number of clauses in a sentence, etc.

[0030] Sentiment analysis: The sentiment tendency of the annotation, using NLP technology to analyze whether the annotation statement is positive or negative.

[0031] Machine Learning Model Selection and Training Select an appropriate machine learning model to evaluate the quality of annotations. Commonly used models include logistic regression, support vector machine (SVM), random forest, etc. The choice of model depends on the characteristics of the data and the preprocessing results. The model training steps include: Dataset preparation: Prepare a labeled dataset where annotations are labeled as “high quality” or “low quality”.

[0032] Training and validation: Use the training set to train the model and optimize the model parameters through cross-validation.

[0033] Performance Evaluation: Use an independent set of test data to evaluate the model’s performance metrics such as accuracy, recall, and F1 score.

[0034] Annotation quality assessment Use the trained model to perform quality assessment on new annotated data: Annotation Scoring: The model generates a quality score for each annotation.

[0035] Threshold setting: Set a score threshold as needed. Annotations above this threshold are considered high-quality, and those below this threshold are filtered out.

[0036] Continuous iteration and optimization As software projects evolve and change, the features and quality standards of annotations may change over time. Therefore, it is necessary to retrain the model regularly and adjust the feature extraction methods and model parameters based on new data.

[0037] In a specific embodiment of the present invention, a BERT model is used for deep semantic analysis, which is suitable for understanding the contextual meaning of annotations.

[0038] Preprocessing annotation data Data cleaning: Clean the annotation data and remove irrelevant characters, such as special symbols, extra spaces, etc.

[0039] Tokenization: Use BERT’s tokenizer to break the annotation text into tokens. This includes adding special tokens such as [CLS] (start token) and [SEP] (separation token).

[0040] Token encoding: Convert tokens into IDs that the model can understand. The BERT model provides a predefined vocabulary for converting tokens into unique integer IDs.

[0041] Embedding with BERT Generate embeddings: Input the preprocessed tokens into the BERT model. The model will return embedding vectors for each token that capture the semantic information in the annotations.

[0042] Attention Mask: If padding is used to handle annotations of varying lengths, an “attention mask” needs to be created to instruct the BERT model to ignore these padding tokens.

[0043] Extracting and utilizing embedding vectors Extract features: Extract embedding vectors from BERT output. We can use the output of the [CLS] token as the representation of the entire sentence, or pool the output of all tokens (such as average pooling) to obtain the overall sentence representation.

[0044] Deep analysis: Use these embedding vectors for subsequent analysis, such as calculating similarity between comments, or similarity with related code snippets.

[0045] Post-processing and application Apply embedding vectors: Use the embedding vectors to perform the desired NLP tasks, such as classification, similarity calculation, or as input for document generation.

[0046] Result interpretation: Based on the analysis results obtained from the embedding vector, the semantics of the annotations are interpreted and understood, which is crucial for subsequent API documentation generation.

[0047] In some embodiments of the present invention, Figure 3 As shown, in step S104, the structure of the source code is parsed to obtain structure information, including: S301, parsing the inheritance relationship, association relationship and dependency relationship between classes and methods in the source code; S302: Obtain structural information based on the inheritance relationship, the association relationship, and the dependency relationship.

[0048] In some embodiments of the present invention, parsing the inheritance relationship, association relationship, and dependency relationship between classes and methods in the source code includes: Parsing the source code into a tree structure based on the ast module parser in Python; Traversing each node of the tree structure, when the node is a class node, obtaining class node data, the class node data including the class name, base class, methods within the class, and attributes in the class; When the node is a method node, method node data is obtained, wherein the method node data includes a method name, a parameter list, a return type, and a method return body; When the node is an attribute node, attribute node data is obtained, wherein the attribute node data includes an attribute name and type, an initial value, and a class structure description corresponding to the attribute node; The inheritance relationship, association relationship and dependency relationship among the classes, methods and attributes in the source code are obtained based on the class node data, method node data and attribute node data.

[0049] In a specific embodiment of the present invention, the structure of the code is deeply analyzed by writing custom scripts and algorithms.

[0050] In object-oriented programming (OOP), the main structure of the code includes classes, methods, and properties. Analyzing the structure of these elements requires not only understanding their definitions and usages, but also identifying the relationships between them: inheritance, association, dependency, etc.

[0051] The following are the specific processes and steps for analyzing the structure of object-oriented programming code: Use Python's ast module parser, such as Python's ast module to parse the source code into AST. AST can represent the code in a tree structure, where each node represents a construct of the code.

[0052] By traversing the AST nodes, identifying and collecting information about classes, methods, and attributes. This is usually done by implementing a Visitor Pattern to operate on specific types of nodes during the traversal.

[0053] Class Node: Identifies the definition of a class, including the class name, base classes (if any), and method and attribute definitions within the class.

[0054] Method node: Identifies the definition of a method, including the method name, parameter list, return type, and method body.

[0055] Attribute Node: Identifies the definition of a class attribute, including the attribute name and type, and possible initial value.

[0056] Based on the collected information, construct a structural description of each class, including: Class name and base class information, used to understand inheritance relationships.

[0057] A list of methods, including each method's signature (parameter types, return type).

[0058] A list of properties, including the type and initial value of each property.

[0059] According to the usage of classes and method calls, analyze the relationship between classes. Inheritance relationship: Identify through base class information. Association and dependency relationship: Identify through method parameters, return type and property type.

[0060] In some embodiments of the present invention, in step S105, the key information and the structural information are integrated based on a preset second natural language processing model to obtain a software document corresponding to the source code, including: S401, converting the key information into a first formatted text that can be processed by natural language; S402, converting the structural information into a second formatted text that can be processed by natural language; S403: Input the first formatted text and the second formatted text into a preset second natural language processing model to obtain a software document corresponding to the source code.

[0061] In a specific embodiment of the present invention, a large language model is used to generate a draft document in combination with code analysis and semantic understanding of annotations. This includes generating a detailed description for each API element (such as class, method, attribute), ensuring that the purpose, parameter description, return value, exception conditions, etc. are included.

[0062] Integrate code analysis and semantic understanding results. Before generating documents, you first need to integrate the previous code structure analysis and semantic understanding results of comments. The structural information of classes, methods, parameters, and other code elements obtained from code analysis; the deep understanding of the comment content obtained from semantic analysis, such as the relevance of the comment to the code, the theme and intention of the comment, etc.

[0063] Prepare input data. Format this information into a form that large language models can understand. Format text: Convert code elements and comments into natural language descriptions. For example, convert a method signature and related comments into "This method accepts [parameters] for [purpose described in the comment]." Contextual information: Provide the model with enough contextual information to help it generate accurate documentation content. This may include descriptions of classes, what methods do, etc.

[0064] Feed the prepared input data into the model, and the model will automatically generate document content, including detailed descriptions of the API, usage examples, etc.

[0065] Content enrichment: In addition to basic descriptions, automatically generated documents also include usage examples, performance analysis, compatibility information, best practices, etc., providing a more comprehensive perspective.

[0066] In some embodiments of the present invention, the method further includes: dividing the software document into chapters and paragraphs based on a clustering algorithm.

[0067] In a specific embodiment of the present invention, the document structure is also optimized as follows: Chapter division: Use algorithms to intelligently divide the generated documents into chapters. For example, group methods according to the functions of the class, or divide the API into different parts according to the usage scenarios. This aims to improve the organization and readability of the document. The following are detailed technical means to achieve this goal: Document content analysis. The generated API documentation content needs to be analyzed to identify different content blocks. Text segmentation: Segment the entire document into smaller paragraphs or sentences. Content tagging: Tag the type of each paragraph or sentence (e.g., definition, description, example, comment, etc.).

[0068] Feature extraction. In order to perform intelligent chapter division, features need to be extracted from each part of the document. These features include: keyword density: the density of specific keywords in each part; text length: the length of each part (for example, the number of words); semantic similarity: the semantic similarity of each part to other parts, which can be calculated using NLP technology.

[0069] Use clustering algorithms to divide chapters. Clustering algorithms can be used to group similar content blocks together to form chapters. Hierarchical clustering: A tree-based clustering method that can provide clustering results at different levels.

[0070] Chapter naming and organization. Divide the document into chapters based on clustering results and name each chapter. Automatic naming: Name each chapter based on the most frequent keywords or topics. Manual review: Manual review and adjustment of chapter names may be required to ensure accuracy and relevance.

[0071] Optimize and adjust the chapter divisions based on user feedback or expert review results.

[0072] Index and Navigation: Automatically generate index and navigation systems, including cross-document links, keyword search functions, etc., to improve the usability and accessibility of documents.

[0073] In order to better implement a method for automatically generating software documentation in an embodiment of the present invention, based on a method for automatically generating software documentation, correspondingly, Figure 5 As shown, an embodiment of the present invention further provides a device for automatically generating software documentation. The device 500 for automatically generating software documentation includes: The data parsing module 501 is used to obtain source code and parse the source code to obtain parsed data; A data preprocessing module 502 is used to preprocess the parsed data to obtain preprocessed data; A key information acquisition module 503 is used to perform semantic analysis on the preprocessed data based on a preset first natural language processing model to obtain key information; A structure information acquisition module 504 is used to parse the structure of the source code to obtain structure information; The software document generation module 505 is used to integrate the key information and the structural information based on a preset second natural language processing model to obtain the software document corresponding to the source code.

[0074] The device 500 for automatically generating software documents provided in the above embodiment can implement the technical solution described in the above method embodiment for automatically generating software documents. The specific implementation principles of the above modules or units can refer to the corresponding contents in the above method embodiment for automatically generating software documents, which will not be repeated here.

[0075] like Figure 6 As shown, the present invention also provides an electronic device 600. The electronic device 600 includes a processor 601, a memory 602 and a display 603. Figure 6 Only some components of the electronic device 600 are shown, but it should be understood that it is not required to implement all of the components shown, and more or fewer components may be implemented instead.

[0076] In some embodiments, the processor 601 may be a central processing unit (CPU), a microprocessor or other data processing chip, used to run program codes stored in the memory 602 or process data, such as a method for automatically generating software documents in the present invention.

[0077] In some embodiments, the processor 601 may be a single server or a server group. The server group may be centralized or distributed. In some embodiments, the processor 601 may be local or remote. In some embodiments, the processor 601 may be implemented in a cloud platform. In some embodiments, the cloud platform may include a private cloud, a public cloud, a hybrid cloud, a community cloud, a distributed cloud, an internal cloud, a multi-cloud, etc., or any combination thereof.

[0078] In some embodiments, the memory 602 may be an internal storage unit of the electronic device 600, such as a hard disk or memory of the electronic device 600. In other embodiments, the memory 602 may also be an external storage device of the electronic device 600, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc., equipped on the electronic device 600.

[0079] Furthermore, the memory 602 may include both an internal storage unit of the electronic device 600 and an external storage device. The memory 602 is used to store application software installed in the electronic device 600 and various data.

[0080] In some embodiments, the display 603 may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode) touch device, etc. The display 603 is used to display information on the electronic device 600 and to display a visual user interface. The components 601-603 of the electronic device 600 communicate with each other via a system bus.

[0081] In one embodiment, when the processor 601 executes a program for automatically generating software documents in the memory 602, the following steps may be implemented: Obtaining source code and parsing the source code to obtain parsed data; Preprocessing the parsed data to obtain preprocessed data; Performing semantic analysis on the preprocessed data based on a preset first natural language processing model to obtain key information; Parsing the structure of the source code to obtain structural information; The key information and the structural information are integrated based on a preset second natural language processing model to obtain a software document corresponding to the source code.

[0082] It should be understood that: when the processor 601 executes a program for automatically generating software documents in the memory 602, in addition to the above functions, other functions can also be implemented. For details, please refer to the description of the corresponding method embodiment above.

[0083] Furthermore, the embodiment of the present invention does not specifically limit the type of the electronic device 600 mentioned, and the electronic device 600 may be a portable electronic device such as a mobile phone, a tablet computer, a personal digital assistant (PDA), a wearable device, a laptop computer, etc. Exemplary embodiments of portable electronic devices include but are not limited to portable electronic devices equipped with IOS, Android, Microsoft or other operating systems. The above-mentioned portable electronic devices may also be other portable electronic devices, such as a laptop computer with a touch-sensitive surface (e.g., a touch panel). It should also be understood that in some other embodiments of the present invention, the electronic device 600 may not be a portable electronic device, but a desktop computer with a touch-sensitive surface (e.g., a touch panel).

[0084] Those skilled in the art will appreciate that all or part of the processes of the above-mentioned embodiments can be implemented by instructing related hardware through a computer program, and the program can be stored in a computer-readable storage medium, wherein the computer-readable storage medium is a disk, an optical disk, a read-only storage memory, or a random access memory, etc.

[0085] The above description is only a preferred specific implementation manner of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily conceived by any technician familiar with the technical field within the technical scope disclosed by the present invention should be covered within the protection scope of the present invention.

Claims

1. A method for automatically generating software documentation, characterized in that: include: Obtaining source code and parsing the source code to obtain parsed data; Preprocessing the parsed data to obtain preprocessed data; Performing semantic analysis on the preprocessed data based on a preset first natural language processing model to obtain key information; Parsing the structure of the source code to obtain structural information; The key information and the structural information are integrated based on a preset second natural language processing model to obtain a software document corresponding to the source code.

2. The method for automatically generating software documentation according to claim 1, characterized in that: The parsed data includes function annotations, interface annotations, and annotations on the mutual calling relationships between functions.

3. The method for automatically generating software documentation according to claim 2, characterized in that: The preprocessing of the parsed data to obtain the preprocessed data includes: clearing invalid or obsolete comments from the parsed data; Eliminate redundant or irrelevant functions or classes in the code in the parsed data.

4. The method for automatically generating software documentation according to claim 1, characterized in that: The step of parsing the structure of the source code to obtain structural information includes: Analyze the inheritance relationship, association relationship and dependency relationship between classes and methods in the source code; Based on the inheritance relationship, the association relationship and the dependency relationship, structural information is obtained.

5. The method for automatically generating software documentation according to claim 4, characterized in that: Parse the inheritance, association, and dependency relationships between classes and methods in the source code, including: Parsing the source code into a tree structure based on the ast module parser in Python; Traversing each node of the tree structure, when the node is a class node, obtaining class node data, the class node data including the class name, base class, methods within the class, and attributes in the class; When the node is a method node, method node data is obtained, wherein the method node data includes a method name, a parameter list, a return type, and a method return body; When the node is an attribute node, attribute node data is obtained, wherein the attribute node data includes an attribute name and type, an initial value, and a class structure description corresponding to the attribute node; The inheritance relationship, association relationship and dependency relationship among the classes, methods and attributes in the source code are obtained based on the class node data, method node data and attribute node data.

6. The method for automatically generating software documentation according to claim 1, characterized in that: The key information and the structural information are integrated based on the preset second natural language processing model to obtain a software document corresponding to the source code, including: Converting the key information into a first formatted text that can be processed by natural language; Converting the structural information into a second formatted text that can be processed by natural language; The first formatted text and the second formatted text are input into a preset second natural language processing model to obtain a software document corresponding to the source code.

7. The method for automatically generating software documentation according to claim 1, characterized in that: Also includes: The software document is divided into chapters and paragraphs based on a clustering algorithm.

8. A device for automatically generating software documentation, characterized in that: include: A data parsing module, used to obtain source code and parse the source code to obtain parsed data; A data preprocessing module, used to preprocess the parsed data to obtain preprocessed data; A key information acquisition module, used to perform semantic analysis on the preprocessed data based on a preset first natural language processing model to obtain key information; A structure information acquisition module, used for parsing the structure of the source code to obtain structure information; The software document generation module is used to integrate the key information and the structural information based on a preset second natural language processing model to obtain the software document corresponding to the source code.

9. An electronic device, characterized in that: comprising a memory and a processor, wherein: The memory is used to store programs; The processor is coupled to the memory and is used to execute the program stored in the memory to implement the steps in the method for automatically generating software documentation as described in any one of claims 1 to 7 above.

10. A computer-readable storage medium, characterized in that: Used to store computer-readable programs or instructions, which, when executed by a processor, can implement the steps in the method for automatically generating software documentation as described in any one of claims 1 to 7.

Citation Information

Cited By

  • Universal document automatic generation method based on structured code annotation

    CN121433716A

  • Agentic AI-based document generation method and device, electronic equipment and storage medium

    CN121902769A