Introduction
When developers encounter issues with specific library methods, Stack Overflow (SO) is often their first destination. However, retrieving the most relevant threads for a specific API method is a non-trivial task. API method names are frequently ambiguous; for instance, generic method names like is() or mock() appear across hundreds of different libraries.
Existing retrieval tools often rely on "type-scoping," which attempts to disambiguate methods by searching for parent class or package names within the discussion. This approach frequently fails when developers discuss methods without explicit context or when common natural language words are incorrectly flagged as API names (e.g., the word "is" being mapped to com.google.common.base.CharMatcher.is). To address these challenges, the authors propose FACOS (Finding API Relevant Contents), a framework that integrates syntactic keyword matching with deep semantic analysis.
The FACOS Framework
FACOS operates through a two-step process designed to collect and then rank potential resources. First, it identifies candidate API methods and potential threads. Second, it applies a dual-layered analysis to determine the relevance of a thread to a specific API.
Syntactic and Semantic Integration
The core of FACOS lies in its ability to combine two distinct scoring mechanisms:
- Syntactic Analysis (DATYS+): An enhanced version of the DATYS tool, this component uses regular expressions and type-scoping to detect explicit mentions of API class names within the thread's text or code blocks.
- Semantic Analysis (API Relevance Classifier): This component leverages CodeBERT, a transformer model pre-trained on both natural language and source code. FACOS generates mathematical embeddings for paragraph-code pairs from SO threads and compares them against embeddings of the API’s official Javadoc and implementation code. This allows the system to recognize the intent of a discussion even when formal names are absent.
These two scores are merged into a Joint Relevance Score using a weighted formula. Interestingly, the authors found that the best performance is achieved when the semantic component is weighted more heavily (70%) than the syntactic component (30%).
Key Insights and Results
The study evaluated FACOS using a ground-truth dataset of 380 Stack Overflow threads and 807 labeled Java API mentions.
- Performance Gains: FACOS achieved an average F1-score of 0.873, representing a 13.9% improvement over the previous state-of-the-art tool, DATYS (0.734).
- The Necessity of Hybridization: Ablation studies revealed that the semantic model performs poorly in isolation (F1-score of 0.34). It requires the syntactic component to provide a "grounding" in actual names, while the semantic model provides the nuance necessary to filter out noise and capture implicit context.
- Bridging the Language Gap: Because CodeBERT is "multilingual" (understanding both English and Java), it effectively bridges the gap between a developer's informal query and the formal technical language used in API documentation.
Limitations and Future Work
Despite its success, FACOS faces challenges when two different libraries feature methods with identical names and nearly identical functionality (e.g., mock() in Mockito vs. PowerMock). In such cases, semantic analysis alone may struggle to distinguish between them.
Future research will focus on expanding the framework to support other programming languages like Python and C#, as well as scaling the evaluation to larger, more diverse datasets.
Summary updated