Skip to main content
CenXiv.org
此网站处于试运行阶段,支持我们!
我们衷心感谢所有贡献者的支持。
贡献
赞助
cenxiv logo > cs > arXiv:2507.02107

帮助 | 高级搜索

计算机科学 > 软件工程

arXiv:2507.02107 (cs)
[提交于 2025年7月2日 ]

标题: 基于自然语言查询的结构化代码搜索

标题: Structural Code Search using Natural Language Queries

Authors:Ben Limpanukorn, Yanjun Wang, Zach Patterson, Pranav Garg, Murali Krishna Ramanathan, Xiaofei Ma, Anoop Deoras, Miryung Kim
摘要: 搜索代码是开发人员执行的常见任务,以理解API、学习常见的代码模式和导航代码。目前,开发人员最常用的关键字和正则表达式进行搜索,这些方法易于使用且广泛可用。除了关键字和正则表达式之外,结构化代码搜索工具允许开发人员根据语法结构搜索代码。这在从错误查找系统地重构代码等各种应用中都有用处。然而,这些结构化代码搜索工具的操作是通过领域特定语言(DSL)编写的查询,这些语言可能难以学习和编写。我们提出允许开发人员使用自然语言进行结构化代码搜索。用自然语言表达查询提供了一种直观的代码搜索方式,并降低了入门门槛。在这项工作中,我们开发了一种新颖的通用方法,将大型语言模型(LLM)的推理能力结合起来,以解释自然语言搜索查询,并利用结构化搜索工具的强大功能来高效准确地检索相关代码。然后,我们将这种方法应用于两种结构化代码搜索DSL:Semgrep和GQL。在我们的评估中,我们构建了一个新的结构化代码搜索基准,包含10个Java项目上的400个查询。我们表明,基于使用LLM将自然语言查询转换为DSL查询的结构化代码搜索方法是有效且稳健的,在精度和召回率方面达到55% - 70%的高水平。此外,我们的方法在F1分数上比基于语义代码搜索和LLM检索的基线方法显著优越,最高可达57%和14%。
摘要: Searching code is a common task that developers perform to understand APIs, learn common code patterns, and navigate code. Currently, developers most commonly search using keywords and regular expressions that are easy to use and widely available. Beyond keywords and regular expressions, structural code search tools allow developers to search for code based on its syntactic structure. This has numerous applications ranging from bug finding to systematically refactoring code. However, these structural code search tools operate on queries expressed in domain-specific languages (DSL) that can be difficult to learn and write. We propose to allow developers to use natural language to search for code structurally. Expressing queries in natural language provides an intuitive way to search for code and lowers the barrier to entry. In this work, we develop a novel general approach that combines the reasoning capabilities of an LLM to interpret natural language search queries with the power of structural search tools to efficiently and accurately retrieve relevant code. We then instantiate this approach for two structural code search DSLs: Semgrep and GQL. In our evaluation, we construct a new benchmark for structural code search consisting of 400 queries over 10 Java projects. We show that our approach for structural code search based on translating NL queries to DSL queries using an LLM is effective and robust, achieving a high precision and recall ranging from 55% - 70%. Further, our approach significantly outperforms baselines based on semantic code search and LLM retrievals by up to 57% and 14% on F1 scores.
主题: 软件工程 (cs.SE) ; 编程语言 (cs.PL)
引用方式: arXiv:2507.02107 [cs.SE]
  (或者 arXiv:2507.02107v1 [cs.SE] 对于此版本)
  https://doi.org/10.48550/arXiv.2507.02107
通过 DataCite 发表的 arXiv DOI

提交历史

来自: Yanjun Wang [查看电子邮件]
[v1] 星期三, 2025 年 7 月 2 日 19:42:37 UTC (3,910 KB)
全文链接:

获取论文:

    查看标题为《》的 PDF
  • 查看中文 PDF
  • 查看 PDF
  • HTML(实验性)
  • TeX 源代码
  • 其他格式
许可图标 查看许可
当前浏览上下文:
cs.SE
< 上一篇   |   下一篇 >
新的 | 最近的 | 2025-07
切换浏览方式为:
cs
cs.PL

参考文献与引用

  • NASA ADS
  • 谷歌学术搜索
  • 语义学者
a 导出 BibTeX 引用 加载中...

BibTeX 格式的引用

×
数据由提供:

收藏

BibSonomy logo Reddit logo

文献和引用工具

文献资源探索 (什么是资源探索?)
连接的论文 (什么是连接的论文?)
Litmaps (什么是 Litmaps?)
scite 智能引用 (什么是智能引用?)

与本文相关的代码,数据和媒体

alphaXiv (什么是 alphaXiv?)
CatalyzeX 代码查找器 (什么是 CatalyzeX?)
DagsHub (什么是 DagsHub?)
Gotit.pub (什么是 GotitPub?)
Hugging Face (什么是 Huggingface?)
带有代码的论文 (什么是带有代码的论文?)
ScienceCast (什么是 ScienceCast?)

演示

复制 (什么是复制?)
Hugging Face Spaces (什么是 Spaces?)
TXYZ.AI (什么是 TXYZ.AI?)

推荐器和搜索工具

影响之花 (什么是影响之花?)
核心推荐器 (什么是核心?)
IArxiv 推荐器 (什么是 IArxiv?)
  • 作者
  • 地点
  • 机构
  • 主题

arXivLabs:与社区合作伙伴的实验项目

arXivLabs 是一个框架,允许合作伙伴直接在我们的网站上开发和分享新的 arXiv 特性。

与 arXivLabs 合作的个人和组织都接受了我们的价值观,即开放、社区、卓越和用户数据隐私。arXiv 承诺这些价值观,并且只与遵守这些价值观的合作伙伴合作。

有一个为 arXiv 社区增加价值的项目想法吗? 了解更多关于 arXivLabs 的信息.

这篇论文的哪些作者是支持者? | 禁用 MathJax (什么是 MathJax?)
  • 关于
  • 帮助
  • contact arXivClick here to contact arXiv 联系
  • 订阅 arXiv 邮件列表点击这里订阅 订阅
  • 版权
  • 隐私政策
  • 网络无障碍帮助
  • arXiv 运营状态
    通过...获取状态通知 email 或者 slack

京ICP备2025123034号