An api recommendation method fusing network structure information and content information
By constructing a mashup-API-tag heterogeneous information network and using a multi-path aggregation attention mechanism, combined with the TF-IDF method to extract feature vectors, the problem of insufficient utilization of structural and content information in existing API recommendation methods is solved, thereby improving the accuracy of API recommendation.
Patent Information
- Application Number
- CN202311559088.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-21
- Publication Date
- 2026-08-04
- Estimated Expiration
- 2043-11-21
Smart Images

Figure CN117743677B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of API recommendation, specifically relating to an API recommendation method that integrates network structure information and content information. Background Technology
[0002] An API (Application Programming Interface) is a predefined set of functions designed to provide applications and developers with the ability to access a set of routines based on specific software or hardware, without needing access to the source code or understanding the details of the internal workings. More and more companies are releasing their core functionalities or data to third parties via APIs. Mashups are a lightweight API composition technology that allows programmers to easily use APIs to develop web applications, also known as Mashup applications. In Mashup development, Web APIs typically provide the most important application functionalities. Choosing the right Web API not only improves development efficiency but also allows for customization. Currently, there are numerous publicly available Web APIs on the market. For example, ProgrammableWeb, the largest online Web API registry platform, has over 20,000 registered Web APIs and over 8,000 registered Mashup applications, covering more than 500 application types. Faced with such a large and diverse Web API library, finding the right Web API to meet one's needs is a key technical challenge in developing Mashup applications.
[0003] To improve development efficiency, researchers have proposed content-based, QoS-based, and hybrid deep neural network approaches for API service recommendation; these methods have played a significant role in advancing API service recommendation. However, content-based API service recommendation methods suffer from limitations due to their overly singular use of data, limiting their application to content information while neglecting other useful information that could improve recommendation performance (such as call history and joint calls). In other words, the mashup and API services, along with their respective attributes and the structural information generated by the invoked API services, are not fully utilized. Similarly, QoS-based API service recommendation methods also fail to leverage this structural information. Secondly, some researchers have used various deep neural networks, such as GCN and GAN, to mine structural information within service networks. These methods can effectively improve the accuracy of API service recommendations, but most directly use node embeddings generated by deep neural networks for recommendation. Research has shown that this approach loses original content information, impacting recommendation performance. Summary of the Invention
[0004] To address the above problems, this invention provides an API recommendation method that integrates network structure information and content information, comprising the following steps:
[0005] S1. Obtain the original dataset from the ProgrammableWeb dataset and preprocess the original dataset to obtain a new dataset; wherein, the original dataset includes multiple API data and multiple Mashup data, each API data includes the name, tag and function description text of an API, and each Mashup data includes the name, tag, function description text of a Mashup and API historical call records;
[0006] S2. Perform vector processing on each function description text in the new dataset to obtain multiple API content feature vectors and multiple Mashup content feature vectors;
[0007] S3. Construct a mashup-API-tag heterogeneous information network based on the API content feature vector and Mashup content feature vector in the new dataset, which includes mashup nodes, API nodes and tag nodes;
[0008] S4. Based on the mashup-API-tag heterogeneous information network, a multi-path aggregation attention mechanism is used to obtain multiple Mashup structure feature vectors;
[0009] S5. Obtain the API recommendation list for the target mashup based on the Mashup content feature vector and the Mashup structure feature vector.
[0010] Furthermore, step S1 preprocesses the original dataset to obtain a new dataset, including:
[0011] S11. Delete special characters and API data that have not been called from the original dataset to obtain the first dataset;
[0012] S12. Convert each functional description text in the first dataset to lowercase;
[0013] S13. After completing the lowercase conversion, delete blank and duplicate data in the first dataset to obtain a new dataset.
[0014] Furthermore, step S2 uses the TF-IDF method to extract Mashup content feature vectors and API content feature vectors from the new dataset, including:
[0015] S21. Perform vector processing on the functional description text of each Mashup to obtain the corresponding Mashup content feature vector, including:
[0016] S211. The functional description text d of the j=1,2,…,J1th Mashup j In the selection process, words that appear more than twice are selected as keywords; the keyword t is calculated. i ∈d j In the function description text d j TF in terms of word frequency i,j Where J1 represents the number of Mashups;
[0017] S212. Based on the functional description text of all APIs and all Mashups, calculate the keyword t. i Inverse document frequency (IDF) i ;
[0018] S213. Keywords t i TF word frequency i,j Inverse Document Frequency (IDF) i Multiplying them together, we get the keyword t. i TF-IDF value;
[0019] S214. Describe the functional text d of the j-th Mashup. j The TF-IDF values of all keywords in the text are combined to obtain the functional description text d. j The corresponding Mashup content feature vector;
[0020] S22. Perform vector processing on the functional description text of each API to obtain the corresponding API content feature vector, including:
[0021] S221. The functional description text d of the API at the j' = 1, 2, ..., J2th API j’ In the selection process, words that appear more than twice are selected as keywords; the keyword t is calculated. i ′∈d j′ In the function description text d j’ TF in terms of word frequency i′,j′ Where J2 represents the number of APIs;
[0022] S222. Based on the functional description text of all APIs and all Mashups, calculate the keyword t. i′ Inverse document frequency (IDF) i′ ;
[0023] S223. Keywords t i′ TF word frequency i′,j′ Inverse Document Frequency (IDF) i′ Multiplying them together, we get the keyword t. i′ TF-IDF value;
[0024] S224. The function description text d of the j'-th API...j’ The TF-IDF values of all keywords in the text are combined to obtain the functional description text d. j’ The corresponding API content feature vector.
[0025] Furthermore, step S3 constructs a mashup-API-tag heterogeneous information network based on the new dataset, including:
[0026] S31. Let each Mashup in the new dataset be a mashup node, each API be an API node, and each tag be a tag node; each API node uses the API content feature vector of its own API as the node vector, and each mashup node uses the Mashup content feature vector of its own Mashup as the node vector.
[0027] S32. If there is a call relationship between the Mashup to which the Mashup node belongs and the API to which the API node belongs, then there is an edge between the Mashup node and the API node; otherwise, there is no edge.
[0028] S33. There is an edge between each mashup node and the tag node corresponding to the label of its mashup; there is an edge between each API node and the tag node corresponding to the label of its API.
[0029] Furthermore, a multi-path aggregation attention mechanism is employed to obtain the Mashup structure feature vector for each Mashup node, including:
[0030] S41. Given metapath P1: M→S→M, metapath P2: M→S→T→S→M, and metapath P3: M→T→M, where M represents the mashup node type, S represents the API node type, and T represents the tag node type;
[0031] S42. Encode the metapath Pa, the metapath instance Pa(m,u) of a=1,2,3, and convert all node features along the metapath instance Pa(m,u) into a single vector, where m represents any mashup node and u represents the neighbor node of node m based on the metapath instance Pa(m,u).
[0032] S43. Take a weighted sum of the vectors of all metapath instances Pa associated with node m to obtain the vector representation of node m based on metapath Pa.
[0033] S44. Take a weighted average of the vector representations of all metapaths for each mashup node to obtain the mashup structure feature vector for each mashup node.
[0034] Furthermore, in the training process of obtaining the Mashup structure feature vector of each mashup node using a multi-path aggregation attention mechanism in the mashup-API-tag heterogeneous information network, the loss function L is used to calculate the loss, expressed as:
[0035]
[0036] l n,i =-w n,i [y n,i ·logσ(x n,i )+(1-y n,i )log(1-σ(x n,i ))]
[0037] Where J1 represents the number of Mashups, I represents the call label, and l n,i y represents the loss value calculated by the nth Mashup for the i-th call label. n,i Let x represent the actual value of the nth Mashup for the i-th calling label. n,i w represents the prediction value of the nth Mashup for the i-th call label. n,i σ represents the weight parameter, and σ() represents the prediction function.
[0038] Furthermore, step S5 obtains the API recommendation list of the target mashup based on the API content feature vector and the Mashup structure feature vector, including:
[0039] S51. Calculate the text similarity between the content feature vector of the target mashup and the content feature vectors of all mashups, and sort them in descending order according to the text similarity. Select the mashups to which the content feature vectors of the top N text similarities belong to form the first list.
[0040] S52. Traverse the Mashups in the first list, perform an expansion operation on each Mashup to obtain the network vector representation of the similar list of length M, and finally obtain the recommendation list of M×N.
[0041] Furthermore, expanding any Mashup in the first list includes: based on the mashup-API-tag heterogeneous information network, calculating the cosine similarity between the Mashup structure feature vector of the corresponding mashup node and the Mashup structure feature vectors of other mashup nodes, and sorting them in descending order according to the size of the cosine similarity, selecting the Mashups to which the Mashup structure feature vectors corresponding to the top M cosine similarities belong to form a network vector representation similarity list.
[0042] The beneficial effects of this invention are:
[0043] This invention proposes an API recommendation method that integrates network structure information and content information. The method first filters a list of recommended mashups similar to the target mashup based on content information. Then, starting from the structure, it searches for mashups with similar structures to those in the recommended mashup list to form the final recommendation list. This approach not only reduces content loss but also incorporates structural information, compensating for the shortcomings of relying solely on content information and improving recommendation accuracy. This method also incorporates heterogeneous graph and meta-path aggregation techniques to enrich the structural information. Attached Figure Description
[0044] Figure 1 This is a flowchart of an API recommendation method that integrates network structure information and content information according to the present invention. Detailed Implementation
[0045] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0046] This invention provides an API recommendation method that integrates network structure information and content information, such as... Figure 1 As shown, it includes the following steps:
[0047] S1. Obtain the original dataset from the ProgrammableWeb dataset and preprocess the original dataset to obtain a new dataset; wherein, the original dataset includes multiple API data and multiple Mashup data, each API data includes the name, label and function description text of an API, and each Mashup data includes the name, label, function description text of a Mashup and API historical call records.
[0048] Specifically, step S1 preprocesses the original dataset to obtain a new dataset, including:
[0049] S11. Delete special characters and API data that have not been called from the original dataset to obtain the first dataset;
[0050] S12. Convert each functional description text in the first dataset to lowercase;
[0051] S13. After completing the lowercase conversion, delete blank and duplicate data in the first dataset to obtain a new dataset.
[0052] S2. Perform vector processing on each function description text in the new dataset to obtain multiple API content feature vectors and multiple Mashup content feature vectors.
[0053] Specifically, step S2 uses the TF-IDF method to extract Mashup content feature vectors and content API feature vectors from the new dataset, including:
[0054] S21. Perform vector processing on the functional description text of each Mashup to obtain the corresponding Mashup content feature vector, including:
[0055] S211. The functional description text d of the j=1,2,…,J1th Mashup j In the selection process, words that appear more than twice are selected as keywords; the keyword t is calculated. i ∈d j In the function description text d j TF in terms of word frequency i,j J1 represents the number of Mashups; TF (term frequency) i,j The calculation formula is expressed as:
[0056]
[0057] Among them, TF i,j Indicates keyword t i In the function description text d j The frequency of occurrence in n i,j Indicates keyword t i In the function description text d j The number of times it appears in The text d represents the function description. j The total number of words, where K represents the number of keywords;
[0058] S212. Based on the functional description text of all APIs and all Mashups, calculate the keyword t. i Inverse document frequency (IDF) i The calculation formula is:
[0059]
[0060] Among them, IDF i Indicates keyword t i inverse document frequency, |d j ∈D:t i ∈d j | indicates that the keyword t is included. i The number of function description texts, where |D| represents the total number of function description texts;
[0061] S213. Keywords t i TF word frequency i,j Inverse Document Frequency (IDF) i Multiplying them together, we get the keyword t. i The TF-IDF value; the calculation formula is:
[0062] TF-IDF i,j =TF i,j ×IDF i
[0063] Among them, TF-IDF i,j The word t i In the function description text d j TF-IDF value;
[0064] S214. Describe the functional text d of the j-th Mashup. j The TF-IDF values of all keywords in the text are combined to obtain the functional description text d. j The corresponding Mashup content feature vector;
[0065] S22. Perform vector processing on the functional description text of each API to obtain the corresponding API content feature vector, including:
[0066] S221. The functional description text d of the API at the j' = 1, 2, ..., J2th API j’ In the selection process, words that appear more than twice are selected as keywords; the keyword t is calculated. i′ ∈d j′ In the function description text d j’ TF in terms of word frequency i′,j′ Where J2 represents the number of APIs;
[0067] S222. Based on the functional description text of all APIs and all Mashups, calculate the keyword t. i′ Inverse document frequency (IDF) i′ ;
[0068] S223. Keywords t i′ TF word frequency i′,j′ Inverse Document Frequency (IDF) i′ Multiplying them together, we get the keyword t. i′ TF-IDF value;
[0069] S224. The function description text d of the j'-th API... j’ The TF-IDF values of all keywords in the text are combined to obtain the functional description text d. j’ The corresponding API content feature vector.
[0070] S3. Construct a mashup-API-tag heterogeneous information network based on the new dataset, which includes mashup nodes, API nodes, and tag nodes.
[0071] Specifically, step S3 constructs a mashup-API-tag heterogeneous information network based on the new dataset, including:
[0072] S31. Let each Mashup in the new dataset be a mashup node, each API be an API node, and each tag be a tag node; each API node uses the API content feature vector of its own API as the node vector, and each mashup node uses the Mashup content feature vector of its own Mashup as the node vector.
[0073] S32. If there is a call relationship between the Mashup to which the Mashup node belongs and the API to which the API node belongs, then there is an edge between the Mashup node and the API node; otherwise, there is no edge.
[0074] S33. There is an edge between each mashup node and the tag node corresponding to the label of its mashup; there is an edge between each API node and the tag node corresponding to the label of its API.
[0075] S4. Based on the mashup-API-tag heterogeneous information network, a multi-path aggregation attention mechanism is used to obtain multiple Mashup structure feature vectors.
[0076] Specifically, a multi-path aggregation attention mechanism is used to obtain multiple Mashup structure feature vectors, including:
[0077] S41. Given metapath P1: M→S→M, metapath P2: M→S→T→S→M, and metapath P3: M→T→M, where M represents the mashup node type, S represents the API node type, and T represents the tag node type;
[0078] S42. Encode the metapath instance Pa(m,u) of metapath Pa, where a = 1, 2, 3, by converting all node features along the metapath instance Pa(m,u) into a single vector, represented as:
[0079]
[0080] Among them, h Pa(m,u) Let f be a vector representing a metapath instance Pa(m,u), where m represents any mashup node, u represents the neighbor node of node m based on metapath instance Pa(m,u), t represents the internal node of metapath instance Pa(m,u), and f is a vector representing a node within the metapath instance Pa(m,u).θ This represents an encoding method, h′ m Let h′ represent the vector representation of node m in the latent space. u Let h′ represent the vector representation of node u in the latent space. t c represents the vector representation of node t in the latent space. Pa(m,u) This represents the set of internal nodes of the metapath instance Pa(m,u);
[0081] S43. The weighted sum of the vectors of all metapath instances Pa associated with node m is expressed as:
[0082]
[0083]
[0084]
[0085] in, This indicates the importance of the metapath instance Pa(m,u) to the node m. The parameterization of the metapath Pa is shown, note the transpose of the vector. Let represent the weight parameters of the metapath instance Pa(m,u), and σ represent the activation function. Let m be the set of neighbors of node m based on the metapath Pa. Represents the vector representation of m nodes based on the meta-path Pa;
[0086] S44. A weighted average of the vector representations of all metapaths for each mashup node is performed to obtain the mashup structure feature vector for each mashup node. This invention transforms the recommendation task into a multi-label, multi-classification task. A loss function is set according to the target task, and the model is trained by minimizing the loss function to obtain the mashup structure feature vector for each mashup node, including:
[0087] l n,i =-w n,i [y n,i ·logσ(x n,i )+(1-y n,i )log(1-σ(x n,i Where J1 represents
[0088] Number of Mashups, l n,i y represents the loss value calculated by the nth Mashup for the i-th call label. n,i Let x represent the actual value of the nth Mashup for the i-th calling label. n,i w represents the prediction value of the nth Mashup for the i-th call label.n,i Let represent the weight parameters, and σ() represent the prediction function. Then we calculate the sum of the above losses for each category, take the average, and obtain the final loss function, as shown below:
[0089]
[0090] Where L is the final loss function, and I represents the total number of call labels (the total number of APIs with call records).
[0091] S5. Obtain the API recommendation list for the target mashup based on the Mashup content feature vector and the Mashup structure feature vector.
[0092] Specifically, step S5 obtains the API recommendation list of the target mashup based on the API content feature vector and the Mashup structure feature vector, including:
[0093] S51. Calculate the text similarity between the content feature vector of the target mashup and the content feature vectors of all mashups, and sort them in descending order according to the text similarity. Select the mashups to which the content feature vectors of the top N text similarities belong to form the first list.
[0094] The text similarity between the content feature vector of the target mashup and the content feature vectors of all mashups is calculated and expressed as follows:
[0095]
[0096] in, M represents the content feature vector of the target mashup. o With the j-th Mashup content feature vector M j The text similarity is given by , where · represents the dot product and ‖‖ represents the operation of calculating the vector length.
[0097] S52. Traverse the Mashups in the first list, and expand each Mashup to obtain a network vector representation similarity list of length M, ultimately obtaining an M×N recommendation list. Specifically, expanding any Mashup in the first list includes: based on the mashup-API-tag heterogeneous information network, calculating the cosine similarity between the Mashup structure feature vector of the corresponding Mashup node and the Mashup structure feature vectors of other Mashup nodes, and sorting them in descending order according to the cosine similarity, selecting the Mashups to which the Mashup structure feature vectors corresponding to the top M cosine similarities belong to form a network vector representation similarity list.
[0098] In this invention, unless otherwise explicitly specified and limited, the terms "installation," "setting," "connection," "fixing," "rotation," etc., should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral part; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; they can refer to the internal connection of two components or the interaction between two components. Unless otherwise explicitly limited, those skilled in the art can understand the specific meaning of the above terms in this invention according to the specific circumstances.
[0099] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.
Claims
1. An API recommendation method that integrates network structure information and content information, characterized in that, Includes the following steps: S1. Obtain the original dataset from the ProgrammableWeb dataset and preprocess the original dataset to obtain a new dataset; wherein, the original dataset includes multiple API data and multiple Mashup data, each API data includes the name, tag and function description text of an API, and each Mashup data includes the name, tag, function description text of a Mashup and API historical call records; S2. Perform vector processing on each function description text in the new dataset to obtain multiple API content feature vectors and multiple Mashup content feature vectors; Step S2 uses the TF-IDF method to extract Mashup content feature vectors and content API content feature vectors from the new dataset, including: S21. Perform vector processing on the functional description text of each Mashup to obtain the corresponding Mashup content feature vector, including: S211. The functional description text d of the j=1,2,…,J1th Mashup j In the process, words that appear more than twice are selected as keywords; keyword calculation is performed. In the function description text d j word frequency in Where J1 represents the number of Mashups; S212. Calculate keywords based on the feature description text of all APIs and all Mashups. Inverse document frequency ; S213. Keywords word frequency and inverse document frequency Multiply to obtain keywords TF-IDF value; S214. Describe the functional text d of the j-th Mashup. j The TF-IDF values of all keywords in the text are combined to obtain the functional description text d. j The corresponding Mashup content feature vector; S22. Perform vector processing on the functional description text of each API to obtain the corresponding API content feature vector, including: S221. The functional description text d of the API at the j'=1,2,…,J2th API j’ In the process, words that appear more than twice are selected as keywords; keyword calculation is performed. In the function description text d j’ word frequency in Where J2 represents the number of APIs; S222. Calculate keywords based on the feature description text of all APIs and all Mashups. Inverse document frequency ; S223. Keywords word frequency and inverse document frequency Multiply to obtain keywords TF-IDF value; S224. The function description text d of the j'-th API... j’ The TF-IDF values of all keywords in the text are combined to obtain the functional description text d. j’ The corresponding API content feature vector; S3. Construct a mashup-API-tag heterogeneous information network based on the API content feature vector and Mashup content feature vector in the new dataset, which includes mashup nodes, API nodes and tag nodes; S4. Based on the mashup-API-tag heterogeneous information network, a multi-path aggregation attention mechanism is used to obtain the Mashup structure feature vector of each mashup node; A multi-path aggregation attention mechanism is used to obtain the Mashup structure feature vector for each Mashup node, including: S41. Given metapath P1: M→S→M, metapath P2: M→S→T→S→M, and metapath P3: M→T→M, where M represents the mashup node type, S represents the API node type, and T represents the tag node type; S42. Encode the metapath Pa, the metapath instance Pa(m,u) of a=1,2,3, and convert all node features along the metapath instance Pa(m,u) into a single vector, where m represents any mashup node and u represents the neighbor node of node m based on the metapath instance Pa(m,u). S43. Take a weighted sum of the vectors of all metapath instances Pa associated with node m to obtain the vector representation of node m based on metapath Pa. S44. Take a weighted average of the vector representations of all metapaths for each mashup node to obtain the mashup structure feature vector for each mashup node. S5. Obtain the API recommendation list for the target mashup based on the Mashup content feature vector and the Mashup structure feature vector.
2. The API recommendation method that integrates network structure information and content information according to claim 1, characterized in that, Step S1 preprocesses the original dataset to obtain a new dataset, including: S11. Delete special characters and API data that have not been called from the original dataset to obtain the first dataset; S12. Convert each functional description text in the first dataset to lowercase; S13. After completing the lowercase conversion, delete blank and duplicate data in the first dataset to obtain a new dataset.
3. The API recommendation method that integrates network structure information and content information according to claim 1, characterized in that, Step S3 involves constructing a mashup-API-tag heterogeneous information network based on the new dataset, including: S31. Let each Mashup in the new dataset be a mashup node, each API be an API node, and each tag be a tag node; each API node uses the API content feature vector of its own API as the node vector, and each mashup node uses the Mashup content feature vector of its own Mashup as the node vector. S32. If there is a call relationship between the Mashup to which the Mashup node belongs and the API to which the API node belongs, then there is an edge between the Mashup node and the API node; otherwise, there is no edge. S33. There is an edge between each mashup node and the tag node corresponding to the label of its mashup; there is an edge between each API node and the tag node corresponding to the label of its API.
4. The API recommendation method that integrates network structure information and content information according to claim 1, characterized in that, In the training process of obtaining the Mashup structure feature vector of each mashup node using a multi-path aggregation attention mechanism in the mashup-API-tag heterogeneous information network, the loss function L is used to calculate the loss, expressed as: , , Where J1 represents the number of Mashups, and I represents the call label. This represents the loss value calculated by the nth Mashup for the i-th call label. This represents the actual value of the nth Mashup for the i-th calling label. This represents the prediction value of the nth Mashup for the i-th call label. Represents the weight parameters. This represents the prediction function.
5. The API recommendation method that integrates network structure information and content information according to claim 1, characterized in that, Step S5 obtains the API recommendation list for the target mashup based on the API content feature vector and the Mashup structure feature vector, including: S51. Calculate the text similarity between the content feature vector of the target mashup and the content feature vectors of all mashups, and sort them in descending order according to the text similarity. Select the mashups to which the content feature vectors of the top N text similarities belong to form the first list. S52. Traverse the Mashups in the first list, perform an expansion operation on each Mashup to obtain the network vector representation of the similar list of length M, and finally obtain the recommendation list of M×N.
6. The API recommendation method that integrates network structure information and content information according to claim 1, characterized in that, Expanding any Mashup in the first list includes: based on the mashup-API-tag heterogeneous information network, calculating the cosine similarity between the Mashup structure feature vector of the corresponding Mashup node and the Mashup structure feature vectors of other Mashup nodes, and sorting them in descending order according to the size of the cosine similarity, selecting the Mashup to which the Mashup structure feature vectors corresponding to the top M cosine similarities belong to form a network vector representation similarity list.