Method and system for automatically generating application program interface document based on lexical analysis
Automatically generate application program interface documents through lexical analysis methods, solving the problem of dependence on annotation quality in the prior art, achieving higher degree of automation and document accuracy, applicable to multiple programming languages and reducing maintenance costs.
Patent Information
- Application Number
- CN202411357745.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-27
- Publication Date
- 2025-02-14
- Estimated Expiration
- 2044-09-27
AI Technical Summary
In the prior art, the application program interface document generation method depends on the developers adding normative comments when writing code. If the comments are lacking, outdated or inaccurate, the generated application program interface document will be incomplete, incorrect or difficult to understand. Finally, This results in low document accuracy.
A method of automatic generation of application program interface documents based on lexical analysis is proposed. By obtaining the source code to be parsed, the lexical analysis method is used to parse each component element and its mark type in the source code, and the bootstrap analysis method is used to determine the belongings of each component element. semantic categories of , and then generate corresponding application program interface documents.
By reducing dependence on high-quality normative annotations, the automation and accuracy of application program interface document generation is improved, the overall maintenance cost of the project is reduced, and a variety of programming languages and data types are supported, enhancing the automatic generation ability of documents and legibility.
Smart Images

Figure CN119440618A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, and in particular to a method and system for automatically generating application program interface documents based on lexical analysis. Background Art
[0002] Currently, in the software development process, the writing and maintenance of Application Programming Interface (API) documentation is an important and time-consuming task. Traditional document writing methods usually rely on manual writing and updating, which is not only inefficient, error-prone and unfriendly to reading, but also easily leads to inconsistencies between documents and code implementations. Although some tools have tried to automate this process, they often require specific comments to be added to the source code or follow a specific format, which limits their applicability and flexibility, and may also increase the complexity of development and cause invasive effects on the project. Due to these limitations, developers often face the problem of outdated or incomplete documentation, which affects development efficiency and software quality.
[0003] Automated code comment parsing technology is usually used in the prior art. This method automatically generates API documents by parsing specific comments in the source code. It relies on developers to add standardized comments when writing code. Although this method can automate the generation of documents to a certain extent, its effect and accuracy are highly dependent on the quality and completeness of the original comments. It is also very invasive to existing projects and has a great dependence on the relevant document generation framework, resulting in a very large degree of coupling. This automated code comment parsing technology is highly dependent on the quality and completeness of the comments added by developers when writing code. If the comments are lacking, outdated or inaccurate, the generated API documents will be incomplete, incorrect or difficult to understand. This places high demands on maintaining high standards and consistency of documents. When the code changes, the relevant comments also need to be updated accordingly to ensure the accuracy of the documents, which means that developers need to spend extra time and effort to maintain the comments, increasing the overall maintenance cost of the project. This method usually relies on a specific document generation framework, which limits its versatility and flexibility. If a project needs to switch to another framework or use multiple programming languages, it will become more complicated and difficult to maintain and generate unified API documents. Therefore, in order to generate useful documents, developers must follow strict comment specifications. This not only increases the burden of learning and following these conventions, but can also negatively impact code readability, especially when comments are too lengthy or complex; in order for automated code comment parsing techniques to be effective, it may require extensive modifications to existing projects to add or update comments. This intrusiveness can have an adverse effect on the structure of a project and code clarity, especially in large or legacy projects.
[0004] In summary, the existing API document generation methods rely on developers adding normative comments when writing code. If the comments are lacking, outdated or inaccurate, the generated API documents will be incomplete, erroneous or difficult to understand, ultimately resulting in low document accuracy. Summary of the invention
[0005] In order to solve the problem that the application interface document generation method in the prior art relies on the developer to add normative comments when writing code, if the comments are lacking, outdated or inaccurate, the generated application interface document will be incomplete, wrong or difficult to understand, which ultimately leads to the problem of low document accuracy, the present invention proposes an automatic generation method of application interface document based on lexical analysis, comprising:
[0006] Get the source code to be parsed;
[0007] The source code is parsed using a lexical analysis method to obtain each component element in the source code and a tag type corresponding to each component element;
[0008] According to each component element in the source code and the tag type corresponding to each component element, using a bootstrap analysis method, determining the semantic category to which each component element belongs;
[0009] Generate an application program interface document corresponding to the source code according to the semantic category to which each component element belongs.
[0010] Optionally, the adopting a lexical analysis method to parse the source code to obtain each component element in the source code and a tag type corresponding to each component element includes:
[0011] Parsing the source code using a lexical analysis method to obtain various constituent elements in the source code;
[0012] Perform element recognition on each component element in the source code to obtain a tag type corresponding to each component element.
[0013] Optionally, the tag types include: spaces, braces, parentheses, identifiers, line breaks, keywords, data types, and code comments.
[0014] Optionally, determining the semantic category to which each component element belongs by using a bootstrap analysis method according to each component element in the source code and a tag type corresponding to each component element includes:
[0015] According to each component element in the source code and the tag type corresponding to each component element, a preset regular expression and a context-aware method are used to obtain the semantic weight of each component element;
[0016] According to the semantic weights of the constituent elements, the semantic categories to which the constituent elements belong are obtained.
[0017] Optionally, the obtaining the semantic weight of each component element by using a preset regular expression and a context-aware method according to each component element in the source code and a tag type corresponding to each component element includes:
[0018] According to each component element in the source code and the tag type corresponding to each component element, a preset regular expression is used to match each component element respectively to obtain a basic weight of each component element;
[0019] According to each component element in the source code and the tag type corresponding to each component element, a context-aware method is used to perform context-awareness on each component element to obtain a context weight of each component element;
[0020] According to the basic weight of each component element and the context weight, the semantic weight corresponding to each component element is obtained.
[0021] Optionally, the semantic weight includes: field weight, data type weight and descriptive annotation weight.
[0022] Optionally, obtaining the semantic category to which each component element belongs according to the semantic weight of each component element includes:
[0023] When the field weight in the semantic weight of the component element is the highest, the semantic category to which the component element belongs is the field category;
[0024] When the data type weight is the highest among the semantic weights of the constituent elements, the semantic category to which the constituent elements belong is the data type category;
[0025] When the descriptive annotation weight is the highest among the semantic weights of the constituent elements, the semantic category to which the constituent elements belong is the descriptive annotation category.
[0026] Optionally, generating an application program interface document corresponding to the source code according to the semantic category to which each component element belongs includes:
[0027] Determining parameter description information of the source code according to the semantic categories to which the constituent elements belong;
[0028] Generate an application program interface document corresponding to the source code according to the parameter description information of the source code.
[0029] Optionally, determining the parameter description information of the source code according to the semantic category to which each component element belongs includes:
[0030] According to the semantic categories to which the constituent elements belong, determining whether there is a constituent element in the source code whose semantic category is a descriptive annotation category;
[0031] If it exists, the component element is used as parameter description information of the source code, and the component element and the component elements of the source code whose semantic category is the field category are stored in a preset dictionary;
[0032] If it does not exist, the translation information corresponding to the constituent elements whose semantic category is the field category in the source code is derived according to a preset dictionary, and the translation information is used as the parameter description information of the source code.
[0033] Based on the same inventive concept, the present invention also provides an automatic generation system of application program interface documents based on lexical analysis, comprising:
[0034] A data acquisition module, used to obtain source code to be parsed;
[0035] A code parsing module, used to parse the source code using a lexical analysis method to obtain each component element in the source code and a tag type corresponding to each component element;
[0036] A semantic analysis module, used to determine the semantic category to which each component element belongs by using a bootstrap analysis method according to each component element in the source code and the tag type corresponding to each component element;
[0037] The document generation module is used to generate an application program interface document corresponding to the source code according to the semantic category to which each component element belongs.
[0038] Optionally, the code parsing module includes:
[0039] A lexical analysis submodule, used to parse the source code using a lexical analysis method to obtain various constituent elements in the source code;
[0040] The element identification submodule is used to perform element identification on each component element in the source code to obtain a tag type corresponding to each component element.
[0041] Optionally, the tag types in the code parsing module include: spaces, braces, parentheses, identifiers, line breaks, keywords, data types, and code comments.
[0042] Optionally, the semantic analysis module includes:
[0043] A weight-aware submodule, for obtaining the semantic weight of each component element according to each component element in the source code and the tag type corresponding to each component element, using a preset regular expression and a context-aware method;
[0044] The semantic classification submodule is used to obtain the semantic category to which each component element belongs according to the semantic weight of each component element.
[0045] Optionally, the weight perception submodule includes:
[0046] A regular matching unit, configured to match each component element in the source code and a tag type corresponding to each component element by using a preset regular expression to obtain a basic weight of each component element;
[0047] A context awareness unit, configured to perform context awareness on each component element in the source code and a tag type corresponding to each component element by using a context awareness method to obtain a context weight of each component element;
[0048] The semantic weight generating unit is used to obtain the semantic weight corresponding to each component element according to the basic weight of each component element and the context weight.
[0049] Optionally, the semantic weights in the semantic analysis module include: field weights, data type weights and descriptive annotation weights.
[0050] Optionally, the semantic classification submodule includes:
[0051] A field category determination unit, configured to determine that when the field weight among the semantic weights of the constituent elements is the highest, the semantic category to which the constituent element belongs is the field category;
[0052] A data category determination unit, configured to, when the data type weight is the highest among the semantic weights of the constituent elements, the semantic category to which the constituent element belongs is the data type category;
[0053] The annotation category determination unit is used to determine that when the descriptive annotation weight is the highest among the semantic weights of the constituent elements, the semantic category to which the constituent elements belong is the descriptive annotation category.
[0054] Optionally, the document generation module includes:
[0055] A parameter information determination submodule, used to determine parameter description information of the source code according to the semantic category to which each component element belongs;
[0056] The interface document generation submodule is used to generate an application interface document corresponding to the source code according to the parameter description information of the source code.
[0057] Optionally, the parameter information determination submodule includes:
[0058] An annotation judgment unit, used for judging whether there is a component element whose semantic category is a descriptive annotation category in the source code according to the semantic categories to which the component elements belong;
[0059] The annotation parameter determination unit, if there is a component element whose semantic category is a descriptive annotation category in the source code, uses the component element as parameter description information of the source code, and stores the component element and the component element whose semantic category in the source code is a field category in a preset dictionary;
[0060] The annotation parameter derivation unit, if there is no component element whose semantic category is the descriptive annotation category in the source code, derives translation information corresponding to the component element whose semantic category is the field category in the source code according to a preset dictionary, and uses the translation information as parameter description information of the source code.
[0061] In another aspect, the present invention further provides an electronic device, comprising: at least one processor and a memory; the memory and the processor are connected via a bus;
[0062] The memory is used to store one or more programs;
[0063] When the one or more programs are executed by the at least one processor, the aforementioned method for automatically generating an application program interface document based on lexical analysis is implemented.
[0064] On the other hand, the present invention also provides a computer-readable storage medium having an execution program stored thereon, and when the execution program is executed, the method for automatically generating an application program interface document based on lexical analysis as described above is implemented.
[0065] Compared with the prior art, the present invention has the following beneficial effects:
[0066] The present invention provides a method and system for automatically generating an application program interface document based on lexical analysis, comprising: obtaining a source code to be analyzed; analyzing the source code by a lexical analysis method to obtain each component element in the source code and a tag type corresponding to each component element; determining the semantic category to which each component element belongs by a bootstrap analysis method according to each component element in the source code and the tag type corresponding to each component element; generating an application program interface document corresponding to the source code according to the semantic category to which each component element belongs; the present application analyzes the tag type of the component element in the source code by a lexical analysis method, which is conducive to reducing the reliance on high-quality normative annotations in the existing application program interface document generation process; analyzing the semantic category to which each component element belongs by a bootstrap analysis method is conducive to improving the practicality and readability of the application program interface document generation; therefore, the method of the present invention is conducive to improving the automation level and accuracy of the application program interface document generation. BRIEF DESCRIPTION OF THE DRAWINGS
[0067] Figure 1 A flowchart of a method for automatically generating an application program interface document based on lexical analysis provided by the present invention;
[0068] Figure 2 A schematic diagram of a framework of a method for automatically generating an application program interface document based on lexical analysis provided by a specific embodiment of the present invention;
[0069] Figure 3 A schematic diagram of the structure of an automatic generation system of application program interface documents based on lexical analysis provided by the present invention;
[0070] Figure 4 The present invention provides a schematic structural diagram of an electronic device. DETAILED DESCRIPTION
[0071] The present invention proposes a method and system for automatically generating an application program interface document based on lexical analysis. The specific implementation of the present invention is further described in detail below in conjunction with the accompanying drawings.
[0072] Embodiment 1:
[0073] The present invention provides a method for automatically generating an application program interface document based on lexical analysis, the flow chart of which is as follows: Figure 1 As shown, including:
[0074] Step 1: Get the source code to be parsed;
[0075] Step 2: Use lexical analysis to parse the source code and obtain the components in the source code and the tag type corresponding to each component;
[0076] Step 3: According to the components in the source code and the tag types corresponding to the components, the bootstrap analysis method is used to determine the semantic category to which the components belong;
[0077] Step 4: Generate an application program interface document corresponding to the source code based on the semantic category to which each component element belongs.
[0078] In one implementation, when obtaining the source code to be parsed in the above step 1, it is also necessary to initialize variables and prepare necessary state management tools for the lexical analysis process. This step ensures that the analysis process starts from a clear starting point. Whenever the analysis is performed, it can start from the same initial conditions, avoiding uncertainty and errors caused by uninitialized states, and providing a structured way to collect and manage the various components that make up the source code (the components can also be called tokens). It can provide a structured way for the subsequent lexical analysis process to collect and manage the various components that make up the source code, which makes the entire analysis process more orderly and easy to track and debug.
[0079] In one implementation, the process of parsing the source code using a lexical analysis method in step 2 to obtain each component element in the source code and a tag type corresponding to each component element may include:
[0080] Use lexical analysis method to parse the source code and obtain the components in the source code;
[0081] Perform element recognition on each component element in the source code to obtain the tag type corresponding to each component element.
[0082] For example, the above-mentioned tag types may include: spaces, braces, parentheses, identifiers, line breaks, keywords, data types, and code comments.
[0083] In this implementation, the lexical analysis method is used to directly analyze the various components of the source code, check the source code character by character, effectively distinguish the different components of the source code, automatically identify the structure and semantics of the source code, extract key information such as function / method definitions, code comments, parameters, return types, etc., and automatically generate a structured Application Programming Interface (API) document based on these key information. The identification of each component element is achieved through precisely defined rules, ensuring the accuracy and reliability of the parsing process. Since the entire parsing process does not require adding specific comments to the source code or following a specific format, it supports multiple programming languages and data types, which is conducive to improving the automatic generation capability of documents, reducing errors and omissions caused by inaccurate or missing standardized comments, and reducing the difficulties caused by the need for projects to switch to another framework or use multiple programming languages . Therefore, the method of the present invention is conducive to reducing the reliance on manual standardized annotations in the process of generating API documents, minimizing the intrusion into the source code, and eliminating the need for the project team to perform large-scale code annotation updates, thereby reducing the cost and workload of document maintenance. In addition, by adopting a lexical analysis method, the parsed source code can be applied to a variety of programming languages, without being restricted by a specific programming language or document generation framework, providing a unified and consistent document generation solution for different development environments, and enhancing the applicability across languages and frameworks.
[0084] After the constituent elements are successfully identified, the present invention uses a bootstrap analysis method to determine the tag type of the constituent elements to further process these constituent elements. The design of the bootstrap analysis method allows the system to dynamically identify fields, data types, and descriptive comments, which is achieved by analyzing the context and specific patterns of the constituent elements. The intelligence of this method greatly enhances the ability to process complex source code structures, specifically:
[0085] In one implementation, the process of determining the semantic category to which each component element belongs in step 3 using a bootstrap analysis method according to each component element in the source code and the tag type corresponding to each component element may include:
[0086] According to the components in the source code and the tag types corresponding to the components, a preset regular expression and context-aware method are used to obtain the semantic weight of each component;
[0087] According to the semantic weight of each component element, the semantic category to which each component element belongs is obtained.
[0088] In this implementation, the process of obtaining the semantic weight of each component element according to each component element in the source code and the tag type corresponding to each component element by using a preset regular expression and a context-aware method may include:
[0089] According to each component element in the source code and the tag type corresponding to each component element, a preset regular expression is used to match each component element respectively to obtain a basic weight of each component element;
[0090] According to the components in the source code and the tag types corresponding to the components, a context-aware method is used to perform context-awareness on the components to obtain the context weights of the components.
[0091] According to the basic weight and context weight of each component element, the semantic weight corresponding to each component element is obtained. For example, the semantic weight may include: field weight, data type weight and descriptive annotation weight;
[0092] In this implementation, the present invention can accurately identify different types of tags, such as identifiers, keywords, strings, numbers, etc., by using a preset regular expression to match the constituent elements in the source code. This method can effectively improve the accuracy of tag recognition; by further analyzing the constituent elements through a context-aware method, the meaning of the constituent elements in a specific context can be better understood, and some special cases, such as ambiguity (the same identifier has different meanings in different contexts), can be better handled. This method is not only conducive to improving the robustness of the parser when facing complex source code, but also can improve the accuracy of parsing; through the comprehensive calculation of basic weights and context weights, the semantic meaning of the constituent elements can be more comprehensively evaluated, for example, the distinction between field weights, data type weights and descriptive comment weights, so that the parser can better understand the role of each element in the code; in summary, the present invention determines the semantic category of each constituent element in the source code by combining regular expressions and context-aware methods, which can significantly improve the accuracy, robustness and automation of parsing, thereby improving development efficiency and code quality. This technical solution has high practical value in practical applications.
[0093] In one implementation, the process of obtaining the semantic category to which each component element belongs according to the semantic weight of each component element may include:
[0094] When the field weight in the semantic weight of a constituent element is the highest, the semantic category to which the constituent element belongs is the field category (also called the isField category, indicating that the constituent element is an attribute name field);
[0095] When the data type weight is the highest among the semantic weights of the constituent element, the semantic category to which the constituent element belongs is the data type category (also called the isType category, indicating that the constituent element is an attribute data category field);
[0096] When the descriptive comment has the highest weight among the semantic weights of a component element, the semantic category to which the component element belongs is the descriptive comment category (also called the isDescription category, indicating that the component element is a code comment);
[0097] In this implementation, the semantic category of the constituent elements is determined by analyzing the weights of different features (such as fields, data types, and descriptive comments), which is conducive to improving the accuracy of code parsing and can make the parsing results more in line with the actual programming intent. This is of great significance for improving the quality, maintainability, and development efficiency of software in the actual development process. Especially in the actual project development process, developers are often required to write detailed and standardized comments, which increases the workload and distracts attention from code development and optimization. This implementation determines the semantic category of the constituent elements according to the highest semantic weight and automatically generates the API documentation process, which can not only reduce this part of the burden on developers, but also enable developers to focus more on the development and optimization of the code itself, while ensuring the timely updating and accuracy of the documentation.
[0098] In one implementation, the process of generating the application program interface document corresponding to the source code according to the semantic category to which each component element belongs in step 4 may include:
[0099] Determine parameter description information of the source code according to the semantic category to which each component element belongs;
[0100] Generate the application program interface document corresponding to the source code based on the parameter description information of the source code.
[0101] In this implementation, the process of determining the parameter description information of the source code according to the semantic category to which each component element belongs may include:
[0102] According to the semantic categories to which each component element belongs, determining whether there is a component element in the source code whose semantic category is a descriptive comment category;
[0103] If it exists, the component element is used as parameter description information of the source code, and the component element and the component element whose semantic category in the source code is the field category are stored in a preset dictionary;
[0104] If it does not exist, the translation information corresponding to the constituent elements whose semantic category is the field category in the source code is derived according to a preset dictionary, and the translation information is used as the parameter description information of the source code.
[0105] In this implementation, the present invention automatically generates API documents based on the collected and processed parameter description information, which are automatically generated based on code structure and semantics, and therefore have better consistency and structure. This step involves organizing the constituent elements and the derived parameter description information into specific content of the API document, including but not limited to parameter descriptions and sample codes, etc., and the document formatting process ensures the readability and professionalism of the final output. By performing special processing on the constituent elements with annotations, the annotation content is added to a special dictionary; for the constituent elements without direct annotations, their meanings are derived based on the existing dictionary content. This process not only improves the integrity of the document, but also enhances the accuracy and information content of the document, so that useful document content can be generated even in the absence of direct annotations.
[0106] In view of the fact that the application interface document generation method in the prior art relies on the developer to add normative comments when writing code, the process of manually writing and standardizing comments is easily affected by personal understanding and style preferences, and the developer is usually required to follow specific comment specifications when generating documents, which not only increases the complexity of the code, but also increases the maintenance cost, especially when the project is large-scale or needs to be updated frequently, resulting in inconsistency and accuracy problems of the document. An automatic generation method of application interface document based on lexical analysis is proposed. The lexical elements of the source code are directly analyzed by the lexical analysis method to automatically generate API documents. This method not only significantly improves the degree of automation of API document generation, but also greatly reduces the intrusion into existing codes by reducing the dependence on specific comment formats, making it easier and less costly to maintain and update documents, reducing the interference of human factors, and reducing errors and omissions by accurately parsing the code structure and semantics by machines, thereby improving the accuracy of the documents. In addition, different programming languages and frameworks often have different annotation habits and document generation tools, which brings challenges to the document maintenance of multi-language projects. The present invention provides a flexible document generation method by adopting language-independent lexical analysis technology, which enables it to be used across languages and frameworks, providing a unified and consistent document generation solution for a variety of development environments, and enhancing its universal applicability. The present invention also aims to further improve the practicality and readability of documents through intelligent document structure and format generation, so that such documents are clearer, well-structured, and easier for developers and users to understand and use.
[0107] In summary, the present invention not only improves the automation degree and accuracy of document generation through the automated API document generation process, reduces the invasiveness and maintenance cost of the project, reduces the burden of developers writing and maintaining detailed annotations, and enables developers to focus more on the development and optimization of the code itself, but also enhances its applicability across languages and frameworks through intelligent document structure and format generation, reduces the burden on developers and improves the practicality and readability of the document, improves the practicality and readability of the final API document, and the automatically generated API document is clearer, has a good structure and consistency, is easier for developers and users to understand and use, and can also ensure the timely updating and accuracy of the document.
[0108] Embodiment 2:
[0109] A method for automatically generating an application program interface document based on lexical analysis provided by the present invention is described with a specific embodiment. Figure 2 As shown, specifically including:
[0110] (1) In this step, a piece of backend programming language source code is input;
[0111] (2) This step begins by preparing the system to parse the source code and initialize relevant variables, such as the state machine and Token array, and define the Token type;
[0112] (3) This step performs lexical analysis on the input source code to parse out the token types corresponding to the input code, such as spaces, braces, parentheses, identifiers, line breaks, keywords, data types, code comments, and other types;
[0113] (4) This step generates a Token from the parsed type and inserts the Token into the Token array;
[0114] (5) This step starts the bootstrap analysis of the Token array generated in the previous step, and bootstraps the weights of the current Token semantics such as isField, isType, and isDescription by combining regular expressions and parsing context, and determines the semantics of the current Token based on the weights;
[0115] (6) This step collects tokens that have been analyzed for semantic categories through bootstrapping;
[0116] (7) In this step, for a token with code comments, the code comments are used to mark the parameter description text of the token, and the comments and the corresponding token fields are added to the dictionary for storage; for a token without code comments, the isField type token field is translated through the dictionary and used as the parameter description text of the line of source code; take the following line of source code as an example:
[0117] String body = "hello"; / / msg
[0118] In this line of source code, "String" is a component element of the isType category, "body" is a component element of the isField category, and " / / msg" is a component element of the isDescription category. If there is a code comment in this line of source code (that is, it contains a component element of the isDescription category), the field is directly used as the parameter description text of this line of source code; if there is no code comment in this line of source code (that is, it does not contain a component element of the isDescription category), the component element of the isField category is directly translated (that is, "body" in the example is translated into "body") as the parameter description text of this line of source code;
[0119] (8) This step will format and output the final semantically-containing Token array into a fixed-format API document, such as Word format, HTML format, etc.
[0120] Through this specific embodiment, it can be explained that the present invention aims to construct a set of technical solutions, which automatically derives relevant API documents and generates a reader-friendly document format by performing lexical analysis on existing source code. The efficiency of document writing is improved by automatic deduction rather than manual writing. Automatic generation based on the current code solves the problem of error-prone writing process. This technical solution analyzes the source code and does not require any modification to the current code. Therefore, there is no need to add specific comments or specific formats to the code, and it will not cause any invasive impact on the project and will not bring any impact on the complexity of development.
[0121] Embodiment 3:
[0122] The present invention based on the same inventive concept also provides an automatic generation system of application program interface documents based on lexical analysis, the structural composition diagram is shown in FIG. Figure 3 As shown, including:
[0123] A data acquisition module, used to obtain source code to be parsed;
[0124] The code parsing module is used to parse the source code using a lexical analysis method to obtain the components in the source code and the tag type corresponding to each component;
[0125] A semantic analysis module, for determining the semantic category to which each component element belongs by using a bootstrap analysis method according to each component element in the source code and the tag type corresponding to each component element;
[0126] The document generation module is used to generate the application program interface document corresponding to the source code according to the semantic category to which each component element belongs.
[0127] In a possible implementation, the above-mentioned code parsing module may include:
[0128] The lexical analysis submodule is used to parse the source code using the lexical analysis method to obtain the various components in the source code;
[0129] The element identification submodule is used to identify each component element in the source code and obtain the tag type corresponding to each component element.
[0130] Optionally, the token types in the code parsing module include: spaces, braces, parentheses, identifiers, line breaks, keywords, data types, and code comments.
[0131] In a possible implementation, the semantic analysis module may include:
[0132] The weight-aware submodule is used to obtain the semantic weight of each component element according to each component element in the source code and the tag type corresponding to each component element, using a preset regular expression and context-aware method;
[0133] The semantic classification submodule is used to obtain the semantic category to which each component element belongs according to the semantic weight of each component element.
[0134] In a possible implementation, the weight perception submodule may include:
[0135] A regular matching unit is used to match each component element in the source code and the tag type corresponding to each component element using a preset regular expression to obtain a basic weight of each component element;
[0136] A context awareness unit, used to perform context awareness on each component element according to each component element in the source code and the tag type corresponding to each component element by using a context awareness method to obtain a context weight of each component element;
[0137] The semantic weight generating unit is used to obtain the semantic weight corresponding to each component element according to the basic weight and context weight of each component element.
[0138] In this implementation, the semantic weight in the above-mentioned semantic analysis module may include: field weight, data type weight and descriptive annotation weight.
[0139] In a possible implementation, the semantic classification submodule may include:
[0140] A field category determination unit, used when the field weight among the semantic weights of the constituent elements is the highest, the semantic category to which the constituent elements belong is the field category;
[0141] A data category determination unit, used when the data type weight is the highest among the semantic weights of the constituent elements, the semantic category to which the constituent elements belong is the data type category;
[0142] The annotation category determination unit is used for determining that when the descriptive annotation weight is the highest among the semantic weights of the constituent elements, the semantic category to which the constituent elements belong is the descriptive annotation category.
[0143] In a possible implementation, the document generation module may include:
[0144] The parameter information determination submodule is used to determine the parameter description information of the source code according to the semantic category to which each component element belongs;
[0145] The interface document generation submodule is used to generate the application interface document corresponding to the source code according to the parameter description information of the source code.
[0146] In this implementation, the above-mentioned parameter information determination submodule may include:
[0147] An annotation judgment unit is used to judge whether there is a component element whose semantic category is a descriptive annotation category in the source code according to the semantic category to which each component element belongs;
[0148] The annotation parameter determination unit, if there is a component element whose semantic category is a descriptive annotation category in the source code, uses the component element as parameter description information of the source code, and stores the component element and the component element whose semantic category in the source code is a field category in a preset dictionary;
[0149] The annotation parameter derivation unit, if there is no component element whose semantic category is the descriptive annotation category in the source code, derives the translation information corresponding to the component element whose semantic category is the field category in the source code according to a preset dictionary, and uses the translation information as the parameter description information of the source code.
[0150] Embodiment 4:
[0151] like Figure 4 As shown, the present invention also provides an electronic device, which may be a computer device, a single-chip device, an intelligent mobile device, etc. The electronic device in this embodiment may include a processor, a memory, a transceiver component, etc. The memory, the processor, and the transceiver component are connected via a bus; the memory may be used to store an execution program, and an exemplary execution program may include instructions; the processor is used to execute the instructions stored in the memory. The memory may also be used to store data, which may be called and / or modified when the instructions are executed.
[0152] The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. It is the computing core and control core of the terminal, which is suitable for implementing one or more instructions, specifically suitable for loading and executing one or more instructions in a storage medium to implement corresponding method flows or corresponding functions, so as to implement the steps of a method for automatically generating an application program interface document based on lexical analysis in the above-mentioned embodiment.
[0153] Embodiment 4:
[0154] Based on the same inventive concept, the present invention also provides a readable storage medium, specifically an electronic device readable storage medium (Memory), which is a memory device in an electronic device for storing programs and data. It can be understood that the storage medium here can include both built-in storage media in the electronic device and, of course, extended storage media supported by the electronic device. The storage medium provides a storage space, which stores the operating system of the terminal. In addition, one or more instructions suitable for being loaded and executed by the processor are also stored in the storage space, and these instructions can be one or more execution programs (including program codes). It should be noted that the storage medium here can be a high-speed RAM memory or a non-volatile memory, such as at least one disk storage. The processor loads and executes one or more instructions stored in the storage medium, which can implement the steps of a method for automatically generating an application program interface document based on lexical analysis in the above embodiment.
[0155] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0156] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0157] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0158] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0159] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit its protection scope. Although the present invention has been described in detail with reference to the above embodiments, ordinary technicians in the field should understand that after reading the present invention, those skilled in the art can still make various changes, modifications or equivalent substitutions to the specific implementation methods of the application, but these changes, modifications or equivalent substitutions are all within the protection scope of the claims to be approved.
Claims
1. A method for automatically generating application program interface documents based on lexical analysis, characterized in that: include: Get the source code to be parsed; The source code is parsed using a lexical analysis method to obtain each component element in the source code and a tag type corresponding to each component element; According to each component element in the source code and the tag type corresponding to each component element, using a bootstrap analysis method, determining the semantic category to which each component element belongs; Generate an application program interface document corresponding to the source code according to the semantic category to which each component element belongs.
2. The method according to claim 1, characterized in that The lexical analysis method is used to parse the source code to obtain each component element in the source code and the tag type corresponding to each component element, including: Parsing the source code using a lexical analysis method to obtain various constituent elements in the source code; Perform element recognition on each component element in the source code to obtain a tag type corresponding to each component element.
3. The method according to claim 1 or 2, characterized in that The tag types include: spaces, braces, parentheses, identifiers, line breaks, keywords, data types, and code comments.
4. The method according to claim 1, characterized in that The step of determining the semantic category to which each component element belongs by using a bootstrap analysis method according to each component element in the source code and the tag type corresponding to each component element includes: According to each component element in the source code and the tag type corresponding to each component element, a preset regular expression and a context-aware method are used to obtain the semantic weight of each component element; According to the semantic weights of the constituent elements, the semantic categories to which the constituent elements belong are obtained.
5. The method according to claim 4, characterized in that The method of obtaining the semantic weight of each component element by using a preset regular expression and a context-aware method according to each component element in the source code and the tag type corresponding to each component element includes: According to each component element in the source code and the tag type corresponding to each component element, a preset regular expression is used to match each component element respectively to obtain a basic weight of each component element; According to each component element in the source code and the tag type corresponding to each component element, a context-aware method is used to perform context-awareness on each component element to obtain a context weight of each component element; According to the basic weight of each component element and the context weight, the semantic weight corresponding to each component element is obtained.
6. The method according to claim 4 or 5, characterized in that The semantic weight includes: field weight, data type weight and descriptive annotation weight.
7. The method according to claim 6, characterized in that The obtaining, according to the semantic weights of the constituent elements, the semantic categories to which the constituent elements belong, comprises: When the field weight in the semantic weight of the component element is the highest, the semantic category to which the component element belongs is the field category; When the data type weight is the highest among the semantic weights of the constituent elements, the semantic category to which the constituent elements belong is the data type category; When the descriptive annotation weight is the highest among the semantic weights of the constituent elements, the semantic category to which the constituent elements belong is the descriptive annotation category.
8. The method according to claim 7, characterized in that The step of generating an application program interface document corresponding to the source code according to the semantic category to which each component element belongs includes: Determining parameter description information of the source code according to the semantic categories to which the constituent elements belong; Generate an application program interface document corresponding to the source code according to the parameter description information of the source code.
9. The method according to claim 8, characterized in that The step of determining the parameter description information of the source code according to the semantic categories to which the constituent elements belong includes: According to the semantic categories to which the constituent elements belong, determining whether there is a constituent element in the source code whose semantic category is a descriptive annotation category; If it exists, the component element is used as parameter description information of the source code, and the component element and the component elements of the source code whose semantic category is the field category are stored in a preset dictionary; If it does not exist, the translation information corresponding to the component element whose semantic category is the field category in the source code is derived according to a preset dictionary, and the translation information is used as the parameter description information of the source code.
10. An automatic generation system of application program interface documents based on lexical analysis, characterized in that: include: A data acquisition module, used to obtain source code to be parsed; A code parsing module, used to parse the source code using a lexical analysis method to obtain each component element in the source code and a tag type corresponding to each component element; A semantic analysis module, used to determine the semantic category to which each component element belongs by using a bootstrap analysis method according to each component element in the source code and the tag type corresponding to each component element; The document generation module is used to generate an application program interface document corresponding to the source code according to the semantic category to which each component element belongs.
11. The system according to claim 10, characterized in that The code parsing module includes: A lexical analysis submodule, used to parse the source code using a lexical analysis method to obtain various constituent elements in the source code; The element identification submodule is used to perform element identification on each component element in the source code to obtain a tag type corresponding to each component element.
12. The system according to claim 10, characterized in that The semantic analysis module comprises: A weight-aware submodule, for obtaining the semantic weight of each component element according to each component element in the source code and the tag type corresponding to each component element, using a preset regular expression and a context-aware method; The semantic classification submodule is used to obtain the semantic category to which each component element belongs according to the semantic weight of each component element.
13. An electronic device, characterized in that: include: at least one processor and memory; The memory and the processor are connected via a bus; The memory is used to store one or more programs; When the one or more programs are executed by the at least one processor, a method for automatically generating an application program interface document based on lexical analysis as described in any one of claims 1 to 9 is implemented.
14. A computing device readable storage medium, characterized in that: An execution program is stored thereon, and when the execution program is executed, a method for automatically generating an application program interface document based on lexical analysis as described in any one of claims 1 to 9 is implemented.
Citation Information
Patent Citations
Interface document and test case generation method and device, computer equipment and storage medium
CN116841900A
Interface document generation method and device, electronic equipment and storage medium
CN117193850A
AST-based software unit function description auxiliary generation method and system
CN118626363A
Producing idiomatic software documentation for many programming languages from a common specification
US20220206759A1