arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2005.14373cs.SEcs.IR
收藏

CodeMatcher:基于重要查询词顺序语义的搜索代码

CodeMatcher: Searching Code Based on Sequential Semantics of Important Query Words

Chao Liu, Xin Xia, David Lo, Zhiwei Liu, Ahmed E. Hassan, Shanping Li

摘要:

为了加速软件开发,开发人员经常从大规模代码库中搜索和重用现有代码片段,例如,GitHub.多年来,研究者们提出了许多基于信息检索的代码检索模型,但这些模型都未能将查询和代码之间的语义鸿沟联系起来。早期成功的基于深度学习的模型DeepCS通过学习代码方法对和相应的自然语言描述之间的关系解决了这个问题。DeepCS的两个主要优点是能够理解不相关/嘈杂的关键字,并捕获查询和代码中单词之间的顺序关系。在本文中,我们提出了一个基于IR的模型CodeMatcher,继承了DeepCS的优点,同时它可以利用基于IR的模型中的索引技术来大大加快搜索响应时间。CodeMatcher首先收集查询词的元数据以识别不相关/噪声词,然后在Elasticsearch工具索引的代码库上使用重要查询词迭代执行模糊搜索,最后根据候选代码片段中的标记如何顺序匹配查询中的重要词来重新排列返回的候选代码集。我们在一个拥有约41 k存储库的大规模代码库上验证了它的有效性。实验结果表明,CodeMatcher的MRR为0.60,比DeepCS、CodeHow和UNIF分别高出82%、62%和46%。我们提出的模型比DeepCS快1.2k倍以上。此外,CodeMatcher在MRR方面分别比GitHub和Google搜索高出46%和33%。我们还注意到:方法名在连接查询和代码中起着重要的作用,提高方法命名的质量有助于代码搜索。

英文摘要:

To accelerate software development, developers frequently search and reuse existing code snippets from a large-scale codebase, e.g., GitHub. Over the years, researchers proposed many information retrieval based models for code search, but they fail to connect the semantic gap between query and code. An early successful deep learning based model DeepCS solved this issue by learning the relationship between pairs of code methods and corresponding natural language descriptions. Two major advantages of DeepCS are the capability of understanding irrelevant/noisy keywords and capturing sequential relationships between words in query and code. In this paper, we proposed an IR-based model CodeMatcher that inherits the advantages of DeepCS, while it can leverage the indexing technique in the IR-based model to accelerate the search response time substantially. CodeMatcher first collects metadata for query words to identify irrelevant/noisy ones, then iteratively performs fuzzy search with important query words on the codebase that is indexed by the Elasticsearch tool, and finally reranks a set of returned candidate code according to how the tokens in the candidate code snippet sequentially matched the important words in a query. We verified its effectiveness on a large-scale codebase with ~41k repositories. Experimental results showed that CodeMatcher achieves an MRR of 0.60, outperforming DeepCS, CodeHow, and UNIF by 82%, 62%, and 46% respectively. Our proposed model is over 1.2k times faster than DeepCS. Moreover, CodeMatcher outperforms GitHub and Google search by 46% and 33% respectively in terms of MRR. We also observed that: fusing the advantages of IR-based and DL-based models is promising; improving the quality of method naming helps code search, since method name plays an important role in connecting query and code.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑