Page 122 - 《软件学报》2026年第2期
P. 122

软件学报 ISSN 1000-9825, CODEN RUXUEW                                        E-mail: jos@iscas.ac.cn
                 2026,37(2):601−620 [doi: 10.13328/j.cnki.jos.007470] [CSTR: 32375.14.jos.007470]  http://www.jos.org.cn
                 ©中国科学院软件研究所版权所有.                                                          Tel: +86-10-62562563



                                                              *
                 基于语义重排序的代码注释生成方法

                 李    重  1,2 ,    施超煊  1,3 ,    潘敏学  1,2 ,    张    天  1,3 ,    王林章  1,3 ,    李宣东  1,3


                 1
                  (计算机软件新技术全国重点实验室        (南京大学), 江苏 南京 210023)
                 2
                  (南京大学 软件学院, 江苏 南京 210093)
                 3
                  (南京大学 计算机学院, 江苏 南京 210023)
                 通信作者: 张天, E-mail: ztluck@nju.edu.cn

                 摘 要: 代码注释是对源代码功能的自然语言描述, 其可以帮助开发人员快速地理解代码语义及功能, 从而提高软
                 件开发和维护的效率. 然而, 书写与维护代码注释费时费力, 导致代码注释经常出现缺失、不匹配以及过时等问题.
                 因此, 如何自动化地为源代码生成注释引起了大量研究人员的关注. 现有方法通常利用信息检索技术或深度学习
                 技术来进行代码注释自动生成, 但这二者均存在自身的一些局限. 目前已有一些对信息检索技术和深度学习技术
                 进行集成的研究工作, 但它们无法有效利用这两种技术优势. 针对这些问题, 提出一种基于语义重排序的代码注释
                 生成方法   SRBCS, 该方法通过语义重排序模型对不同方法所生成代码注释进行排序选择来实现代码注释生成, 从
                 而在实现对不同方法集成的同时最大化地利用不同方法在代码注释生成上的优势. 在两个数据集上将                                   SRBCS  与
                 14  种代码注释生成方法进行比较. 实验评估结果表明               SRBCS  可以有效地对不同代码注释生成方法进行集成, 实
                 现了优于现有     14  种代码注释生成方法的性能.
                 关键词: 代码注释生成; 语义重排序模型; 对比学习
                 中图法分类号: TP311


                 中文引用格式: 李重, 施超煊, 潘敏学, 张天, 王林章, 李宣东. 基于语义重排序的代码注释生成方法. 软件学报, 2026, 37(2): 601–620.
                 http://www.jos.org.cn/1000-9825/7470.htm
                 英文引用格式: Li Z, Shi CX, Pan MX, Zhang T, Wang LZ, Li XD. Code Comment Generation Method Based on Semantic Reranking.
                 Ruan Jian Xue Bao/Journal of Software, 2026, 37(2): 601–620 (in Chinese). http://www.jos.org.cn/1000-9825/7470.htm
                 Code Comment Generation Method Based on Semantic Reranking

                        1,2
                                      1,3
                                                               1,3
                                                                               1,3
                                                  1,2
                 LI Zhong , SHI Chao-Xuan , PAN Min-Xue , ZHANG Tian , WANG Lin-Zhang , LI Xuan-Dong 1,3
                 1
                 (State Key Laboratory for Novel Software Technology (Nanjing University), Nanjing 210023, China)
                 2
                 (Software Institute, Nanjing University, Nanjing 210093, China)
                 3
                 (School of Computer Science, Nanjing University, Nanjing 210023, China)
                 Abstract:  Code  comments  serve  as  natural-language  descriptions  of  the  source  code  functionality,  helping  developers  quickly  understand
                 the  code’s  semantics  and  functionality,  thus  improving  software  development  and  maintenance  efficiency.  However,  writing  and
                 maintaining  code  comments  is  time-consuming  and  labor-intensive,  often  leading  to  issues  such  as  absence,  inconsistency,  and
                 obsolescence.  Therefore,  the  automatic  generation  of  comments  for  source  code  has  attracted  significant  attention.  Existing  methods
                 typically  use  information  retrieval  techniques  or  deep  learning  techniques  for  automatic  code  comment  generation,  but  both  have  their
                 limitations.  Some  research  has  integrated  these  two  techniques,  but  such  approaches  often  fail  to  effectively  leverage  the  advantages  of
                 both  methods.  To  address  these  issues,  this  study  proposes  a  semantic  reranking-based  code  comment  generation  method,  SRBCS.  SRBCS
                 employs  a  semantic  reranking  model  to  rank  and  select  comments  generated  by  various  approaches,  thus  integrating  multiple  methods  and


                 *    基金项目: 国家自然科学基金  (62402214, 62372227, 62232014); 江苏省自然科学基金  (BK20241194)
                  收稿时间: 2024-12-16; 修改时间: 2025-02-05, 2025-04-07; 采用时间: 2025-05-11; jos 在线出版时间: 2025-09-17
                  CNKI 网络首发时间: 2025-09-18
   117   118   119   120   121   122   123   124   125   126   127