Abstract
An activity constantly engaged by most programmers in coding is to search for appropriate application programming interfaces (APIs). Contextual information is widely recognized to play a crucial role in effective API recommendation, but it is largely overlooked in practice. In this paper, we propose context-aware API recommendation using tensor factorization (CARTF), a novel API recommendation approach in considering programmers’ working context. To this end, we use tensors to explicitly represent the query-API-context triadic relation. When a new query is made, CARTF harnesses word embeddings to retrieve similar user queries, based on which a third-order tensor is constructed. CARTF then applies non-negative tensor factorization to complete missing values in the tensor and the Smith-Waterman algorithm to identify the most matched context. Finally, the ranking of the candidate APIs can be derived based on which API sequences are recommended. Our evaluation confirms the effectiveness of CARTF for class-level and method-level API recommendations, outperforming state-of-the-art baseline approaches against a number of performance metrics, including SuccessRate, Precision, and Recall.
Similar content being viewed by others
References
Raghothaman M, Wei Y, Hamadi Y. SWIM: synthesizing what I mean: code search and idiomatic snippet synthesis. In: Proceedings of the 38th International Conference on Software Engineering, 2016. 357–367
Ye X, Shen H, Ma X, et al. From word embeddings to document similarities for improved information retrieval in software engineering. In: Proceedings of the 38th International Conference on Software Engineering, 2016. 404–415
Robillard M P, Walker R J, Zimmermann T. Recommendation systems for software engineering. IEEE Softw, 2010, 27: 80–86
Lv F, Zhang H, Lou J, et al. CodeHow: effective code search based on API understanding and extended Boolean model (E). In: Proceedings of the 30th IEEE/ACM International Conference on Automated Software Engineering (ASE), 2015. 260–270
Thung F, Wang S, Lo D, et al. Automatic recommendation of API methods from feature requests. In: Proceedings of the 28th IEEE/ACM International Conference on Automated Software Engineering (ASE), 2013. 290–300
Chan W, Cheng H, Lo D. Searching connected API subgraph via text phrases. In: Proceedings of the ACM SIGSOFT 20th International Symposium on the Foundations of Software Engineering, 2012. 1–11
Thung F, Lo D, Lawall J L. Automated library recommendation. In: Proceedings of the 20th Working Conference on Reverse Engineering (WCRE), 2013. 182–191
Mcmillan C, Grechanik M, Poshyvanyk D, et al. Portfolio: finding relevant functions and their usage. In: Proceedings of the 33rd International Conference on Software Engineering (ICSE), 2011. 111–120
Rahman M M, Roy C K, Lo D. RACK: automatic API recommendation using crowdsourced knowledge. 2018. ArXiv:1807.02953
Cai L, Wang H, Huang Q, et al. BIKER: a tool for bi-information source based API method recommendation. In: Proceedings of the ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering, 2019. 1075–1079
Holmes R, Murphy G C. Using structural context to recommend source code examples. In: Proceedings of the 27th International Conference on Software Engineering, 2005. 117–125
Rahman M M, Roy C K. On the use of context in recommending exception handling code examples. In: Proceedings of 2014 IEEE 14th International Working Conference on Source Code Analysis and Manipulation, 2014. 285–294
Ai L, Huang Z, Li W, et al. Sensory: leveraging code statement sequence information for code snippets recommendation. In: Proceedings of IEEE 43rd Annual Computer Software and Applications Conference (COMPSAC), 2019. 27–36
Nguyen A T, Nguyen T N. Graph-based statistical language model for code. In: Proceedings of IEEE/ACM 37th IEEE International Conference on Software Engineering (ICSE), 2015
Nguyen P T, Rocco J D, Ruscio D D, et al. FOCUS: a recommender system for mining API function calls and usage patterns. In: Proceedings of IEEE/ACM 41st International Conference on Software Engineering (ICSE), 2019. 1050–1060
Huang Q, Xia X, Xing Z, et al. API method recommendation without worrying about the task-API knowledge gap. In: Proceedings of the 33rd IEEE/ACM International Conference on Automated Software Engineering (ASE), 2018. 293–304
Frolov E, Oseledets I. Tensor methods and recommender systems. WIREs Data Min Knowl Discov, 2017, 7: e1201
Ligowski L, Rudnicki W. An efficient implementation of smith waterman algorithm on GPU using CUDA, for massively parallel scanning of sequence databases. In: Proceedings of IEEE International Symposium on Parallel & Distributed Processing, 2009. 1–8
Mihalcea R, Corley C, Strapparava C. Corpus-based and knowledge-based measures of text semantic similarity. In: Proceedings of National Conference on Artificial Intelligence & the 18th Innovative Applications of Artificial Intelligence Conference, 2006. 775–780
Mikolov T, Sutskever I, Chen K, et al. Distributed representations of words and phrases and their compositionality. In: Proceedings of the 26th International Conference on Neural Information Processing Systems, 2013. 3111–3119
Baroni M, Dinu G, Kruszewski G. Don’t count, predict! A systematic comparison of context-counting vs. context-predicting semantic vectors. In: Proceedings of the 52nd Annual Meeting of the Association for Computational Linguistics, 2014. 238–247
Collobert R, Weston J, Bottou L, et al. Natural language processing (almost) from scratch. J Mach Learn Res, 2011, 12: 2493–2537
Mikolov T, Yih W, Zweig G. Linguistic regularities in continuous space word representations. In: Proceedings of Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, 2013. 746–751
Mikolov T, Chen K, Corrado G, et al. Efficient estimation of word representations in vector space. In: Proceedings of the 1st International Conference on Learning Representations, 2013
Bird S. NLTK: the natural language toolkit. In: Proceedings of the 21st International Conference on Computational Linguistics and the 44th Annual Meeting of the Association for Computational Linguistics, 2006
An N L, Nguyen A T, Nguyen H A, et al. Combining deep learning with information retrieval to localize buggy files for bug reports (n). In: Proceedings of IEEE/ACM International Conference on Automated Software Engineering, 2015
Noia T D, Mirizzi R, Ostuni V C, et al. Linked open data to support content-based recommender systems. In: Proceedings of International Conference on Semantic Systems, 2012
Avazpour I, Pitakrat T, Grunske L, et al. Dimensions and metrics for evaluating recommendation systems. In: Proceedings of Recommendation Systems in Software Engineering, 2014. 245–273
Zhou J, Zhang H, Lo D. Where should the bugs be fixed? More accurate information retrieval-based bug localization based on bug reports. In: Proceedings of International Conference on Software Engineering, 2012. 14–24
Feldt R, Magazinius A. Validity threats in empirical software engineering research — an initial survey. In: Proceedings of International Conference on Software Engineering and Knowledge Engineering, 2010. 374–379
Haiduc S, Bavota G, Marcus A, et al. Automatic query reformulations for text retrieval in software engineering. In: Proceedings of the 35th International Conference on Software Engineering, 2013. 842–851
McMillan C, Grechanik M, Poshyvanyk D, et al. Exemplar: a source code search engine for finding highly relevant applications. IEEE Trans Software Eng, 2012, 38: 1069–1087
Bajracharya S K, Ossher J, Lopes C V. Leveraging usage similarity for effective retrieval of examples in code repositories. In: Proceedings of the 18th ACM SIGSOFT International Symposium on Foundations of Software Engineering, 2010. 157–166
Chatterjee S, Juvekar S, Sen K. SNIFF: a search engine for Java using free-form queries. In: Fundamental Approaches to Software Engineering. Berlin: Springer, 2009. 385–400
Dasgupta T, Grechanik M, Moritz E, et al. Enhancing software traceability by automatically expanding corpora with relevant documentation. In: Proceedings of IEEE International Conference on Software Maintenance, 2013. 320–329
Stylos J, Myers B A. Mica: a web-search tool for finding API components and examples. In: Proceedings of 2006 IEEE Symposium on Visual Languages and Human-Centric Computing (VL/HCC 2006), 2006. 195–202
Ye X, Bunescu R, Liu C. Learning to rank relevant files for bug reports using domain knowledge. In: Proceedings of ACM Sigsoft International Symposium on Foundations of Software Engineering, 2014. 689–699
Ponzanelli L, Scalabrino S, Bavota G, et al. Supporting software developers with a holistic recommender system. In: Proceedings of IEEE/ACM International Conference on Software Engineering, 2017. 94–105
Cordeiro J, Antunes B, Gomes P. Context-based recommendation to support problem solving in software development. In: Proceedings of the 3rd International Workshop on Recommendation Systems for Software Engineering, 2012. 85–89
Ponzanelli L, Bacchelli A, Lanza M. Leveraging crowd knowledge for software comprehension and development. In: Proceedings of European Conference on Software Maintenance & Reengineering, 2013. 57–66
Ponzanelli L, Bavota G, Penta M D, et al. Mining StackOverflow to turn the IDE into a self-confident programming prompter. In: Proceedings of Working Conference on Mining Software Repositories, 2014. 102–111
Rahman M M, Yeasmin S, Roy C K. Towards a context-aware IDE-based meta search engine for recommendation about programming errors and exceptions. In: Proceedings of Software Maintenance, Reengineering & Reverse Engineering, 2014. 194–203
Rigby P C, Robillard M P. Discovering essential code elements in informal documentation. In: Proceedings of International Conference on Software Engineering, 2013. 832–841
Takuya W, Masuhara H. A spontaneous code recommendation tool based on associative search. In: Proceedings of the 3rd International Workshop on Search-Driven Development: Users, Infrastructure, Tools, and Evaluation, 2011. 17–20
Treude C, Robillard M P. Augmenting API documentation with insights from stack overflow. In: Proceedings of IEEE/ACM International Conference on Software Engineering, 2017. 392–403
Zhang J, Jiang H, Ren Z, et al. Recommending APIs for API related questions in stack overflow. IEEE Access, 2018, 6: 6205–6219
Zhou Y, Yang X, Chen T, et al. Boosting API recommendation with implicit feedback. IIEEE Trans Software Eng, 2022, 48: 2157–2172
Zhou Y, Jin H, Yang X, et al. Braid: an API recommender supporting implicit user feedback. In: Proceedings of the 29th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering, 2021. 1510–1514
Acharya M, Tao X, Jian P, et al. Mining API patterns as partial orders from source code: from usage scenarios to specifications. In: Proceedings of Joint Meeting of the European Software Engineering Conference & the ACM Sigsoft Symposium on the Foundations of Software Engineering, 2007. 25–34
Zhong H, Xie T, Zhang L, et al. MAPO: mining and recommending API usage patterns. In: ECOOP 2009—Object-Oriented Programming. Berlin: Springer, 2009. 5653: 318–343
Wang J, Dang Y, Zhang H, et al. Mining succinct and high-coverage API usage patterns from source code. In: Proceedings of Mining Software Repositories, 2013. 319–328
Wang J Y, Han J W. Bide: efficient mining of frequent closed sequences. In: Proceedings of International Conference on Data Engineering, 2004. 79–90
Holmes R, Walker R J, Murphy G C. Approximate structural context matching: an approach to recommend relevant examples. IEEE Trans Software Eng, 2006, 32: 952–970
Fowkes J, Sutton C. Parameter-free probabilistic API mining across GitHub. In: Proceedings of the 24th ACM SIGSOFT International Symposium on Foundations of Software Engineering, 2016. 254–265
Niu H, Keivanloo I, Zou Y. API usage pattern recommendation for software development. J Syst Software, 2017, 129: 127–139
Saied M A, Abdeen H, Benomar O, et al. Could we infer unordered API usage patterns only using the library source code? In: Proceedings of IEEE International Conference on Program Comprehension, 2015. 71–81
Saied M A, Benomar O, Abdeen H, et al. Mining multi-level API usage patterns. In: Proceedings of IEEE International Conference on Software Analysis, 2015. 23–32
Gu X, Zhang H, Zhang D, et al. Deep API learning. In: Proceedings of the 24th ACM SIGSOFT International Symposium on Foundations of Software Engineering, 2016. 631–642
Ling C, Zou Y, Xie B. Graph neural network based collaborative filtering for API usage recommendation. In: Proceedings of 2021 IEEE International Conference on Software Analysis, Evolution and Reengineering (SANER), 2021. 36–47
Liu X, Huang L, Ng V. Effective API recommendation without historical software repositories. In: Proceedings of the 33rd IEEE/ACM International Conference on Automated Software Engineering (ASE), 2018. 282–292
Acknowledgements
This work was partially supported by National Natural Science Foundation of China (Grant Nos. 61972197, 61802179), Collaborative Innovation Center of Novel Software Technology and Industrialization, and Qing Lan Project. Taolue CHEN is partially supported by Birkbeck BEI School Project (EFFECT), National Natural Science Foundation of China (Grant No. 61872340), Guangdong Science and Technology Department (Grant No. 2018B010107004), and Natural Science Foundation of Guangdong Province, China (Grant No. 2019A1515011689).
Author information
Authors and Affiliations
Corresponding author
Additional information
Supporting information
Tables S1–S4. The supporting information is available online at info.scichina.com and link.springer.com. The supporting materials are published as submitted, without typesetting or editing. The responsibility for scientific accuracy and content remains entirely with the authors.
Supplementary File
Rights and permissions
About this article
Cite this article
Zhou, Y., Chen, C., Wang, Y. et al. Context-aware API recommendation using tensor factorization. Sci. China Inf. Sci. 66, 122101 (2023). https://doi.org/10.1007/s11432-021-3529-9
Received:
Revised:
Accepted:
Published:
DOI: https://doi.org/10.1007/s11432-021-3529-9