| Crates.io | scribe-analysis |
| lib.rs | scribe-analysis |
| version | 0.5.0 |
| created_at | 2025-09-13 06:22:40.588026+00 |
| updated_at | 2025-09-19 03:42:57.28238+00 |
| description | Code analysis algorithms and AST processing for Scribe |
| homepage | https://github.com/sibyllinesoft/scribe |
| repository | https://github.com/sibyllinesoft/scribe |
| max_upload_size | |
| id | 1837299 |
| size | 320,515 |
A sophisticated multi-dimensional file scoring system for code repository analysis, implementing advanced heuristics for file importance ranking.
final_score = ฮฃ(weight_i ร normalized_score_i) + priority_boost + template_boost
Score Components:
HeuristicWeights {
doc_weight: 0.15, // Documentation importance
readme_weight: 0.20, // README files get priority
import_weight: 0.20, // Dependency centrality
path_weight: 0.10, // Shallow files preferred
test_link_weight: 0.10, // Test-code relationships
churn_weight: 0.15, // Git activity recency
centrality_weight: 0.0, // Disabled in V1
entrypoint_weight: 0.05, // Entry points
examples_weight: 0.05, // Usage examples
}
HeuristicWeights {
doc_weight: 0.12,
readme_weight: 0.18,
import_weight: 0.15,
path_weight: 0.08,
test_link_weight: 0.08,
churn_weight: 0.12,
centrality_weight: 0.12, // PageRank enabled
entrypoint_weight: 0.08,
examples_weight: 0.07,
}
use scribe_analysis::heuristics::*;
// Create heuristic system
let mut system = HeuristicSystem::new()?;
// Score individual file
let score = system.score_file(&file, &all_files)?;
println!("Final score: {}", score.final_score);
// Get top-K files
let top_files = system.get_top_files(&files, 10)?;
// V2 features with centrality
let mut system = HeuristicSystem::with_v2_features()?;
// Custom weights
let weights = HeuristicWeights {
doc_weight: 0.25, // Boost documentation importance
readme_weight: 0.30,
// ... other weights
features: ScoringFeatures::v2(),
};
let mut system = HeuristicSystem::with_weights(weights)?;
// Check if file is a template
if is_template_file("component.vue")? {
let boost = get_template_score_boost("component.vue")?;
println!("Template boost: {}", boost);
}
// Advanced template analysis
let detector = TemplateDetector::new();
if let Some(result) = detector.detect_template("layout.hbs")? {
println!("Engine: {:?}, Confidence: {}", result.engine, result.confidence);
}
// Build dependency graph
let mut builder = ImportGraphBuilder::new();
let graph = builder.build_graph(&files)?;
// Calculate PageRank centrality
let scores = graph.get_pagerank_scores()?;
// Check import relationships
if import_matches_file("@/components/Button", "src/components/Button.tsx") {
println!("Import matches file!");
}
# Run full benchmark suite
cargo bench --package scribe-analysis
# Specific benchmark groups
cargo bench single_file_scoring
cargo bench batch_scoring
cargo bench template_detection
cargo bench import_analysis
scoring.rs: Core scoring algorithms and weight managementtemplate_detection.rs: Multi-engine template recognitionimport_analysis.rs: Dependency graph construction and centralitymod.rs: Unified API and system orchestrationScanResult trait for flexible input typesimpl ScanResult for YourFileType {
fn path(&self) -> &str { &self.path }
fn is_docs(&self) -> bool { self.is_documentation }
fn imports(&self) -> Option<&[String]> { self.imports.as_deref() }
// ... other required methods
}
scribe_core::ResultThe implementation has been benchmarked to validate performance targets:
MIT OR Apache-2.0