An API recommendation system and method based on deep learning and semantic information

Through an API recommendation system based on deep learning and semantic information, the code context is used to automatically recommend APIs, which solves the problems of poor accuracy and reliability in existing technologies and improves the efficiency and quality of Python code writing.

CN116881568BActive Publication Date: 2025-09-16HAINAN UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310912315.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-07-24
Publication Date
2025-09-16
Estimated Expiration
2043-07-24

Smart Images

  • Figure CN116881568B_ABST
    Figure CN116881568B_ABST
Patent Text Reader

Abstract

The present invention belongs to the field of software engineering technology, and discloses an API recommendation system and method based on deep learning and semantic information. The system includes an API recommendation point positioning unit, a data preprocessing unit, a data extraction unit, a data encoding unit, and an API recommendation unit connected in sequence. The method includes the following steps: receiving the user's source code, obtaining the code context, caller object, and positive example API before the recommendation point of the source code; obtaining the source code token sequence, AST token sequence, natural language token sequence, and variable type of the caller object; obtaining the candidate API and optimistic data flow token sequence of the recommendation point; obtaining the semantic feature vector and the data flow feature vector; and obtaining a recommendation list of candidate APIs. The present invention solves the problems of poor recommendation accuracy, poor reliability, and heavy query burden in the prior art.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of software engineering technology, and specifically relates to an API recommendation system and method based on deep learning and semantic information. Background Art

[0002] In recent years, with the continuous development of artificial intelligence technology, Python has gradually become one of the most popular programming languages. Many popular machine learning and deep learning programming frameworks, such as TensorFlow and PyTorch, support applications written in Python. In software development using integrated development environments, Python's Application Programming Interface (API) recommendations can help developers quickly find the right API and improve their programming efficiency.

[0003] Currently, there are two main API recommendation methods for the Python language: code-based and query-based. Code-based API recommendation methods can recommend incorrect API types when type inference fails, and rely on local data streams for API recommendations. When the local data streams don't contain information about the correct APIs, the recommended APIs are often incorrect. Query-based API methods require users to provide query statements and then use them to recommend APIs from a knowledge base. However, users often need to consider the context when writing code to determine the APIs they want, and this additional query burden increases the user's workload. Summary of the Invention

[0004] In order to solve the problems of poor recommendation accuracy, poor reliability and heavy query burden in the prior art, the present invention aims to provide an API recommendation system and method based on deep learning and semantic information.

[0005] The technical solution adopted in the present invention is:

[0006] An API recommendation system based on deep learning and semantic information, comprising an API recommendation point positioning unit, a data preprocessing unit, a data extraction unit, a data encoding unit, and an API recommendation unit connected in sequence, wherein the API recommendation point positioning unit and the API recommendation unit are both connected to a user's code server, and the API recommendation unit is provided with a deep learning API recommendation model;

[0007] An API recommendation point location unit is used to receive the source code sent by the user's code server and obtain the code context, caller object, and positive example API before the recommendation point in the source code;

[0008] A data preprocessing unit is used to obtain source code token sequences, AST token sequences, and natural language token sequences based on the code context before the recommendation point, and obtain the variable type of the caller object using post-processing type inference based on the caller object;

[0009] A data extraction unit is used to obtain candidate APIs for the recommendation point based on the variable type of the caller object and the positive example API, and to obtain an optimistic data flow token sequence based on the code context before the recommendation point;

[0010] A data encoding unit is used to obtain a semantic feature vector based on a source code token sequence, an AST token sequence, and a natural language token sequence, and to obtain a data flow feature vector of a candidate API based on an optimistic data flow token sequence and a candidate API;

[0011] The API recommendation unit is used to obtain a recommendation list of candidate APIs based on the semantic feature vector and the data stream feature vector using a deep learning API recommendation model, and send the recommendation list to the user's code server.

[0012] Furthermore, the data preprocessing unit includes a type inference module and a code parsing module. The type inference module is provided with a type inference model, which is the first large pre-trained model constructed using the Transformer algorithm. The code parsing module is provided with a code parsing model, which is a natural language processing model constructed using a natural language word segmentation algorithm.

[0013] Furthermore, the data extraction unit includes a candidate API generation module and a feature collection module.

[0014] Furthermore, the data encoding unit includes a first data encoding module and a second data feature encoding module. The first data encoding module is provided with a first data encoding model, which is a second large pre-trained model constructed using the Transformer algorithm. The second data feature encoding module is provided with a second data feature encoding model, which is an Ngram language model.

[0015] An API recommendation method based on deep learning and semantic information, applied to an API recommendation system, is characterized in that the method comprises the following steps:

[0016] Receive the user's source code, obtain the code context, caller object, and positive example API before the recommended point in the source code;

[0017] According to the code context before the recommendation point, the source code token sequence, AST token sequence and natural language token sequence are obtained, and the variable type of the caller object is obtained by using post-processing type inference based on the caller object;

[0018] According to the variable type of the caller object and the positive example API, the candidate API of the recommendation point is obtained, and according to the code context before the recommendation point, the optimistic data flow token sequence is obtained;

[0019] Obtain semantic feature vectors based on source code token sequences, AST token sequences, and natural language token sequences, and obtain data flow feature vectors of candidate APIs based on optimistic data flow token sequences and candidate APIs;

[0020] Based on the semantic feature vector and data stream feature vector, a deep learning API recommendation model is used to obtain a recommendation list of candidate APIs and send the recommendation list to the user.

[0021] Furthermore, receiving the user's source code and obtaining the code context, caller object, and positive example API before the recommended point in the source code include the following steps:

[0022] Receive source code sent by users;

[0023] Locate recommended points in the source code;

[0024] According to the recommended point, the code context, caller object, and positive example API before the recommended point in the source code are obtained.

[0025] Furthermore, according to the code context before the recommendation point, the source code token sequence, the AST token sequence, and the natural language token sequence are obtained, and according to the caller object, the variable type of the caller object is obtained by using post-processing type inference, including the following steps:

[0026] Based on the underscore naming convention, camelCase naming convention, and spaces, the code parsing model is used to segment the code context before the recommendation point into a sequence of source code tokens.

[0027] According to the X-SBT method, the AST tree of the code context before the recommendation point is split into a sequence of AST tokens;

[0028] Based on the comments and documents in the code context before the recommendation point, use the code parsing model to segment the code context before the recommendation point into a natural language token sequence;

[0029] Use the static type inference tool to perform static type inference on the caller object. If the static type inference succeeds, the variable type of the caller object is obtained. Otherwise, proceed to the next step.

[0030] Obtain a combined token sequence based on the source code token sequence, the AST token sequence, and the natural language token sequence;

[0031] According to the combined token sequence, a type inference model is used to obtain the semantic vector;

[0032] Get word vectors based on candidate variable types;

[0033] Get the variable type range of the caller object based on the semantic vector and word vector;

[0034] Gets the variable type of the caller object based on the variable type scope of the caller object.

[0035] Furthermore, according to the variable type of the caller object and the positive example API, the candidate API of the recommendation point is obtained, and according to the code context before the recommendation point, the optimistic data flow token sequence is obtained, including the following steps:

[0036] According to the variable type of the caller object, collect the corresponding variable type of the positive example API to obtain the candidate API of the recommendation point;

[0037] Based on the basic abstract syntax, derive optimistic data flow rules;

[0038] According to the optimistic data flow rules, the optimistic data flow of the code context before the recommended point is extracted;

[0039] Collect the token sequences of the optimistic data stream to obtain the optimistic data stream token sequence.

[0040] Furthermore, a semantic feature vector is obtained based on the source code token sequence, the AST token sequence, and the natural language token sequence, and a data flow feature vector of the candidate API is obtained based on the optimistic data flow token sequence and the candidate API, including the following steps:

[0041] Obtain a combined token sequence based on the source code token sequence, the AST token sequence, and the natural language token sequence;

[0042] Obtaining a semantic vector using a first data encoding model according to the combined token sequence;

[0043] Compress the semantic vector to obtain the semantic feature vector;

[0044] According to the data flow path containing the correct API, the corresponding optimistic data flow token sequence is collected to obtain the correct data flow token sequence;

[0045] Inputting the correct data stream token sequence into the second data encoding model for training to obtain an optimized second data encoding model;

[0046] Use the candidate API to replace the correct API in the correct data flow token sequence to obtain the corresponding replacement data flow token sequence;

[0047] Inputting the replacement data stream token sequence into the optimized second data encoding model to obtain the logarithmic probability score of the candidate API;

[0048] According to the logarithmic probability score, the data flow feature vector of the candidate API is obtained.

[0049] Furthermore, based on the semantic feature vector and the data stream feature vector, a deep learning API recommendation model is used to obtain a recommendation list of candidate APIs, and the recommendation list is sent to the user, including the following steps:

[0050] Concatenate the semantic feature vector and the data stream feature vector to obtain the combined feature vector of the candidate API;

[0051] Input the combined feature vector into the deep learning API recommendation model to obtain the API score of the candidate API;

[0052] Based on the API scores, a recommended list of candidate APIs is obtained and sent to the user.

[0053] The beneficial effects of the present invention are:

[0054] The present invention provides an API recommendation system and method based on deep learning and semantic information. The system adopts post-processing type inference. Even if the type inference of the dynamic language fails, the post-processing type inference can still give the correct type range, thereby reducing the recommendation of incorrect API types and improving the accuracy of recommendations. The system adds semantic information of the code context on the basis of local data flow information. When the information of the local data flow is insufficient to recommend the correct API, the system can also recommend the API through the semantic information of the code context, thereby improving the reliability of the recommendation. The system automatically recommends APIs based on the code context of the source code written by the user, without the need for the user to query, thereby reducing the query burden of the user. The system improves the efficiency and quality of Python code writing, reduces errors and debugging time in the writing process, and enhances the readability and maintainability of Python code.

[0055] Other beneficial effects of the present invention will be further described in the specific embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0056] Figure 1 This is a structural diagram of the API recommendation system based on deep learning and semantic information in the present invention.

[0057] Figure 2 This is a flowchart of the API recommendation method based on deep learning and semantic information in the present invention. DETAILED DESCRIPTION

[0058] The present invention will be further explained below with reference to the accompanying drawings and specific embodiments.

[0059] Example 1:

[0060] like Figure 1As shown, this embodiment provides an API recommendation system based on deep learning and semantic information, including an API recommendation point positioning unit, a data preprocessing unit, a data extraction unit, a data encoding unit, and an API recommendation unit connected in sequence. The API recommendation point positioning unit and the API recommendation unit are both connected to the user's code server, and the API recommendation unit is provided with a deep learning API recommendation model;

[0061] An API recommendation point location unit is used to receive the source code sent by the user's code server and obtain the code context, caller object, and positive example API before the recommendation point in the source code;

[0062] A data preprocessing unit is used to obtain source code token sequences, AST token sequences, and natural language token sequences based on the code context before the recommendation point, and obtain the variable type of the caller object using post-processing type inference based on the caller object;

[0063] A data extraction unit is used to obtain candidate APIs for the recommendation point based on the variable type of the caller object and the positive example API, and to obtain an optimistic data flow token sequence based on the code context before the recommendation point;

[0064] A data encoding unit is used to obtain a semantic feature vector based on a source code token sequence, an AST token sequence, and a natural language token sequence, and to obtain a data flow feature vector of a candidate API based on an optimistic data flow token sequence and a candidate API;

[0065] The API recommendation unit is used to obtain a recommendation list of candidate APIs based on the semantic feature vector and the data stream feature vector using a deep learning API recommendation model, and send the recommendation list to the user's code server.

[0066] Preferably, the data preprocessing unit includes a type inference module and a code parsing module. The type inference module is provided with a type inference model, which is a first large pre-trained model constructed using the Transformer algorithm. The code parsing module is provided with a code parsing model, which is a natural language processing model constructed using a natural language word segmentation algorithm.

[0067] A code parsing module is used to obtain source code token sequences, abstract syntax tree (AST) token sequences, and natural language token sequences based on the code context before the recommendation point using a code parsing model;

[0068] The type inference module is used to obtain the variable type of the caller object using the type inference model based on the caller object.

[0069] Preferably, the data extraction unit includes a candidate API generation module and a feature collection module;

[0070] The candidate API generation module is used to collect the positive example APIs of the corresponding variable types according to the variable types of the caller object, and obtain the candidate APIs of the recommended points;

[0071] The feature collection module is used to extract the optimistic data flow in the code context before the recommendation point and obtain the optimistic data flow feature token based on the optimistic data flow.

[0072] Preferably, the data encoding unit includes a first data encoding module and a second data feature encoding module, the first data encoding module is provided with a first data encoding model, the first data encoding model is a second large pre-trained model constructed using the Transformer algorithm, and the second data feature encoding module is provided with a second data feature encoding model, and the second data feature encoding model is an Ngram language model;

[0073] A first data encoding module is configured to obtain a semantic feature vector using a first data encoding model according to a source code token sequence, an AST token sequence, and a natural language token sequence;

[0074] The second data feature encoding module is used to collect optimistic data flow feature tokens based on the data flow path containing the correct API, obtain the correct data flow feature tokens, and use the second data feature encoding model based on the correct data flow feature tokens and the candidate API to obtain the data flow feature vector of the candidate API.

[0075] Example 2:

[0076] like Figure 2 As shown, this embodiment provides an API recommendation method based on deep learning and semantic information, which is applied to an API recommendation system. The method is characterized in that: the method includes the following steps:

[0077] Receive the user's source code and obtain the code context, caller object, and positive example API before the recommended point in the source code, including the following steps:

[0078] Receive source code sent by users;

[0079] The source code of this embodiment is the get_p_contents method, as shown below:

[0080]

[0081]

[0082] Locate the recommended point of the source code according to the form of [Expression].targetAPI() soup.find_all('div');

[0083] According to the recommendation point, extract the code before soup.find_all('div') as the code context before the recommendation point, extract soup in soup.find_all('div') as the caller object, and extract find_all() as the positive example API;

[0084] According to the code context before the recommendation point, the source code token sequence, AST token sequence, and natural language token sequence are obtained. Then, based on the caller object, the variable type of the caller object is obtained using post-processing type inference. The steps include the following:

[0085] According to the underscore naming rule, camel case naming rule and space, the code parsing model is used to split the code context before the recommendation point into a source code token sequence C = {c1, c2, ..., c l}, where l is the length of the token sequence of the source code;

[0086] According to the X-Balanced Binary Search Tree (SBT) method, the AST tree of the code context before the recommendation point is split into an AST token sequence. The specific method is as follows: the code context before the recommendation point is converted into an AST tree, the nodes at the expression level and above in the AST tree are traversed, and the X-SBT (XML-like SBT) method is used to convert it into a linearized AST to obtain the AST token sequence A = {a1, a2, ..., a m}, where m represents the length of the token sequence of the AST;

[0087] According to the comments and documents in the code context before the recommendation point, the code context before the recommendation point is segmented into a natural language token sequence using a code parsing model. The specific method is as follows: the code context before the recommendation point is segmented into word sequences using the NLTK word segmentation method, and all method names and method call sequences are extracted from the code context before the recommendation point, and they are split into token sequences according to the camel case naming or underscore naming rules. When the documents and comments in the code context are not available, the token sequence of the method name is used instead of the token sequence of the comment and document. The final natural language token sequence is N = {n1,n2,…,n p}, where p is the length of the natural language token sequence;

[0088] In this embodiment, the source token sequence is {import,requests,import,os,import,pandas,aspd,from,bs4,import,BeautifulSoup,def,get,p,contents,(,html,),:,soup,=,BeautifulSoup,(,html,,,',lxml,',),div,items,=}, and the AST token sequence is {import,import,import,import, <expression> ,assignment,< / expression>}, the natural language token sequence is {get,p,contents,Beautiful,Soup};

[0089] Use the static type inference tool Pytype to perform static type inference on the caller object. If the static type inference is successful, the variable type of the caller object is obtained. Otherwise, proceed to the next step.

[0090] According to the source code token sequence, AST token sequence and natural language token sequence, obtain the combined token sequence Input = c1,…,c l ,[SEP],a1,…,a m ,[SEP],n1,…,n p ;

[0091] According to the combined token sequence, the semantic vector E is obtained using the type inference model. s ;

[0092] According to the candidate variable type, get the word vector E t ;

[0093] According to the semantic vector and word vector, the variable type range of the caller object is obtained. The formula is:

[0094]

[0095] dist(E s ,E t ) meets the criteria, it is within the scope of the variable type;

[0096] Get the variable type of the caller object according to the variable type range of the caller object;

[0097] The caller object is soup. The static type inference tool Pytype is used to perform static type inference on soup. The type obtained is None, which means that the static type inference fails. At this time, according to the combined token sequence Input = import,…,items,[SEP],import,…,assignment,[SEP],get,…,Soup, after vocabulary conversion, it is input into the type inference model. The type inference model will obtain the semantic vector E of the code context. s The candidate type will be selected from the packages imported in the code context. The source code of this embodiment imports the packages requests, os, pd, and BeautifulSoup. We take BeautifulSoup as an example and obtain the word vector E of BeautifulSoup. t , E s and E t After calculating the distance formula, it is the closest, so we infer that the type of soup is BeautifulSoup;

[0098] The type inference model built based on the pre-trained model is used to infer the correct type of the caller object, so that the subsequent candidate API generation module can collect candidate APIs of the correct type and improve the recommendation accuracy;

[0099] Based on the variable type of the caller object and the positive example API, the candidate API of the recommendation point is obtained. Based on the code context before the recommendation point, the optimistic data flow token sequence is obtained, including the following steps:

[0100] According to the variable type of the caller object, collect the corresponding variable type of the positive example API to obtain the candidate API of the recommendation point;

[0101] Based on the basic abstract syntax, optimistic data flow rules are derived; the five basic abstract syntaxes are assignment, loop, object property access / call, container access, and function parameter passing;

[0102] According to the optimistic data flow rules, the optimistic data flow of the code context before the recommended point is extracted;

[0103] Collecting token sequences of optimistic data streams to obtain optimistic data stream token sequences;

[0104] Obtaining a semantic feature vector based on the source code token sequence, the AST token sequence, and the natural language token sequence, and obtaining a data flow feature vector of the candidate API based on the optimistic data flow token sequence and the candidate API, including the following steps:

[0105] According to the source code token sequence, AST token sequence and natural language token sequence, obtain the combined token sequence Input = c1,…,cl ,[SEP],a1,…,a m ,[SEP],n1,…,n p ;

[0106] According to the combined token sequence, the semantic vector E is obtained using the first data encoding model. s , where E s is a 768-dimensional vector;

[0107] Compress the semantic vector to obtain a 10-dimensional semantic feature vector to obtain key semantic information;

[0108] According to the data flow path x0→x1→…→API→…→x n , collect the corresponding optimistic data stream token sequence, and get the correct data stream token sequence (x0, x1, ..., API, ..., x n );

[0109] Inputting the correct data stream token sequence into the second data encoding model for training to obtain an optimized second data encoding model;

[0110] Use the candidate API to replace the correct API in the correct data flow token sequence to obtain the corresponding replacement data flow token sequence;

[0111] Input the replacement data stream token sequence into the optimized second data encoding model to obtain the logarithmic probability score p of the candidate API i , i is the indicator;

[0112] Specifically, the following steps are included:

[0113] Using the Ngram language model, the data stream information of the replacement data stream token sequence is encoded into a first 1-dimensional feature vector;

[0114] Using the Ngram language model, we calculate the similarity features between the replacement data stream token sequence and the candidate API and encode them into a second 1-dimensional feature vector. The similarity feature calculation formula is:

[0115]

[0116] Among them, lcs k Represents a data stream token x i and the longest common token subsequence of the candidate API, d represents the data flow token x i The distance to the candidate API;

[0117] Using the Ngram language model, we calculate the co-occurrence features of the replacement data stream token sequence and the candidate API and encode them into a 2D feature vector. The formula for calculating the co-occurrence feature is:

[0118]

[0119] Where N(x) represents the number of occurrences of the caller object x, and N(API,x) represents the number of times the caller object x and the candidate API appear at the same time;

[0120] Obtaining the logarithmic probability scores of the first 1-dimensional feature vector, the second 1-dimensional feature vector, and the 2-dimensional feature vector;

[0121] According to the logarithmic probability score, obtain the 4-dimensional data flow feature vector of the candidate API;

[0122] Based on the semantic feature vector and data stream feature vector, a deep learning API recommendation model is used to obtain a recommendation list of candidate APIs and send the recommendation list to the user. The process includes the following steps:

[0123] The semantic feature vector and the data stream feature vector are concatenated to obtain a 14-dimensional combined feature vector of the candidate API.

[0124] Input the combined feature vector into the deep learning API recommendation model to obtain the API score of the candidate API;

[0125] The deep learning API recommendation model consists of a linear layer for extracting key features and a linear layer for recommendation. It is trained using a training dataset that includes commonly used Python open source code libraries and sample code from the official Python documentation.

[0126] Based on the API scores, a recommended list of candidate APIs is obtained and sent to the user.

[0127] The present invention provides an API recommendation system and method based on deep learning and semantic information. The system adopts post-processing type inference. Even if the type inference of the dynamic language fails, the post-processing type inference can still give the correct type range, thereby reducing the recommendation of incorrect API types and improving the accuracy of recommendations. The system adds semantic information of the code context on the basis of local data flow information. When the information of the local data flow is insufficient to recommend the correct API, the system can also recommend the API through the semantic information of the code context, thereby improving the reliability of the recommendation. The system automatically recommends APIs based on the code context of the source code written by the user, without the need for the user to query, thereby reducing the query burden of the user. The system improves the efficiency and quality of Python code writing, reduces errors and debugging time in the writing process, and enhances the readability and maintainability of Python code.

[0128] The present invention is not limited to the above optional embodiments. Anyone can derive various other forms of products based on the teachings of the present invention. The above specific embodiments should not be construed as limiting the scope of protection of the present invention. The scope of protection of the present invention shall be based on the scope defined in the claims, and the description can be used to interpret the claims.

Claims

1. An API recommendation system based on deep learning and semantic information, characterized by: It includes an API recommendation point positioning unit, a data preprocessing unit, a data extraction unit, a data encoding unit and an API recommendation unit connected in sequence, wherein the API recommendation point positioning unit and the API recommendation unit are both connected to the user's code server, and the API recommendation unit is provided with a deep learning API recommendation model; An API recommendation point location unit is used to receive the source code sent by the user's code server and obtain the code context, caller object, and positive example API before the recommendation point in the source code; A data preprocessing unit is used to obtain source code token sequences, AST token sequences, and natural language token sequences based on the code context before the recommendation point, and obtain the variable type of the caller object using post-processing type inference based on the caller object; A data extraction unit is used to obtain candidate APIs for the recommendation point based on the variable type of the caller object and the positive example API, and to obtain an optimistic data flow token sequence based on the code context before the recommendation point; A data encoding unit is used to obtain a semantic feature vector based on a source code token sequence, an AST token sequence, and a natural language token sequence, and to obtain a data flow feature vector of a candidate API based on an optimistic data flow token sequence and a candidate API; The API recommendation unit is used to obtain a recommendation list of candidate APIs based on the semantic feature vector and the data stream feature vector using a deep learning API recommendation model, and send the recommendation list to the user's code server.

2. The API recommendation system based on deep learning and semantic information according to claim 1, characterized in that: The data preprocessing unit includes a type inference module and a code parsing module. The type inference module is provided with a type inference model, and the type inference model is a first large pre-training model constructed using the Transformer algorithm. The code parsing module is provided with a code parsing model, and the code parsing model is a natural language processing model constructed using a natural language word segmentation algorithm.

3. The API recommendation system based on deep learning and semantic information according to claim 1, characterized in that: The data extraction unit includes a candidate API generation module and a feature collection module.

4. The API recommendation system based on deep learning and semantic information according to claim 1, characterized in that: The data encoding unit includes a first data encoding module and a second data feature encoding module. The first data encoding module is provided with a first data encoding model, and the first data encoding model is a second large pre-trained model constructed using the Transformer algorithm. The second data feature encoding module is provided with a second data feature encoding model, and the second data feature encoding model is an Ngram language model.

5. An API recommendation method based on deep learning and semantic information, applied to the API recommendation system according to any one of claims 1 to 4, characterized in that: The method comprises the following steps: Receive the user's source code, obtain the code context, caller object, and positive example API before the recommended point in the source code; According to the code context before the recommendation point, the source code token sequence, AST token sequence and natural language token sequence are obtained, and the variable type of the caller object is obtained by using post-processing type inference based on the caller object; According to the variable type of the caller object and the positive example API, the candidate API of the recommendation point is obtained, and according to the code context before the recommendation point, the optimistic data flow token sequence is obtained; Obtain semantic feature vectors based on source code token sequences, AST token sequences, and natural language token sequences, and obtain data flow feature vectors of candidate APIs based on optimistic data flow token sequences and candidate APIs; Based on the semantic feature vector and data stream feature vector, a deep learning API recommendation model is used to obtain a recommendation list of candidate APIs and send the recommendation list to the user.

6. The API recommendation method based on deep learning and semantic information according to claim 5, characterized in that: Receive the user's source code and obtain the code context, caller object, and positive example API before the recommended point in the source code, including the following steps: Receive source code sent by users; Locate recommended points in the source code; According to the recommended point, the code context, caller object, and positive example API before the recommended point in the source code are obtained.

7. The API recommendation method based on deep learning and semantic information according to claim 5, characterized in that: According to the code context before the recommendation point, the source code token sequence, AST token sequence, and natural language token sequence are obtained. Then, based on the caller object, the variable type of the caller object is obtained using post-processing type inference. The steps include the following: Based on the underscore naming convention, camelCase naming convention, and spaces, the code parsing model is used to segment the code context before the recommendation point into a sequence of source code tokens. According to the X-SBT method, the AST tree of the code context before the recommendation point is split into a sequence of AST tokens; Based on the comments and documents in the code context before the recommendation point, use the code parsing model to segment the code context before the recommendation point into a natural language token sequence; Use the static type inference tool to perform static type inference on the caller object. If the static type inference succeeds, the variable type of the caller object is obtained. Otherwise, proceed to the next step. Obtain a combined token sequence based on the source code token sequence, the AST token sequence, and the natural language token sequence; According to the combined token sequence, a type inference model is used to obtain the semantic vector; Get word vectors based on candidate variable types; Get the variable type range of the caller object based on the semantic vector and word vector; Gets the variable type of the caller object based on the variable type scope of the caller object.

8. The API recommendation method based on deep learning and semantic information according to claim 5, characterized in that: Based on the variable type of the caller object and the positive example API, the candidate API of the recommendation point is obtained. Based on the code context before the recommendation point, the optimistic data flow token sequence is obtained, including the following steps: According to the variable type of the caller object, collect the corresponding variable type of the positive example API to obtain the candidate API of the recommendation point; Based on the basic abstract syntax, derive optimistic data flow rules; According to the optimistic data flow rules, the optimistic data flow of the code context before the recommended point is extracted; Collect the token sequences of the optimistic data stream to obtain the optimistic data stream token sequence.

9. The API recommendation method based on deep learning and semantic information according to claim 5, characterized in that: Obtaining a semantic feature vector based on the source code token sequence, the AST token sequence, and the natural language token sequence, and obtaining a data flow feature vector of the candidate API based on the optimistic data flow token sequence and the candidate API, including the following steps: Obtain a combined token sequence based on the source code token sequence, the AST token sequence, and the natural language token sequence; Obtaining a semantic vector using a first data encoding model according to the combined token sequence; Compress the semantic vector to obtain the semantic feature vector; According to the data flow path containing the correct API, the corresponding optimistic data flow token sequence is collected to obtain the correct data flow token sequence; Inputting the correct data stream token sequence into the second data encoding model for training to obtain an optimized second data encoding model; Use the candidate API to replace the correct API in the correct data flow token sequence to obtain the corresponding replacement data flow token sequence; Inputting the replacement data stream token sequence into the optimized second data encoding model to obtain the logarithmic probability score of the candidate API; According to the logarithmic probability score, the data flow feature vector of the candidate API is obtained.

10. The API recommendation method based on deep learning and semantic information according to claim 5, characterized in that: Based on the semantic feature vector and data stream feature vector, a deep learning API recommendation model is used to obtain a recommendation list of candidate APIs and send the recommendation list to the user. The process includes the following steps: Concatenate the semantic feature vector and the data stream feature vector to obtain the combined feature vector of the candidate API; Input the combined feature vector into the deep learning API recommendation model to obtain the API score of the candidate API; Based on the API scores, a recommended list of candidate APIs is obtained and sent to the user.

Citation Information

Patent Citations

  • Python API real-time recommendation method based on context analysis

    CN114254097A

  • Generation and / or recommendation of tools for automating aspects of computer programming

    US20220188081A1