Files
PdfMarker_Web/PdfMarker/Services/BallooningService.cs
2026-01-23 09:57:52 +01:00

68 lines
1.8 KiB
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using PdfMarker.Models;
namespace PdfMarker.Services;
public class BallooningService
{
private readonly PdfQuotaExtractor _quotaExtractor;
private readonly QuotaClusterer _clusterer;
private readonly IWebHostEnvironment _env;
public BallooningService(
PdfQuotaExtractor quotaExtractor,
QuotaClusterer clusterer,
IWebHostEnvironment env)
{
_quotaExtractor = quotaExtractor;
_clusterer = clusterer;
_env = env;
}
public async Task<AutoBalloonResult> GenerateAsync(string fileName)
{
// 1⃣ Path fisico del PDF
var pdfPath = Path.Combine(
_env.WebRootPath,
"pdf",
fileName);
// 2⃣ Estrazione QUOTE
var quotes = _quotaExtractor.Extract(pdfPath);
// 🔴 CHECK CRITICO
// se qui quotes è vuoto → il problema NON è il clustering
if (quotes.Count == 0)
{
return new AutoBalloonResult
{
Balloons = new List<BalloonVm>()
};
}
// 3⃣ Clustering QUOTE → FEATURE
var features = _clusterer.Cluster(quotes);
// 4⃣ Feature → Pallini
var balloons = new List<BalloonVm>();
int index = 1;
foreach (var feature in features)
{
balloons.Add(new BalloonVm
{
Number = index++,
Description = string.Join(" | ",
feature.Quotes.Select(q => q.RawText)),
X = feature.CenterX,
Y = feature.CenterY,
Selected = false
});
}
// 5⃣ Output finale
return new AutoBalloonResult
{
Balloons = balloons
};
}
}