14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/legion/extensions/knowledge/runners/corpus.rb', line 14
def corpus_stats(path:, extensions: nil)
return { success: false, error: 'path does not exist' } unless ::File.exist?(path)
opts = { path: path }
opts[:extensions] = extensions if extensions
entries = Helpers::Manifest.scan(**opts)
chunk_count = entries.sum do |entry|
sections = Helpers::Parser.parse(file_path: entry[:path])
next 0 if sections.first&.key?(:error)
Helpers::Chunker.chunk(sections: sections).size
end
{
success: true,
path: path,
file_count: entries.size,
estimated_chunks: chunk_count,
total_bytes: entries.sum { |e| e[:size] }
}
rescue StandardError => e
{ success: false, error: e.message }
end
|