SAR: Learning Cross-Language API Mappings with Little Knowledge

  • 2019-06-10 08:13:01
  • Nghi D. Q. Bui, Yijun Yu, Lingxiao Jiang
  • 2

Abstract

To save manual effort, developers often translate programs from oneprogramming language to another, instead of implementing it from scratch.Translating application program interfaces (APIs) used in one language tofunctionally equivalent ones available in another language is an importantaspect of program translation. Existing approaches facilitate the translationby automatically identifying the API mappings across programming languages.However, all these approaches still require large amount of manual effort inpreparing parallel program corpora, ranging from pairs of APIs, to manuallyidentified code in different languages that are considered as functionallyequivalent. To minimize the manual effort in identifying parallel programcorpora and API mappings, this paper aims at an automated approach to map APIsacross languages with much less knowledge a priori needed than other existingapproaches. The approach is based on an realization of the notion of domainadaption combined with code embedding, which can better align two vectorspaces: taking as input large sets of programs, our approach first generatesnumeric vector representations of the programs, especially the APIs used ineach language, and it adapts generative adversarial networks (GAN) to align thevectors from the spaces of two languages. For a better alignment, we initializethe GAN with parameters derived from optional API mapping seeds that can beidentified accurately with a simple automatic signature-based matchingheuristic. Then the cross-language API mappings can be identified vianearest-neighbors queries in the aligned vector spaces.

 

Quick Read (beta)

SAR: Learning Cross-Language API Mappings with Little Knowledge

Nghi D. Q. Bui School of Information SystemsSingapore Management University [email protected] Yijun Yu Department of Computing & CommunicationsThe Open University [email protected]  and  Lingxiao Jiang School of Information SystemsSingapore Management University [email protected]
Abstract.

To save effort, developers often translate programs from one programming language to another, instead of implementing it from scratch. Translating application program interfaces (APIs) used in one language to functionally equivalent ones available in another language is an important aspect of program translation. Existing approaches facilitate the translation by automatically identifying the API mappings across programming languages. However, these approaches still require large amount of parallel corpora, ranging from pairs of APIs or code fragments that are functionally equivalent, to similar code comments.

To minimize the need of parallel corpora, this paper aims at an automated approach that can map APIs across languages with much less a priori knowledge than other approaches. The approach is based on an realization of the notion of domain adaption, combined with code embedding, to better align two vector spaces. Taking as input large sets of programs, our approach first generates numeric vector representations of the programs (including the APIs used in each language), and it adapts generative adversarial networks (GAN) to align the vectors in different spaces of two languages. For a better alignment, we initialize the GAN with parameters derived from API mapping seeds that can be identified accurately with a simple automatic signature-based matching heuristic. Then the cross-language API mappings can be identified via nearest-neighbors queries in the aligned vector spaces. We have implemented the approach (SAR, named after three main technical components in the approach) in a prototype for mapping APIs across Java and C# programs. Our evaluation on about 2 million Java files and 1 million C# files shows that the approach can achieve 54% and 82% mapping accuracy in its top-1 and top-10 API mapping results with only 257 automatically identified seeds, more accurate than other approaches using the same or much more mapping seeds.

journalyear: 2018copyright: acmlicensedconference: 40th International Conference on Software Engineering: New Ideas and Emerging Results Track; May 27-June 3 2018; Gothenburg, Swedenbooktitle: ICSE-NIER’18: 40th International Conference on Software Engineering: New Ideas and Emerging Results Track, May 27-June 3 2018, Gothenburg, Swedenprice: 15.00doi: 10.1145/3183399.3183427isbn: 978-1-4503-5662-6/18/05