use crate::domain::edge::EdgeKind;
use crate::domain::graph::ContextGraph;
use crate::domain::node::Node;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum NodeType {
Function,
Variable,
Type,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PruningDecision {
Boundary, Transparent, }
pub trait PruningPolicy: Send + Sync {
fn evaluate(
&self,
source: &Node,
target: &Node,
edge_kind: &EdgeKind,
graph: &ContextGraph,
) -> PruningDecision;
fn doc_threshold(&self) -> f32 {
0.5
}
}
pub trait SizeFunction: Send + Sync {
fn compute(&self, source: &str, span: &SourceSpan, doc_texts: &[String]) -> u32;
}
pub use crate::domain::node::SourceSpan;
pub trait DocumentationScorer: Send + Sync {
fn score(&self, node_info: &NodeInfo, doc_text: Option<&str>) -> f32;
}
pub struct NodeInfo {
pub node_type: NodeType,
pub name: String,
pub signature: Option<String>, pub language: Option<String>, }
#[cfg(test)]
mod tests {
use super::*;
use crate::domain::edge::EdgeKind;
use crate::domain::graph::ContextGraph;
use crate::domain::node::Node;
struct UseDefaultDocThreshold;
impl PruningPolicy for UseDefaultDocThreshold {
fn evaluate(&self, _: &Node, _: &Node, _: &EdgeKind, _: &ContextGraph) -> PruningDecision {
PruningDecision::Transparent
}
}
#[test]
fn test_default_doc_threshold() {
assert!((UseDefaultDocThreshold.doc_threshold() - 0.5).abs() < 1e-5);
}
}