A document-guided API usage sequence search method

Through the document-guided API using sequence search method, API documents are used for cross-modal attention and similarity calculations, solving the problem of semantic gap between API and text and improving the accuracy of API using sequence search.

CN116301824BActive Publication Date: 2025-04-29HARBIN INST OF TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310131203.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-02-17
Publication Date
2025-04-29
Estimated Expiration
2043-02-17

AI Technical Summary

Technical Problem

It is difficult for the prior art to accurately search the API usage sequence that meets specific functional needs, and there is a semantic gap between the API and the text, resulting in inaccurate search results.

Method used

Through the document-guided API usage sequence search method, API documents are used as guidance information for model training, and cross-modal similarity calculation is realized to alleviate the semantic gap between function description and API usage sequence.

Benefits of technology

It improves the accuracy of API usage sequence search, can more effectively match function descriptions and API usage sequences, and reduces the difficulties for developers when learning and using APIs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116301824B_ABST
    Figure CN116301824B_ABST
Patent Text Reader

Abstract

The present invention discloses a document-guided API sequence search method, which includes the following steps: Step 1: Acquire an API set and an API document dictionary by mining an API document repository; Step 2: Construct a data set and an API usage sequence database for search by mining a code repository; Step 3: Preprocess the original data and convert it into a feature vector that can be processed by a deep learning model; Step 4: Construct a network model; Step 5: Train the network model and use the trained network model to implement API usage sequence search. The present invention uses the API document as guidance information for model training to assist in cross-modal attention and cross-modal similarity calculation, which can alleviate the semantic gap problem between function descriptions and API usage sequences, thereby improving the accuracy of the search.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to an API usage sequence search method, and in particular to a document-guided API usage sequence search method. Background Art

[0002] In order to speed up software development and avoid reinventing the wheel, developers often use the Application Programming Interface (API) provided by libraries or frameworks when programming. Specifically, developers often call a set of APIs in a specific order to achieve a specific function. This set of APIs called in order is also called an API usage sequence. For example, in order to "convert an input stream into a string", developers can call the following API usage sequence:

[0003] java.util.Scanner.new()→

[0004] java.util.Scanner.useDelimiter()→

[0005] java.util.Scanner.hasNext()→

[0006] java.util.Scanner.next()

[0007] However, the number of APIs has exploded in recent years. For example, the number of APIs included in the common .NET and JDK frameworks is more than a thousand, making it difficult for developers to master all API usage methods. In addition, a study published by Microsoft in 2009 showed that there are few existing API-related learning materials, and the standardization of API documents is also poor. 67.7% of developers said they would encounter difficulties in learning how to use APIs. Therefore, in order to make up for their own lack of knowledge in APIs, developers often need to manually search for APIs that meet their functional requirements in general search engines. However, it is difficult for existing general search engines to accurately search for API usage sequences that can meet functional requirements.

[0008] In the API usage sequence search task, programming language type API usage sequences are often considered to be data of different modalities from natural language type function descriptions, so there is a semantic gap between the two. However, as natural language type data, API documents often have a high semantic overlap with function descriptions, which provides a feasible idea to alleviate the semantic gap problem between API and text.

[0009] At present, the research related to API recommendation mainly focuses on API pattern generation and API pattern search. Among them, API pattern generation refers to converting the function description into an API pattern tree, API pattern graph or API usage sequence that can realize the function through the codec model. API pattern search refers to searching for a sorted list of a set of API patterns related to the function query in the API pattern database and returning it to the user. At present, there are more studies on API pattern generation, but fewer studies on API pattern search. API pattern search mainly focuses on the search of a single API and the search of API pattern graphs. No research related to API usage sequence search has been retrieved. Summary of the invention

[0010] In order to alleviate the semantic gap problem between API and text, the present invention provides a document-guided API usage sequence search method, which uses a function description in natural language as a query, searches for an API usage sequence that can satisfy the function, and uses API documents as auxiliary information to alleviate the semantic gap. The present invention uses API documents as guidance information for model training to assist in cross-modal attention and cross-modal similarity calculation, which can alleviate the semantic gap problem between function descriptions and API usage sequences, thereby improving the accuracy of the search.

[0011] The objective of the present invention is achieved through the following technical solutions:

[0012] A document-guided API sequence search method comprises the following steps:

[0013] Step 1: Dig into the API documentation repository

[0014] Obtain API set S by mining the API document repository API And the API documentation dictionary D API2doc , providing a data foundation for extracting API usage sequences from source code and implementing document-guided cross-modal attention and matching;

[0015] Step 2: Dig into the code repository

[0016] By mining the code repository, we construct a dataset D consisting of triples of “function description-API usage sequence-API document sequence”. set , and an API for searching using the sequence database D base ;

[0017] Step 3: Data preprocessing and representation

[0018] Preprocess the original function description, API usage sequence, and API document sequence and convert them into feature vectors X that can be processed by the deep learning model desc , X api and Xdoc ;

[0019] Step 4: Network model construction

[0020] Build a network model to extract features of function description, API usage sequence and API document sequence, and calculate the similarity between function description and API usage sequence;

[0021] Step 5: Network model training and API usage sequence search

[0022] Train the network model and use the trained network model to implement API usage sequence search.

[0023] Compared with the prior art, the present invention has the following advantages:

[0024] 1. This paper proposes an API usage sequence search task for the first time, and proposes a document-guided API usage sequence search model in this task. The model consists of an intra-modal feature extraction module, a document-guided cross-modal attention module, and a document-guided cross-modal matching module. The semantic gap problem in the cross-modal attention stage is alleviated by the document-guided cross-modal attention module, and the semantic gap problem in the cross-modal matching stage is alleviated by the document-guided cross-modal matching module.

[0025] 2. The present invention proposes a document-guided cross-modal attention module, which calculates the attention score of each API and its document for function queries under the guidance of API documents, as well as the attention score of the words in each function query for the API usage sequence, which can effectively alleviate the impact of the semantic gap between API and text on the attention score calculation.

[0026] 3. The present invention proposes a document-guided cross-modal matching module, which calculates the similarity between API usage sequence and function query under the guidance of API document, and can effectively alleviate the impact of the semantic gap between API and text on cross-modal similarity calculation. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] Figure 1 This is the overall flow chart of the API usage sequence search guided by the documentation.

[0028] Figure 2 It is a network model structure diagram.

[0029] Figure 3 It is an instance of the API using the sequence extraction process.

[0030] Figure 4 It is an example of the API using the sequence preprocessing process.

[0031] Figure 5 It is an instance of the API sequence search process. DETAILED DESCRIPTION

[0032] The technical solution of the present invention is further described below in conjunction with the accompanying drawings, but is not limited thereto. Any modification or equivalent replacement of the technical solution of the present invention without departing from the spirit and scope of the technical solution of the present invention should be included in the protection scope of the present invention.

[0033] The present invention provides a document-guided API sequence search method, which includes the following stages:

[0034] 1. Software repository mining phase: This includes extracting API entities and their corresponding documents based on API documents, mining the code repository to build a training dataset and an API usage sequence database for search.

[0035] 2. Network model construction and training phase: Figure 2 As shown in the figure, the network model consists of three modules, namely, the intra-modal feature extraction module, the document-guided cross-modal attention module, and the document-guided cross-modal matching module. Among them, the intra-modal feature extraction module is used to extract the internal semantics of each modal data; the document-guided cross-modal attention module is used for the cross-modal semantics between different modal data; the document-guided cross-modal matching module is used to give the similarity between the function description and the API usage sequence. After the network model is constructed, the gradient descent algorithm is used to train the network model with the triple loss function as the optimization target.

[0036] 3. API usage sequence search phase: Use the trained network model to search for the API usage sequence that can implement the given function query, and recommend it to the user in the form of a sorted list.

[0037] like Figure 1 As shown, the specific implementation steps are as follows:

[0038] Step 1: Dig into the API documentation repository

[0039] Obtain API set S by mining the API document repository API And the API documentation dictionary D API2doc , providing a data foundation for extracting API usage sequences from source code and implementing document-guided cross-modal attention and matching. The specific steps are as follows:

[0040] Step 11: Screening Candidate API Documents

[0041] Traverse all API documents officially provided by JDK, and select all .xml files whose first letter of the file name is an uppercase letter and whose file name contains only uppercase and lowercase letters as candidate API documents;

[0042] Step 12: Extract API data

[0043] Extract the API class name class_name, method name method_name and method documentation from all candidate API documents. The specific method is as follows:

[0044] Step 121: Extract the API class name and class description from the "h1" node whose "class" attribute is "title", and use the class description as the documentation of the constructor;

[0045] Step 122: Find all API method names and their documents from the "section" node whose "class" attribute is "method-details"; if an API has no document, set its document to an empty string;

[0046] Step 13: Build API entity collection

[0047] Define the constructor type API entity in the form of "class_name.new", and construct the member method type API entity in the form of "class_name.method_name". All API entities together constitute the API set S API ;

[0048] Step 14: Build the API documentation dictionary

[0049] Step 141, extract the first sentence in the document corresponding to each API, specifically, find the position end_pos where ".\n" or "." first appears in each API document, and slice the API document within the index range from 0 to end_pos, so as to obtain the first sentence in the API document;

[0050] Step 142: Use the API entity as the key and the first sentence in its document as the value to construct the API document dictionary D API2doc .

[0051] Step 2: Dig into the code repository

[0052] By mining the code repository, we construct a dataset D consisting of triples of “function description-API usage sequence-API document sequence”. set and an API for searching using the sequence database D base The specific steps are as follows:

[0053] Step 21: Filter all Java software projects with at least one star from GitHub and initialize the API using the sequence dataset D set is an empty set;

[0054] Step 22: Traverse the .java files in all software projects;

[0055] Step 23: Traverse all function definition code blocks contained in the .java file;

[0056] Step 24: Determine whether the currently traversed method definition code block contains a function annotation Desc that does not start with the string "TODO", "NOTE" or "TEST", wherein when determining whether the function annotation starts with a specific string, it is case insensitive; if not, return to step 23; if contained, execute step 25;

[0057] Step 25: Build the control flow graph (CFG) of the function through the existing static code analysis tool;

[0058] Step 26: Use the Depth-First Search (DFS) algorithm to traverse all paths contained in the control flow graph without passing through repeated edges to form a control flow path (CFP) set;

[0059] Step 27: traverse each CFP in the CFP set;

[0060] Step 28: Traverse each statement node in the CFP;

[0061] Step 29: Extract the API usage sequence in the statement from the statement node according to the following rules:

[0062] (1) For a class instantiation structure "new C()", where C is a class, if "C.new" belongs to S API , its corresponding API usage sequence is [C.new], otherwise it is an empty list;

[0063] (2) For the method call structure "om()", where o is the object, m is the method, and C is the class corresponding to object o, if "Cm" belongs to S API , its corresponding API usage sequence is [Cm], otherwise it is an empty list;

[0064] (3) For the nested method call structure "01.m1(o2.m2(), ..., o n .m n ())", where o i For the object, m i For the method, C i For object o i The corresponding class, its corresponding API usage sequence is [C2.m2→...→C n .mn →C1.m1], judge each method C i .m i Is it S? API If it does not belong, delete the method from the API usage sequence; if it does belong, keep the method;

[0065] (4) For the method cascade call structure "o1.m1().m2()...m n ()", where o i For the object, m i For the method, C i For object o i The corresponding class, its corresponding API usage sequence is [C1.m1→C2.m2→...→C n .m n ], judge each method C i .m i Is it S? API If it does not belong, delete the method from the API usage sequence; if it does belong, keep the method;

[0066] (5) For the square declaration structure "C func(C1o1, C2o2, ..., C n o n )", where C is the return value type of the method, func is the method name, i For the object, C i For object o i The corresponding class, its corresponding API usage sequence is [C1.new→C2.new→...→C n .new], judge each method C i .new whether it belongs to S API If it does not belong, delete the method from the API usage sequence; if it does belong, keep the method;

[0067] (6) If a given statement contains at least one of the above structures, the API usage sequences corresponding to different structures are concatenated according to the order of appearance from left to right and the order of nested calls from inside to outside to obtain the API usage sequence of the statement;

[0068] (7) If a given statement does not contain the above structure, its corresponding API usage sequence is an empty list;

[0069] Step 210: Determine whether all statement nodes in the CFP have been traversed. If so, execute step 211; if not, return to step 28;

[0070] Step 211: concatenate the API usage sequence in each CFP according to the statement order to obtain the API usage sequence APISeq corresponding to the given CFP;

[0071] Step 212: By retrieving D API2doc Use the sequence to build the API document sequence DocSeq for each API. If the document of an API is an empty string, set its document to the API itself.

[0072] Step 213: Construct a triple (Desc, APISeq, DocSeq) consisting of a function annotation, an API usage sequence, and an API document sequence, and add it to D set middle;

[0073] Step 214: Determine whether all CFPs in the CFG have been traversed. If so, execute step 215; if not, return to step 27;

[0074] Step 215: Determine whether all function definition code blocks contained in the file have been traversed. If so, execute step 216; if not, return to step 23;

[0075] Step 216: Determine whether all .java files have been traversed. If so, execute step 217; if not, return to step 22;

[0076] Step 217: Using D set All API usage sequences in the database D constitute the API usage sequence database used for searching base .

[0077] Step 3: Data preprocessing and representation

[0078] Preprocess the raw data and convert it into a feature vector X that can be processed by the deep learning model desc The specific steps are as follows:

[0079] Step 31: Generate vector representation of functional description

[0080] Each word in a given function description is represented as a Word2Vec word embedding representation, thereby obtaining a vector representation of the function description, denoted as Where n is the number of words and d is the word embedding dimension;

[0081] Step 32: Generate vector representation of API usage sequence

[0082] Step 321: Initialize vector representation is an all-zero tensor, where m is the number of APIs and d is the word embedding dimension;

[0083] Step 322: Traverse each API in the API usage sequence;

[0084] Step 323: Initialize the current API buffer Buff api as an empty character, and initialize the word list List api as an empty list. Starting from the first character, traverse each character c in the API in turn i , where i is the index of the character;

[0085] Step 324: Determine whether the following four conditions are simultaneously satisfied: (1) c i is an uppercase letter or a number; (2) i ≠ 1; (3) c i-1 is a lowercase letter; (4) Buff api is not an empty string; if satisfied, add Buff api to List api , and set Buff api to c i , then execute Step 328; otherwise, execute Step 325;

[0086] Step 325: Determine whether the following four conditions are simultaneously satisfied: (1) c i is an uppercase letter; (2) i < n, where n is the number of characters in the API; (3) c i+1 is a lowercase letter; (4) Buff api is not an empty string; if satisfied, add Buff api to List api , and set Buff api to c i , execute Step 328; otherwise, execute Step 326;

[0087] Step 326: If c i is ". " or "-", add Buff api to List api , and set Buff api to an empty string, then execute Step 328; otherwise execute Step 327;

[0088] Step 327: Lowercase c i and splice it to the end of Buff api ;

[0089] Step 328: Determine whether i = n holds. If it holds, execute Step 329; otherwise, return to Step 323;

[0090] Step 329: Determine whether Buff api is an empty string. If it is not, add Buff api to Listapi , and execute step 3210; if not, directly execute step 3210;

[0091] Step 3210: List api Remove duplicates. If a word appears multiple times, only the first occurrence of the word is retained.

[0092] Step 3211: List api Each word in is represented as a Word2Vec word embedding representation and averaged to obtain a vector representation for each API and assign it to X api The corresponding position;

[0093] Step 3212: Determine whether all APIs have been traversed; if so, execute step 314; if not, return to step 322;

[0094] Step 33: Generate vector representation of API document sequence

[0095] Step 331: traverse each document in the API document sequence;

[0096] Step 332: Represent each word in the document as a Word2Vec word embedding representation and average it to obtain a vector representation of the document;

[0097] Step 333: Determine whether all documents have been traversed. If not, return to step 331; if yes, concatenate the vector representations of each document in order to obtain the vector representation of the API usage sequence, recorded as Where m is the number of words and d is the word embedding dimension.

[0098] Step 4: Network model construction

[0099] Build a network model to extract features of function description, API usage sequence and API document sequence, and calculate the similarity between function description and API usage sequence. The specific steps are as follows:

[0100] Step 41: Vector representation X of function query, API usage sequence and API document sequence desc , X api and X doc Add sine and cosine position encoding to model the position information of words, APIs or API documents in the sequence;

[0101] Step 42: Intra-modal feature extraction stage

[0102] In the intra-modal feature extraction module, three different multi-head self-attention models are used to extract X desc, X api and X doc The semantic features of the modality are obtained and

[0103] Step 43: Document-Guided Cross-Modal Attention Stage

[0104] In the document-guided cross-modal attention module, the intra-modal semantic representation and As input, we get their respective inter-modal semantic representations and This stage is also implemented based on the multi-head self-attention model. The specific steps are as follows:

[0105] Step 431: Define the value input of the self-attention model as X V , key input is X K , the query input is X Q ;

[0106] Step 432: In the cross-modal attention process of function description, let Model Output In the cross-modal attention process of API usage sequence, let Model Output In the cross-modal attention process of the API document sequence, let Model Output

[0107] Step 44: Document-guided cross-modal similarity calculation phase

[0108] Step 441: In the document-guided cross-modal matching module, the representation of the API usage sequence and the API document sequence are fused to obtain the representation of the API usage sequence containing the document information.

[0109]

[0110] Step 442: Convert the function query and API usage sequence into a single vector representation by performing a max pooling operation along the word or API direction. and

[0111]

[0112]

[0113] Step 443: Calculate and The cosine similarity is used as the matching score of the sequence used by the function query and API:

[0114]

[0115] Step 5: Network model training and API usage sequence search

[0116] Train the network model and use the trained network model to implement API usage sequence search. The specific steps are as follows:

[0117] Step 51: Take the following triple loss function as the optimization target and optimize the network model using the Adam gradient descent algorithm:

[0118]

[0119] Where N is the size of the training set, is the matching score of the i-th positive sample pair (i.e., the matching function description-API usage sequence data pair) in the dataset, is the matching score of the i-th negative sample pair constructed by negative sampling, and c is the threshold;

[0120] Step 52: Calculate the similarity between the function query and all API usage sequences in the API usage sequence database through the network model trained in step 51;

[0121] Step 53: Sort all API usage sequences in the database in descending order according to the matching scores, and return the first N results in the sorted list to the user.

[0122] Embodiment 1:

[0123] This article takes the method of implementing the "Create and write files." function as an example to introduce the API usage sequence extraction process. Figure 3 As shown in the figure, we first build a control flow graph for the source code. Then, we extract all control flow paths from the control flow graph through a depth-first search without repeated edges. Finally, we generate the corresponding API usage sequence for each control flow path.

[0124] Embodiment 2:

[0125] Taking the API usage sequence that implements the "Create and write files." function as an example, the process of API usage sequence preprocessing is introduced. Figure 4 As shown, the original API usage sequence is first split and lowercase according to the rules formulated by the present invention, and then converted into a word sequence. Subsequently, only the first occurrence of each word in the sequence is retained to reduce the weight of the sequence, thereby reducing information redundancy.

[0126] Embodiment 3:

[0127] Taking the function query "Convert an inputStream to a String." as an example, this article introduces the process of implementing API usage sequence search based on the trained model. Figure 5 As shown in the figure. First, for a given query, the trained network model is used to calculate the similarity score between the query and all API usage sequences in the database. Then, all API usage sequences are sorted in descending order according to the score and returned to the user.

Claims

1. A document-guided API sequence search method, characterized in that The method comprises the following steps: Step 1: Dig into the API documentation repository Obtain API set S by mining the API document repository API And the API documentation dictionary D API2doc , providing a data foundation for extracting API usage sequences from source code and implementing document-guided cross-modal attention and matching; Step 2: Dig into the code repository By mining the code repository, we construct a dataset D consisting of triples of "function description-API usage sequence-API document sequence" set and an API for searching using the sequence database D base ; Step 3: Data preprocessing and representation Preprocess the original function description, API usage sequence, and API document sequence and convert them into feature vectors X that can be processed by the deep learning model desc , X api and X doc ; Step 4: Network model construction Construct a network model to realize feature extraction of function description, API usage sequence and API document sequence, and similarity calculation between function description and API usage sequence, wherein the network model comprises an intra-modal feature extraction module, a document-guided cross-modal attention module and a document-guided cross-modal matching module, wherein: the intra-modal feature extraction module is used to extract the internal semantics of each modal data; the document-guided cross-modal attention module is used for cross-modal semantics between different modal data; the document-guided cross-modal matching module is used to give the similarity between function description and API usage sequence; The specific steps are as follows: Step 41: Vector representation X of function query, API usage sequence and API document sequence desc , X api and X doc Add sine and cosine position encoding to model the position information of words, APIs or API documents in the sequence; Step 42: Intra-modal feature extraction stage Use three different multi-head self-attention models to extract X desc , X api and X doc The semantic features of the modality are obtained and Step 43: Document-Guided Cross-Modal Attention Stage In the document-guided cross-modal attention module, the intra-modal semantic representation and As input, we get their respective inter-modal semantic representations and Step 44: Document-guided cross-modal similarity calculation phase Step 441: In the document-guided cross-modal matching module, the representation of the API usage sequence and the API document sequence are fused to obtain the representation of the API usage sequence containing the document information. Step 442: Convert the function query and API usage sequence into a single vector representation by performing a max pooling operation along the word or API direction. and Step 443: Calculate and The cosine similarity e of is used as the matching score between the function query and the API usage sequence; Step 5: Network model training and API usage sequence search Train the network model and use the trained network model to implement API usage sequence search.

2. The document-guided API sequence search method according to claim 1, characterized in that The specific steps of step 1 are as follows: Step 11: Screening Candidate API Documents Traverse all API documents officially provided by JDK, and select all .xml files whose first letter of the file name is an uppercase letter and whose file name contains only uppercase and lowercase letters as candidate API documents; Step 12: Extract API data Extract the API class name class_name, method name method_name and method documentation from all candidate API documents; Step 13: Build API entity collection Define the constructor API entity in the form of "class_name.new", and construct the member method API entity in the form of "class_name.method_name". All API entities together constitute the API set S API ; Step 14: Build the API documentation dictionary Step 141, extract the first sentence in the document corresponding to each API, specifically, find the position end_pos where ".\n" or "." first appears in each API document, and slice the API document within the index range from 0 to end_pos, so as to obtain the first sentence in the API document; Step 142: Use the API entity as the key and the first sentence in its document as the value to construct the API document dictionary D API2doc .

3. The document-guided API sequence search method according to claim 2, characterized in that The specific method of step 12 is as follows: Step 121: Extract the API class name and class description from the "h1" node whose "class" attribute is "title", and use the class description as the documentation of the constructor; Step 122: Find all API method names and their documents from the "section" node whose "class" attribute is "method-details"; if an API has no document, set its document to an empty string.

4. The document-guided API sequence search method according to claim 1, characterized in that The specific steps of step 2 are as follows: Step 21: Filter all Java software projects with at least one star from GitHub and initialize the API using the sequence dataset D set is an empty set; Step 22: Traverse the .java files in all software projects; Step 23: Traverse all function definition code blocks contained in the .java file; Step 24: Determine whether the definition code block contains a function annotation Desc that does not start with the string "TODO", "NOTE" or "TEST", wherein when determining whether the function annotation starts with a specific string, it is case insensitive; if not, return to step 23; if contained, execute step 25; Step 25: Build the CFG of the function; Step 26: Use the depth-first search algorithm to traverse all paths included in the control flow graph without passing through repeated edges to form a CFP set; Step 27: traverse each CFP in the CFP set; Step 28: Traverse each statement node in the CFP; Step 29: Extract the API usage sequence in the statement from the statement node according to the following rules: (1) For a class instantiation structure "new C()", where C is a class, if "C.new" belongs to S API , its corresponding API usage sequence is [C.new], otherwise it is an empty list; (2) For the method call structure "om()", where o is the object, m is the method, and C is the class corresponding to object o, if "Cm" belongs to S API , its corresponding API usage sequence is [Cm], otherwise it is an empty list; (3) For the nested method call structure "o1.m1(o2.m2(),…,o n .m n ())", where o i For the object, m i For the method, C i For object o i The corresponding class, its corresponding API usage sequence is [C2.m2→…→C n .m n →C1.m1], judge each method C i .m i Is it S? API If it does not belong, delete the method from the API usage sequence; if it does belong, keep the method; (4) For the method cascade call structure "o1.m1().m2()...m n ()", where o i For the object, m i For the method, C i For object o i The corresponding class, its corresponding API usage sequence is [C1.m1→C2.m2→…→C n .m n ], judge each method C i .m i Is it S? API If it does not belong, delete the method from the API usage sequence; if it does belong, keep the method; (5) For the declaration structure "C func(C1 o1, C2 o2, ..., C n o n )", where C is the return value type of the method, func is the method name, i For the object, C i For object o i The corresponding class, its corresponding API usage sequence is [C1.new→C2.new→…→C n .new], judge each method C i .new whether it belongs to S API If it does not belong, delete the method from the API usage sequence; if it does belong, keep the method; (6) If a given statement contains at least one of the above structures, the API usage sequences corresponding to different structures are concatenated according to the order of appearance from left to right and the order of nested calls from inside to outside to obtain the API usage sequence of the statement; (7) If a given statement does not contain the above structure, its corresponding API usage sequence is an empty list; Step 210: Determine whether all statement nodes in the CFP have been traversed. If so, execute step 211; if not, return to step 28; Step 211: concatenate the API usage sequence in each CFP according to the statement order to obtain the API usage sequence APISeq corresponding to the given CFP; Step 212: By retrieving D API2doc Use the sequence to build the API document sequence DocSeq for each API. If the document of an API is an empty string, set its document to the API itself. Step 213: Construct a triple (Desc, APISeq, DocSeq) consisting of a function annotation, an API usage sequence, and an API document sequence, and add it to D set middle; Step 214: Determine whether all CFPs in the CFG have been traversed. If so, execute step 215; if not, return to step 27; Step 215: Determine whether all function definition code blocks contained in the file have been traversed. If so, execute step 216; if not, return to step 23; Step 216: Determine whether all .java files have been traversed. If so, execute step 217; if not, return to step 22; Step 217: Using D set All API usage sequences in the database D constitute the API usage sequence database used for searching base .

5. The document-guided API sequence search method according to claim 1, characterized in that The specific steps of step 3 are as follows: Step 31: Generate vector representation of functional description Each word in a given function description is represented as a Word2Vec word embedding representation, thereby obtaining a vector representation of the function description, denoted as Where n is the number of words and d is the word embedding dimension; Step 32: Generate vector representation of API usage sequence Step 321: Initialize vector representation is an all-zero tensor, where m is the number of APIs and d is the word embedding dimension; Step 322: traverse each API in the API usage sequence; Step 323: Initialize the current API buffer Buff api Initialize the word list List with an empty character api It is an empty list, starting from the first character, and traverses each character c in the API in turn i , where i is the index of the character; Step 324: Determine whether the following four conditions are met at the same time: (1) c i is a capital letter or number; (2) i≠1; (3) c i-1 is a lowercase letter; (4) Buff api Not an empty string; if satisfied, Buff api Add to List api , and Buff api Set to c i , then execute step 328; Otherwise, execute step 325; Step 325: Determine whether the following four conditions are simultaneously satisfied: (1) c i is an uppercase letter; (2) i < n, where n is the number of characters in the API; (3) c i+1 is a lowercase letter; (4) Buff api is not an empty string; if satisfied, add Buff api to List api , and set Buff api to c i , and execute Step 328; Otherwise, execute step 326; Step 326: If c i If it is ". " or "_", then Buff api Add to List api , and Buff api Set to an empty string, then execute step 328; Otherwise, execute step 327; Step 327: c i Lowercase and concatenate to Buff api back; Step 328: Determine whether i=n is true, if so, execute step 329; Otherwise, return to step 323; Step 329: Determine Buff api Is it an empty string? If not, Buff api Add to List api , and execute step 3210; if yes, directly execute step 3210; Step 3210: List api Remove duplicates. If a word appears multiple times, only the first occurrence of the word is retained. Step 3211: List api Each word in is represented as a Word2Vec word embedding representation and averaged to obtain a vector representation for each API and assign it to X api The corresponding position; Step 3212: Determine whether all APIs have been traversed; if so, execute step 314; if not, return to step 322; Step 33: Generate vector representation of API document sequence Step 331: traverse each document in the API document sequence; Step 332: Represent each word in the document as a Word2Vec word embedding representation and average it to obtain a vector representation of the document; Step 333: Determine whether all documents have been traversed. If not, return to step 331; if so, concatenate the vector representations of each document in order to obtain the vector representation of the API usage sequence, recorded as Where m is the number of words and d is the word embedding dimension.

6. The document-guided API sequence search method according to claim 1, characterized in that The specific steps of step 43 are as follows: Step 431: Define the value input of the self-attention model as X V , key input is X K , the query input is X Q ; Step 432: In the cross-modal attention process of function description, let Model Output In the cross-modal attention process of API usage sequence, let Model Output In the cross-modal attention process of the API document sequence, let Model Output 7. The document-guided API sequence search method according to claim 1, characterized in that Said The calculation formula is: and The calculation formula is: The calculation formula of cosine similarity e is:

8. The document-guided API sequence search method according to claim 1, characterized in that The specific steps of step 5 are as follows: Step 51: Take the following triple loss function as the optimization target and optimize the network model using the Adam gradient descent algorithm: Where N is the size of the training set, is the matching score of the i-th positive sample pair in the dataset, is the matching score of the i-th negative sample pair constructed by negative sampling, and c is the threshold; Step 52: Calculate the similarity between the function query and all API usage sequences in the API usage sequence database through the network model trained in step 51; Step 53: Sort all API usage sequences in the database in descending order according to the matching scores, and return the first N results in the sorted list to the user.