使用文本分类检测API规范中的API指令
Discovering API Directives from API Specifications with Text Classification
-
摘要: 1、研究背景(context):API规范是软件开发人员学习API的正确使用时需要参考的最重要的资源之一。在参考API规范时,开发人员必须特别注意API指令,这些API指令说明了调用API所必须满足的约束和限制,以避免导致软件缺陷和效率低下。然而,API指令通常包含在冗长的API规范中,导致开发人员发现所有相关的API指令既费时又容易出错。
2、目的(Objective):尽管研究人员提出了一种从API规范中检测API指令的方法,但检测效果仍有很大的提升空间。本研究的目标是提出一种新的利用文本分类从API规范中检测API指令的方法,提高API指令的检测效率。
3、方法(Method):我们的方法包括两个阶段,即模型构建阶段和预测阶段。在模型构建阶段,我们的方法采用欠采样策略来处理类不平衡训练集(API指令仅占API规范内容的非常小的一部分)。基于采样后的训练集,我们的方法训练了几个随机森林分类器。在预测阶段,我们的方法将训练好的分类器结合起来,为API规范中新句子的类标签进行投票,决定其是否是API指令。
4、结果(Result&Findings):为了验证新方法的有效性,我们在标注好的API指令语料库(包含超过85,000个句子)上对其进行了评估。实验结果表明,我们的方法最高可以达到82.08%的F度量值。此外,就F量度值而言,我们的方法显著超过现有方法,最高超过现有方法29.67%。
5、结论(Conclusions):在API规范中突出显示API指令可以帮助软件开发人员正确地使用API进行编程并避免错误。在本研究中,我们提出了一种利用文本分类从API规范中检测API指令的新方法。实验结果表明,我们提出的新方法显著优于现有方法。Abstract: Application programming interface (API) libraries are extensively used by developers. To correctly program with APIs and avoid bugs, developers shall pay attention to API directives, which illustrate the constraints of APIs. Unfortunately, API directives usually have diverse morphologies, making it time-consuming and error-prone for developers to discover all the relevant API directives. In this paper, we propose an approach leveraging text classification to discover API directives from API specifications. Specifically, given a set of training sentences in API specifications, our approach first characterizes each sentence by three groups of features. Then, to deal with the unequal distribution between API directives and non-directives, our approach employs an under-sampling strategy to split the imbalanced training set into several subsets and trains several classifiers. Given a new sentence in an API specification, our approach synthesizes the trained classifiers to predict whether it is an API directive. We have evaluated our approach over a publicly available annotated API directive corpus. The experimental results reveal that our approach achieves an F-measure value of up to 82.08%. In addition, our approach statistically outperforms the state-of-the-art approach by up to 29.67% in terms of F-measure.