RACK: Automatic API Recommendation using Crowdsourced Knowledge

Abstract: Traditional code search engines often do not perform well with natural language queries since they mostly apply keyword matching. These engines thus need carefully designed queries containing information about programming APIs for code search. Unfortunately, existing studies suggest that preparing an effective code search query is both challenging and time consuming for the developers. In this paper, we propose a novel API recommendation technique–RACK that recommends a list of relevant APIs for a natural language query for code search by exploiting keyword-API associations from the crowdsourced knowledge of Stack Overflow. We first motivate our technique using an exploratory study with 11 core Java packages and 344K Java posts from Stack Overflow. Experiments using 150 code search queries randomly chosen from three Java tutorial sites show that our technique recommends correct API classes within the top 10 results for about 79% of the queries which is highly promising. Comparison with two variants of the state-of-the-art technique also shows that RACK outperforms both of them not only in Top-K accuracy but also in mean average precision and mean recall by a large margin. Once the NL query is reformulated into relevant API classes, we use them for code search using GitHub code search API. Our tool then returns a list of relevant code examples for the given NL query.


Replication Package

Plug-in overview
  • Type: Eclipse IDE Plug-in
  • System Requirement: Kepler 4.3.2+ (Tested)
  • Prototype: RACK update site
RACK Installation
  1. Copy the update site URL
  2. Use with Help>Add New Software>Work with option of Eclipse IDE for RACK installation
  3. Installation will require the IDE to restart
  4. Once installed successfully, you will see RACK icon in the main menu
  5. Please check Use remote option for code search if you do not have RACK server installed

RACK User Guide

Note: RACK server might be down sometimes. If you want to try the plug-in, please contact Masud Rahman. Thanks for your interest.

We collected code search queries from three popular programming tutorial sites -- KodeJava, Java2s and JavaDB. Each of the uploaded files below contains queries in the odd line and relevant API names in the next (i.e., even) line.

  • NL-Queries & Ground Truth
    • NL-queries and their oracle (i.e., ground-truth API classes)
  • Suggested Queries by RACK
    • Suggested API classes by RACK (for noun+verb NL keywords)
    • Suggested API classes by RACK (for noun keywords)
    • Suggested API classes by RACK (for verb keywords)
    • Suggested API classes by RACK (KAC)
    • Suggested API classes by RACK (KKC)

Please contact Masud Rahman for information related to the experiments.

Tool Installation:
  1. Download rack-exec.jar, models, stopword and database from Google Drive.
  2. Keep all four items in the same directory.
  3. Download and keep sample files--sample-queries and sample-output in the same directory (Optional).

NL-Query Preparation:
  1. Add each code search query in a single line. If you have N queries, the query file should have N lines
  2. Avoid special symbols in the query texts.
  3. Keep the query file in the tool's installation directory

Running RACK

Execute the following command with your custom parameters:

java -jar rack-exec.jar -queryfile ./sample-queries.txt -outputfile ./sample-output.txt -K 5
  • -queryfile : the file containing the NL-queries, each query on an individual line
  • -outputfile : the file containing the suggested API names by RACK
  • -K : Number of top relevant API names to be returned
Once the tool is done, you can compare the suggested API names with the ground truth provided above.

Snapshot of RACK's Run:

RACK Library Installation:
  1. Download rack-exec.jar, models, stopword and database from Google Drive.
  2. Add rack-exec.jar to the CLASSPATH of your Java project
  3. Add models, stopword and database to the home directory of your Java project
  4. database contains NL term to API mappings extracted from Stack Overflow questions and answers.

Accessing RACK Library (Sample Code):
	Library name:  ca.usask.cs.srlab.rack.server
String query = "How to send email in Java?"; int TOPK=5; CodeTokenProvider ctProvider = new CodeTokenProvider(query,TOPK); System.out.println(ctProvider.recommendRelevantAPIs());

Related Publication(s)

author={Rahman, M. M. and Roy, C. K. and Lo, D.},
booktitle={Proc. SANER}, title={{RACK}: {A}utomatic {API} {R}ecommendation using {C}rowdsourced {K}nowledge},
pages={349--359} }

author={Rahman, M. M. and Roy, C. K. and Lo, D.},
booktitle={Proc. ICSE}, title={RACK: Code Search in the IDE using Crowdsourced Knowledge},
pages={51--54} }

← Check out other tools by Masud Rahman

© Masud Rahman, Computer Science, University of Saskatchewan, Canada.