首页|期刊导航|软件导刊|基于图神经网络的相似性代码检测方法

基于图神经网络的相似性代码检测方法OA

Code Similarity Detection Method Based on Graph Neural Network

中文摘要英文摘要

针对现有代码相似性检测方法在语义表达能力方面的不足,提出一种基于图神经网络的代码相似性分析方法.现有技术通常可分为基于文本、基于词法单元、基于语法结构以及基于程序依赖关系的多种类型,但大多侧重单一层面的特征表示,难以有效捕获程序执行过程中的深层语义信息.为解决这一问题,构建一种融合语法结构与程序行为特征的图表示模型.具体而言,以抽象语法树为基础框架,通过引入控制依赖边与数据依赖边,对原有树结构进行扩展,从而形成包含多类型关系的程序图表示.在此基础上,利用图神经网络对代码片段进行表示学习,通过节点间信息传播与聚合获得代码的向量化表示,并采用余弦相似度对不同代码片段进行相似性度量.该方法能够同时刻画程序的结构特征与语义信息,从而提升对复杂代码相似性的识别能力.实验结果表明,与传统方法相比,所提方法在语义相似性检测任务中具有更好的性能表现.

To address the shortcomings of existing code similarity detection methods in terms of semantic representation capabilities,this pa-per proposes a code similarity analysis method based on graph neural networks.Existing techniques are generally categorized into text-based,lexical unit-based,syntactic structure-based,and program dependency-based methods,but most focus on single-level feature representa-tion,failing to effectively capture deep semantic information during program execution.To solve this problem,this paper constructs a graph representation model that integrates syntactic structure and program behavior features.Specifically,based on an abstract syntax tree frame-work,the original tree structure is expanded by introducing control dependency edges and data dependency edges,thus forming a program graph representation containing multiple types of relationships.On this basis,a graph neural network is used to learn the representation of code fragments,obtaining vectorized representations of the code through information propagation and aggregation between nodes,and using co-sine similarity to measure the similarity of different code fragments.This method can simultaneously characterize the structural features and se-mantic information of the program,thereby improving the ability to identify complex code similarities.Experimental results show that the pro-posed method has better performance in semantic similarity detection tasks compared to traditional methods.

赵涵;崔博夕;张卫丰

南京邮电大学 计算机学院,江苏 南京 210023南京邮电大学 计算机学院,江苏 南京 210023南京邮电大学 计算机学院,江苏 南京 210023

信息技术与安全科学

图神经网络代码相似性检测数据流控制流

graph neural networksimilarity code detectiondata flowcontrol flow

《软件导刊》 2026 (6)

48-55,8

国家自然科学基金面上项目(62272214)南京市国际合作项目(202401006)

10.11907/rjdk.241789

评论