Task-Oriented API Usage Examples Prompting Powered By Programming Task Knowledge Graph

Zhenchang Xing, Jiamou Sun, Xin Peng, Xiwei Xu, Zhu Liming · DOI

TL;DR

This paper tackles the challenge of developers struggling to find and use relevant API usage examples from tutorials, often due to mismatched task descriptions and overwhelming code. They introduce a novel approach that enhances a programming task knowledge graph with more granular actions and uses code matching for task search, integrated into an IDE to proactively suggest relevant examples.

What Problem Does This Paper Address?

Developers often turn to official API documentation and tutorials for guidance on how to use APIs. However, a significant problem exists: these high-quality tutorials are underutilized. The authors identify two primary culprits:

  1. Task Mismatch: Tutorials are structured around pre-defined tasks by API developers, which rarely perfectly align with the diverse and specific needs of developers in real-world scenarios. For instance, a tutorial might cover "creating a dialog," but a developer might need to "create a dialog without a title," a specific sub-task not explicitly documented.
  2. Code Information Overload: Even when a relevant tutorial is found, the accompanying code examples can be lengthy and dense, making it difficult for developers to quickly pinpoint the exact code snippet that solves their particular problem.

Existing search methods, like general document search or activity-centric search over knowledge graphs, fall short. Document search might find the right tutorial page but not the specific code. Activity-centric search, while better, suffers from limited action coverage and coarse-grained recommendations.

Methods

The paper proposes a multi-faceted solution to address these barriers:

  • Enhanced Knowledge Graph: They extend a previously developed programming task knowledge graph. Key enhancements include:
  • Extracting actions from code comments: This adds finer-grained actions that might not be explicitly stated in tutorial text.
  • Expanding activity sentence detection: Incorporating non-imperative sentences and more diverse training data to capture a wider range of programming actions.
  • Replacing BiLSTM with BERT: Utilizing a more powerful transformer-based model for activity sentence classification, improving its ability to understand context and co-references.
  • Introducing "duplicate action" relationships: Linking similar actions found in both tutorial text and code comments.
  • Code Matching based Task Search: Instead of relying solely on natural language queries, this approach matches the code a developer is currently writing (the "code under development") with code examples in the knowledge graph. The rationale is that even if tasks are described differently, the underlying APIs used are often the same or similar. This method helps overcome task mismatch by focusing on code similarity.
  • In-IDE Prompting (CueMeIn Tool): The enhanced knowledge graph and code matching search are integrated into an IntelliJ IDE plugin called "CueMeIn." This tool adopts an "observe-push" paradigm: it passively observes the developer's code and proactively suggests relevant API usage examples from tutorials when the developer pauses. It highlights key actions and APIs within the suggested tutorial excerpts and code snippets to combat information overload.

Datasets

The study primarily uses:

  • Android Developer Guides: This forms the basis for constructing the programming task knowledge graph.
  • Stack Overflow Questions: 20 top-viewed Android-tagged questions were selected for a formative study to identify problems and evaluate the proposed solution. These questions were chosen based on their view counts and whether their accepted answers referenced Android Developer Guides.
  • Custom Datasets for Activity Sentence Classification: The paper mentions enriching existing datasets with new forms of activity sentences and sentences from code comments.

Key Insights and Ideas

  • Code Comments are Goldmines for Granular Actions: Extracting actions from code comments significantly boosts the coverage of fine-grained programming tasks, which are often missed in tutorial text alone.
  • Code Similarity is a Powerful Task Matcher: Matching code directly, rather than just natural language descriptions, is a more robust way to bridge the gap between a developer's specific need and available tutorial examples.
  • Proactive IDE Assistance is Key: Developers don't always know what to search for. An IDE that intelligently suggests relevant examples based on their current coding context can be far more effective than manual searching.
  • Highlighting is Crucial for Reducing Overload: Simply presenting a code example isn't enough. Visually highlighting relevant parts within the tutorial text and code snippets is essential for helping developers quickly grasp the solution.

Key Results

  • Knowledge Graph Quality: The information extraction methods for constructing the knowledge graph achieved high accuracy (e.g., 79% or above for various components). The enhanced knowledge graph contains 23,918 programming actions and 4,050 code-example snippets.
  • Task Search Effectiveness: The code matching based task search successfully recommended effective code solutions for 15 out of 20 Stack Overflow questions. This is a significant improvement over activity-centric search, which was effective for only 6 questions.
  • User Study: A small-scale user study with 12 master students showed that the CueMeIn tool helped participants complete programming tasks faster (average time reduction of 14%-60%) and more successfully compared to using search engines.
  • BERT vs. BiLSTM: The BERT-based classifier outperformed the BiLSTM-based classifier for activity sentence classification, achieving 0.97 precision, 0.99 recall, and 0.98 F1 score on both original and enriched data.

Limitations and Future Work

  • Limited Scope of Code Matching: The current code matching primarily focuses on exact API matches. It struggles with cases where similar functionality is achieved through different API calls (e.g., BitmapFactory.decodeStream() vs. BitmapFactory.decodeFile()).
  • Incomplete API Knowledge: For tasks requiring deep understanding of API definitions or complex configurations (like Task 4 and Task 6 in the user study), the tool's recommendations were less effective because the knowledge graph didn't cover all necessary background information.
  • Future Work: The authors plan to:
  • Apply their approach to a wider range of programming tutorials.
  • Release their knowledge graph and tool for public evaluation.
  • Integrate other types of API knowledge into the knowledge graph to enhance recommendations for more complex scenarios.

Summary updated

BibTeX
@inproceedings{xing2021task,
  author = {Zhenchang Xing and Jiamou Sun and Xin Peng and Xiwei Xu and Zhu Liming},
  title = {{Task-Oriented API Usage Examples Prompting Powered By Programming Task Knowledge Graph}},
  booktitle = {Icsme},
  year = {2021},
  doi = {10.1109/icsme52107.2021.00046},
}
Figure