CodeGraph:基于Wikidata锚定的源代码开放分类知识图谱

·

研究论文 · 2026/09/28

公共软件仓库(如GitHub和Software Heritage Archive)存储了数十亿文件,但提取其隐含的工程知识(如算法、范式、模式和应用领域)仍具挑战,因为现有工具局限于语法和词元级分析。我们提出一个使用代码专用大语言模型构建源代码开放分类语义标注的流程。提取的实体通过三阶段链接程序锚定到Wikidata:确定性SPARQL阶段处理无歧义实体,深度研究代理解决剩余长尾,层次汇总阶段导入每个已解析Wikidata标识符的父类闭包。生成的标注物化为源代码特定的开放分类知识图谱。我们进一步引入校准的质量保证协议,通过结合小型人工金标准集和LLM作为评判过滤器来量化标注精度。我们将流程应用于Stack-Edu语料的1.67亿文件,创建了首个已知的大规模源代码开放分类知识图谱。我们的图谱名为CodeGraph,包含约1.58亿节点,其中包括约1.45亿文件、约6.3万个提取的概念实体(如算法、范式、设计模式和应用领域)以及约1.98万个锚定的Wikidata实体。此外,CodeGraph具有约10亿条类型化边,连接文件到各自概念、链接概念到其锚定的Wikidata标识符,并关联到父类别,覆盖14种编程语言。

该工作首次实现了大规模源代码的开放分类知识图谱构建,将代码语义与Wikidata锚定,为代码理解、搜索和推荐提供了结构化知识基础,并提出了可量化的质量保证方法,对软件工程和知识图谱领域具有重要价值。

Public software repositories, like GitHub and Software Heritage Archive, store billions of files, yet extracting their implicit engineering knowledge ---i.e., the algorithms they implement, the paradigms they follow, the patterns they instantiate, and the application domains they serve--- remains challenging, as current tools are constrained to syntactic and token-level analysis. We present a pipeline for building an open-taxonomy semantic annotation of source code using a code-specialised Large Language Model. The extracted entities are grounded in Wikidata through a three-stage linking procedure: a deterministic SPARQL stage handles unambiguous entities, a Deep Research Agent resolves the residual long tail, and a hierarchy-rollup stage imports the parent-of closure of each resolved Wikidata identifier. The resulting annotations are materialised as a source-code-specific open-taxonomy knowledge graph. We further introduce a calibrated quality-assurance protocol that quantifies annotation precision by combining a small human gold set with an LLM-as-a-judge filter. We applied our pipeline to the 167 million files of the Stack-Edu corpus, creating the first known large-scale open-taxonomy knowledge graph for source code. Our graph, named CodeGraph, contains approximately 158 million nodes, which include around 145 million files, about 63,000 extracted concept entities (such as algorithms, paradigms, design patterns, and application domains), and roughly 19,800 grounded Wikidata entities. Furthermore, CodeGraph features approximately 1 billion typed edges that connect files to their respective concepts, link these concepts to their grounded Wikidata identifiers, and relate them to their parent categories, covering 14 programming languages.

阅读原文

参与讨论