feat: Update package references and enhance AI extraction service with CSV output functionality
This commit is contained in:
parent
55e8f0face
commit
af74c90ce7
12 changed files with 400 additions and 153 deletions
|
|
@ -198,20 +198,7 @@ public class AiExtractionService : IAiExtractionService
|
|||
{
|
||||
try
|
||||
{
|
||||
var dir = Path.GetDirectoryName(request.CsvOutputPath) ?? string.Empty;
|
||||
if (!string.IsNullOrWhiteSpace(dir) && !Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
using var sw = new StreamWriter(request.CsvOutputPath, false, Encoding.UTF8);
|
||||
sw.WriteLine("Path,Text");
|
||||
foreach (var r in extractedResults)
|
||||
{
|
||||
var csvFileName = Path.GetFileName(r.Path ?? string.Empty);
|
||||
var safeText = (r.Text ?? string.Empty).Replace("\"", "\"\"");
|
||||
sw.WriteLine($"\"{csvFileName}\",\"{safeText}\"");
|
||||
}
|
||||
WriteCsvOutput(request.CsvOutputPath, extractedResults);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -222,6 +209,24 @@ public class AiExtractionService : IAiExtractionService
|
|||
return summary;
|
||||
}
|
||||
|
||||
internal static void WriteCsvOutput(string csvOutputPath, IEnumerable<AiResultItem> extractedResults)
|
||||
{
|
||||
var dir = Path.GetDirectoryName(csvOutputPath) ?? string.Empty;
|
||||
if (!string.IsNullOrWhiteSpace(dir) && !Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
using var sw = new StreamWriter(csvOutputPath, false, Encoding.UTF8);
|
||||
sw.WriteLine("filename,text");
|
||||
foreach (var result in extractedResults)
|
||||
{
|
||||
var csvFileName = Path.GetFileName(result.Path ?? string.Empty);
|
||||
var safeText = (result.Text ?? string.Empty).Replace("\"", "\"\"");
|
||||
sw.WriteLine($"\"{csvFileName}\",\"{safeText}\"");
|
||||
}
|
||||
}
|
||||
|
||||
private static double CalculateAverageImagesPerSecond(int processed, TimeSpan elapsed)
|
||||
{
|
||||
return elapsed.TotalSeconds > 0 ? processed / elapsed.TotalSeconds : 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue