Abstract:
When facing API usage problems during the development process, software developers usually hope to get effective suggestions on API usage patterns to help them learn and use. Traditional API recommendation methods mine the usage knowledge of APIs in the codebase, and then recommend context-sensitive APIs to developers. However, several aspects affect the performance of the recommendation, such as the insufficient representation of contextual information, the appearance of redundant and homogeneous contents in the recommendation list. Focus on those problems, we propose an approach named as context-aware based API recommendation with diversity (CAPIRD), in which we build an API hierarchy call graph (AHCG) model of projects, methods, and APIs to represent API contextual relationships better. According to AHCG model, we can fully use API structural and semantic information to reduce redundant and homogenous contents. In addition, the measurement of relevance and correlation parts are introduced into the approach, which are used to maximize the relevant results, while balancing the correlation of selected APIs and candidate APIs, so as to dig out a reasonable list of APIs. Finally, we reorder the above relevant and correlated results using the optimal weight combination to increase the diversity. The optimal weight is learned on the standard patterns datasets combined with the maximal marginal relevance algorithm. Experiments are implemented on 3 datasets, which are consisted of 2210 projects, to verify the recommendation performance of CAPIRD. The experimental results show that CAPIRD performs better in context-based scenarios of API usage recommendation. In detail, compared with the baseline approaches, the average improvement of MAP (mean average precision) is about 9%. In the Top-1 success rate, the average improvement is about 13%.