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

614                                                        软件学报  2026  年第  37  卷第  2  期


                 一步突显了    SRBCS  在代码注释生成方面的有效性. 同时, 还注意到受访者对代码注释的评分与                       METEOR  呈现高
                 相关性. 一般而言, METEOR     得分越高的方法, 其在用户调研中的评分越高. 这一发现与先前研究中的发现一致                         [48] .

                                                                                词法检索
                                                                                语义检索
                             5                                                  SiT
                                                                                Script
                                                                                AST-Trans
                             4                                                  CodeBERT
                                                                                CodeT5
                                                                                Code LLaMA-fewshot
                           平均分数  3                                              DeepSeek-Coder-fewshot
                                                                                Qwen-Coder-fewshot
                                                                                Re2Com
                             2
                                                                                Recons
                                                                                EditSum
                             1                                                  DECOM
                                                                                Code LLaMA-RAG
                                                                                DeepSeek-Coder-RAG
                             0
                                                                                Qwen-Coder-RAG
                                  受访者 A      受访者 B      受访者 C      受访者 D        SRBCS
                                          图 5 对于各方法所生成的代码注释的用户评估

                    此外, 我们还进一步对       SRBCS  的重排序过程进行了分析, 以观察基于检索的方法和基于深度学习的方法分别
                 在何种情况下会具有更高的有效性. 我们发现, 当代码与其检索代码之间的词级相似度越高时, 基于检索的方法所
                 生成的注释被选择的概率越高, 特别对于那些存在克隆现象的代码而言. 图                       6  给出了该情况的一个例子. 在该例子
                 中, 基于词法检索的方法成功从训练数据集中检索到了与测试代码具有相同功能但不同变量名的训练代码, 从而
                 生成了一段与真实注释完全一致的代码注释; 而在该情况下, 基于深度学习的方法则无法有效预测代码运行环境.
                 同时, 还注意到基于深度学习的方法在生成长代码注释方面存在挑战, 而基于检索的方法由于直接从训练数据中
                 检索相关代码注释可以更好进行长代码注释生成. 因此在面对长代码注释时, 基于检索的方法所生成注释同样具
                 有较高概率被重排序在更优位置. 与之相反, 当训练数据中无法检索到高词级相似的训练代码时, 基于检索的方法
                 无法得到相似代码, 从而导致其选择不恰当的代码注释作为测试代码的注释. 而基于深度学习的方法由于经过大
                 量数据训练, 其可以更好地捕捉代码中深层次语义信息用于代码注释生成, 从而得到质量更优的代码注释.

                            #  真实注释:  avoid extraneous  whitespace  in  the  following  situations:  - more  than  one  space  around  an
                            assignment operator to align it with another .
                            def whitespace_around_operator ( logical_line ) :
                               for match in OPERATOR_REGEX . finditer ( logical_line ) :
                                 (before, after) = match. groups ( )
                                 if (_STR in before) :
                                    (yield (match.start ( _NUM ) , _STR ) )
                                 elif (len ( before ) > _NUM ) :
                                    ( yield ( match.start (_NUM) , _STR ) )
                                 if ( _STR in after ) :
                                    (yield (match.start ( _NUM ) , _STR ) )
                                 elif (len ( after ) > _NUM ) :
                                    (yield ( match.start ( _NUM ) , _STR ) )",
                            #  基于词法检索的方法生成的标签: avoid extraneous whitespace in the following situations: - more than one
                            space around an assignment operator to align it with another
                            def whitespace_around_operator(logical_line):
                               for match in OPERATOR_REGEX.finditer(logical_line):
                                 (before, after) = match.groups()
                                 if (' DCTB ' in before):
                                    (yield (match.start(1), 'E223\ttab\tbefore\toperator'))
                                 elif (len(before) > 1):
                                    (yield (match.start(1), 'E221\tmultiple\tspaces\tbefore\toperator'))
                                 if (' DCTB ' in after):
                                    (yield (match.start(2), 'E224\ttab\tafter\toperator'))
                                 elif (len(after) > 1):
                                    (yield (match.start(2), 'E222\tmultiple\tspaces\tafter\toperator'))
                            # CodeT5 生成的标签: avoid extraneous whitespace in the following situations: - immediately inside parentheses
                                           图 6 基于检索的方法所生成代码注释被选择
   130   131   132   133   134   135   136   137   138   139   140