一种基于层次化上下文感知的代码摘要生成方法及系统

By constructing a function call graph and a hierarchical generation mechanism, the problem of insufficient context modeling in code comment generation of large language models is solved, generating accurate, consistent and understandable code comments, thus improving code maintainability and readability.

CN121957613BActive Publication Date: 2026-07-17HANGZHOU DIANZI UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HANGZHOU DIANZI UNIV
Filing Date
2026-03-31
Publication Date
2026-07-17

AI Technical Summary

Technical Problem

Existing code annotation generation methods based on large language models are insufficient in project-level context modeling, resulting in poor semantic consistency of the generated annotations, an inability to deeply understand complex call structures, and a tendency to produce inaccurate descriptions when domain-related knowledge is lacking.

Method used

By constructing a function call graph to eliminate loop structures, identifying and classifying leaf nodes, calculating the importance score of child nodes, and combining it with a large language model to generate annotations, a hierarchical generation mechanism is adopted to generate annotations layer by layer from bottom to top. Class function descriptions are introduced as multi-source contexts to ensure the accuracy and consistency of annotations.

Benefits of technology

It significantly improves the accuracy and semantic consistency of annotations, overcomes the input length limitation of large language models, enhances the ability to model project-level contexts, generates annotations that are consistent with the code design intent, and has strong anti-interference capabilities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121957613B_ABST
    Figure CN121957613B_ABST
Patent Text Reader

Abstract

本发明公开了一种基于层次化上下文感知的代码摘要生成方法及系统,属于自然语言处理和软件工程领域。该方法基于函数调用图为代码仓库生成层级注释,首先提取图中的调用关系并消除环结构,然后对叶子节点分类并生成注释;核心步骤采用自底向上的拓扑顺序:为每个父节点计算子节点的重要性得分,并融合其子节点注释、类功能描述及自身代码体,输入大语言模型生成注释,直至覆盖全图。本发明适用于复杂软件项目的自动化文档生成场景,通过函数调用图分析、子节点重要性度量和类功能描述相结合的技术路径,提升代码注释的准确性和语义一致性,可广泛应用于软件维护、代码理解、智能开发工具以及企业级代码仓库的自动化文档生成等领域。
Need to check novelty before this filing date? Find Prior Art

Citation Information

Patent Citations

  • Code abstract generation method fusing abstract syntax tree node features

    CN116820557A

  • Adaptive code annotation updating method and system, terminal and storage medium

    CN119576363A