This commit is contained in:
2026-01-23 09:57:52 +01:00
commit 831badd188
136 changed files with 7705 additions and 0 deletions

View File

@ -0,0 +1,68 @@
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
};
}
}