This invention relates to the field of
software engineering technology and discloses a method and
system for generating code annotations based on a
dual graph neural network. The method includes: acquiring
source code and
natural language annotations as
source code, preprocessing the
source code, and constructing training data based on the preprocessed source code and
natural language annotations; constructing a code
processing model, training the code
processing model using the training data, and obtaining a trained code
processing model. The code processing model includes a
dual graph module, an
encoder, an aggregator, and a decoder. The
dual graph module parses the preprocessed source code to obtain an
abstract syntax tree (AST), and constructs a syntactic
dependency graph and a
semantic dependency graph based on the AST; the
encoder obtains a first encoding representation based on the syntactic
dependency graph and a second encoding representation based on the
semantic dependency graph; the aggregator obtains an aggregate graph representation based on the first and second encoding representations; the decoder generates
natural language annotations based on the first, second, and aggregate graph representations; and inputting the code to be annotated into the trained code processing model to obtain natural language annotations. This invention can more effectively
encode code structure, improve the accuracy of
annotation generation, and enhance the generalization ability of the code processing model.