Skip to main content

code_repo_wiki/model/
mod.rs

1pub mod node;
2pub mod edge;
3pub mod document;
4
5pub use node::*;
6pub use edge::*;
7pub use document::*;
8
9use petgraph::stable_graph::StableDiGraph;
10use serde::{Deserialize, Serialize};
11
12/// 完整的知识图谱
13#[derive(Debug, Clone, Serialize, Deserialize)]
14pub struct KnowledgeGraph {
15    pub graph: StableDiGraph<CodeNode, CodeEdge>,
16    /// 模块聚类结果
17    pub modules: Vec<ModuleCluster>,
18    /// 实体级特征聚类结果(跨文件协作实现同一功能的方法组)
19    #[serde(default)]
20    pub features: Vec<Feature>,
21}
22
23/// 模块聚类
24#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
25pub struct ModuleCluster {
26    pub name: String,
27    pub node_ids: Vec<NodeId>,
28    pub cohesion: f64,
29    pub coupling: f64,
30    pub description: Option<String>,
31}
32
33/// 特征聚类:跨文件协作实现同一功能的一组方法(演进计划 T1.2b)
34#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
35pub struct Feature {
36    /// 特征名(确定性命名,如 feature_0)
37    pub name: String,
38    /// 参与该特征的方法节点集合
39    pub node_ids: Vec<NodeId>,
40    /// LLM 生成的特征职责描述(卡片生成阶段填充)
41    pub description: Option<String>,
42}
43
44impl Default for KnowledgeGraph {
45    fn default() -> Self {
46        Self {
47            graph: StableDiGraph::new(),
48            modules: Vec::new(),
49            features: Vec::new(),
50        }
51    }
52}