MAPO: Mining and Recommending API Usage Patterns

  • Hao Zhong
  • Tao Xie
  • Lu Zhang
  • Jian Pei
  • Hong Mei
Part of the Lecture Notes in Computer Science book series (LNCS, volume 5653)


To improve software productivity, when constructing new software systems, programmers often reuse existing libraries or frameworks by invoking methods provided in their APIs. Those API methods, however, are often complex and not well documented. To get familiar with how those API methods are used, programmers often exploit a source code search tool to search for code snippets that use the API methods of interest. However, the returned code snippets are often large in number, and the huge number of snippets places a barrier for programmers to locate useful ones. In order to help programmers overcome this barrier, we have developed an API usage mining framework and its supporting tool called MAPO (Mining API usage Pattern from Open source repositories) for mining API usage patterns automatically. A mined pattern describes that in a certain usage scenario, some API methods are frequently called together and their usages follow some sequential rules. MAPO further recommends the mined API usage patterns and their associated code snippets upon programmers’ requests. Our experimental results show that with these patterns MAPO helps programmers locate useful code snippets more effectively than two state-of-the-art code search tools. To investigate whether MAPO can assist programmers in programming tasks, we further conducted an empirical study. The results show that using MAPO, programmers produce code with fewer bugs when facing relatively complex API usages, comparing with using the two state-of-the-art code search tools.


Open Source Project Frequent Sequence Call Sequence Programming Task Code Snippet 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Acharya, M., Xie, T., Pei, J., Xu, J.: Mining API patterns as partial orders from source code: From usage scenarios to specifications. In: Proc. 7th ESEC/FSE, pp. 25–34 (2007)Google Scholar
  2. 2.
    Aeschlimann, M., Baumer, D., Lanneluc, J.: Java tool smithing extending the Eclipse Java Development Tools. In: Proc. 2nd EclipseCon (2005)Google Scholar
  3. 3.
    Agrawal, R., Srikant, R.: Mining sequential patterns. In: Proc. 7th ICDE, pp. 3–14 (1995)Google Scholar
  4. 4.
    Alur, R., Černỳ, P., Madhusudan, P., Nam, W.: Synthesis of interface specifications for Java classes. In: Proc. 32nd POPL, pp. 98–109 (2005)Google Scholar
  5. 5.
    Ammons, G., Bodik, R., Larus, J.R.: Mining specifications. In: Proc. 29th POPL, pp. 4–16 (2002)Google Scholar
  6. 6.
    Angluin, D.: Learning regular sets from queries and counterexamples. Information and Computation 75(2), 87–106 (1987)MathSciNetCrossRefzbMATHGoogle Scholar
  7. 7.
    Ayres, J., Flannick, J., Gehrke, J., Yiu, T.: Sequential pattern mining using a bitmap representation. In: Proc. 8th KDD, pp. 429–435 (2002)Google Scholar
  8. 8.
    Bruch, M., Schäfer, T., Mezini, M.: FrUiT: IDE support for framework understanding. In: Proc. 4th ETX, pp. 55–59 (2006)Google Scholar
  9. 9.
    Chang, R., Podgurski, A., Yang, J.: Finding what’s not there: a new approach to revealing neglected conditions in software. In: Proc. ISSTA, pp. 163–173 (2007)Google Scholar
  10. 10.
    Engler, D., Chen, D.Y., Hallem, S., Chou, A., Chelf, B.: Bugs as deviant behavior: a general approach to inferring errors in systems code. In: Proc. 8th SOSP, pp. 57–72 (2001)Google Scholar
  11. 11.
    Gabel, M., Su, Z.: Javert: fully automatic mining of general temporal properties from dynamic traces. In: Proc. 16th FSE, pp. 339–349 (2008)Google Scholar
  12. 12.
    Google Code Search Engine (2008),
  13. 13.
    Han, J., Kamber, M.: Data mining: concepts and techniques. Morgan Kaufmann Publishers Inc., San Francisco (2000)zbMATHGoogle Scholar
  14. 14.
    Henzinger, T., Jhala, R., Majumdar, R.: Permissive interfaces. In: Proc. 5th ESEC/FSE, pp. 31–40 (2005)Google Scholar
  15. 15.
    Holmes, R., Murphy, G.C.: Using structural context to recommend source code examples. In: Proc. 27th ICSE, pp. 117–125 (2005)Google Scholar
  16. 16.
    Holmes, R., Walker, R.J., Murphy, G.C.: Approximate structural context matching: An approach to recommend relevant examples. IEEE Transactions on Software Engineering 32(12), 952–970 (2006)CrossRefGoogle Scholar
  17. 17.
    Hudson, R., Shah, P.: GEF in depth. In: Proc. 2nd EclipseCon (2005)Google Scholar
  18. 18.
    Jain, A.K., Murty, M.N., Flynn, P.J.: Data clustering: a review. ACM Computing Surveys 31(3), 264–323 (1999)CrossRefGoogle Scholar
  19. 19.
    Li, Z., Zhou, Y.: PR-Miner: Automatically extracting implicit programming rules and detecting violations in large software code. In: Proc. 5th ESEC/FSE, pp. 306–315 (2005)Google Scholar
  20. 20.
    Livshits, V.B., Zimmermann, T.: Dynamine: Finding common error patterns by mining software revision histories. In: Proc. 5th ESEC/FSE, pp. 296–305 (2005)Google Scholar
  21. 21.
    Lo, D., Khoo, S.: SMArTIC: towards building an accurate, robust and scalable specification miner. In: Proc. 6th ESEC/FSE, pp. 265–275 (2006)Google Scholar
  22. 22.
    Mandelin, D., Xu, L., Bodik, R., Kimelman, D.: Jungloid mining: helping to navigate the API jungle. In: Proc. PLDI, pp. 48–61 (2005)Google Scholar
  23. 23.
    Matthew Scarpino, S.N., Holder, S., Mihalkovic, L.: SWT/JFace in Action. Manning (2005)Google Scholar
  24. 24.
    McCarey, F., Cinnéide, M.Ó., Kushmerick, N.: Recommending library methods: An evaluation of the vector space model (VSM) and latent semantic indexing (LSI). In: Proc. 9th ICSR, pp. 217–230 (2006)Google Scholar
  25. 25.
    Michail, A.: Data mining library reuse patterns using generalized association rules. In: Proc. 22nd ICSE, pp. 167–176 (2000)Google Scholar
  26. 26.
    Ng, T., Cheung, S., Chan, W., Yu, Y.: Work experience versus refactoring to design patterns: a controlled experiment. In: Proc. 6th ESEC/FSE, pp. 12–22 (2006)Google Scholar
  27. 27.
    Ramanathan, M.K., Grama, A., Jagannathan, S.: Path-sensitive inference of function precedence protocols. In: Proc. 29th ICSE, pp. 240–250 (2007)Google Scholar
  28. 28.
    Reiss, S., Renieris, M.: Encoding Program Executions. In: Proc. 23rd ICSE, pp. 221–230 (2001)Google Scholar
  29. 29.
    Saul, Z.M., Filkov, V., Devanbu, P., Bird, C.: Recommending random walks. In: Proc. 7th ESEC/FSE, pp. 15–24 (2007)Google Scholar
  30. 30.
    Scaffidi, C.: Why are APIs difficult to learn and use? Crossroads 12(4), 4–4 (2005)CrossRefGoogle Scholar
  31. 31.
    Shoham, S., Yahav, E., Fink, S., Pistoia, M.: Static specification mining using automata-based abstractions. In: Proc. ISSTA, pp. 174–184 (2007)Google Scholar
  32. 32.
    Tansalarak, N., Claypool, K.T.: XSnippet: Mining for sample code. In: Proc. 21st OOPSLA, pp. 413–430 (2006)Google Scholar
  33. 33.
    Thummalapenta, S., Xie, T.: PARSEWeb: A programmer assistant for reusing open source code on the web. In: Proc. 22nd ASE, pp. 204–213 (2007)Google Scholar
  34. 34.
    Wasylkowski, A., Zeller, A., Lindig, C.: Detecting object usage anomalies. In: Proc. 7th ESEC/FSE, pp. 35–44 (2007)Google Scholar
  35. 35.
    Weimer, W., Necula, G.: Mining temporal specifications for error detection. In: Halbwachs, N., Zuck, L.D. (eds.) TACAS 2005. LNCS, vol. 3440, pp. 461–476. Springer, Heidelberg (2005)CrossRefGoogle Scholar
  36. 36.
    Whaley, J., Martin, M., Lam, M.: Automatic extraction of object-oriented component interfaces. In: Proc. ISSTA, pp. 218–228 (2002)Google Scholar
  37. 37.
    Williams, C.C., Hollingsworth, J.K.: Recovering system specific rules from software repositories. In: Proc. 2nd MSR, pp. 1–5 (2005)Google Scholar
  38. 38.
    Xie, T., Pei, J.: MAPO: Mining API usages from open source repositories. In: Proc. 3rd MSR, pp. 54–57 (2006)Google Scholar
  39. 39.
    Yang, J., Evans, D., Bhardwaj, D., Bhat, T., Das, M.: Perracotta: mining temporal API rules from imperfect traces. In: Proc. 28th ICSE, pp. 282–291 (2006)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2009

Authors and Affiliations

  • Hao Zhong
    • 1
    • 2
  • Tao Xie
    • 3
  • Lu Zhang
    • 1
    • 2
  • Jian Pei
    • 4
  • Hong Mei
    • 1
    • 2
  1. 1.Key Laboratory of High Confidence Software TechnologiesMinistry of EducationChina
  2. 2.School of Electronics Engineering and Computer SciencePeking UniversityChina
  3. 3.Department of Computer ScienceNorth Carolina State UniversityUSA
  4. 4.School of Computer ScienceSimon Fraser UniversityCanada

Personalised recommendations