Backup #1818
| ID | 1818 |
| Dateipfad | /var/www/dev.campus.systemische-tools.de/src/UseCases/Taxonomy/GetTaxonomyOverviewUseCase.php |
| Version | 5 |
| Typ |
modified |
| Größe | 4.9 KB |
| Hash | aecfb6eeff7d6281e09bce0bc3fed5458a84dc6ac74d604f0c40e01d91d1b19f |
| Datum | 2025-12-27 23:15:10 |
| Geändert von | claude-code-hook |
| Grund | Claude Code Pre-Hook Backup vor Edit-Operation |
| Datei existiert |
Ja
|
Dateiinhalt
<?php
declare(strict_types=1);
namespace UseCases\Taxonomy;
// @responsibility: Taxonomie-Übersicht mit aggregierten Statistiken
use Domain\Constants;
use Domain\Repository\ChunkTaxonomyRepositoryInterface;
use Domain\Repository\EntityTaxonomyRepositoryInterface;
use Domain\Repository\TaxonomyRepositoryInterface;
final class GetTaxonomyOverviewUseCase
{
public function __construct(
private ChunkTaxonomyRepositoryInterface $chunkTaxonomyRepository,
private EntityTaxonomyRepositoryInterface $entityTaxonomyRepository,
private TaxonomyRepositoryInterface $taxonomyRepository
) {
}
/**
* Get complete taxonomy overview with statistics.
*
* @return array{
* taxonomy_stats: array{total_terms: int, root_terms: int, max_depth: int, tagged_chunks: int},
* chunk_coverage: array{total: int, mapped: int, percentage: float},
* entity_validation: array{total: int, validated: int, pending: int},
* term_usage: array<int, int>
* }
*/
public function execute(): array
{
$taxonomyStats = $this->taxonomyRepository->getStats();
$chunkCoverage = $this->calculateChunkCoverage();
$entityValidation = $this->entityTaxonomyRepository->getValidationStats();
$termUsage = $this->chunkTaxonomyRepository->countByTaxonomyTerm();
return [
'taxonomy_stats' => $taxonomyStats,
'chunk_coverage' => $chunkCoverage,
'entity_validation' => $entityValidation,
'term_usage' => $termUsage,
];
}
/**
* Get chunks that have no taxonomy mapping.
*
* @return array<array{id: int, document_id: int, content: string}>
*/
public function getUnmappedChunks(int $limit = 100): array
{
return $this->chunkTaxonomyRepository->getUnmappedChunks($limit);
}
/**
* Get entity mappings that need validation.
*
* @return array<\Domain\Entity\EntityTaxonomyMapping>
*/
public function getUnvalidatedEntityMappings(int $limit = 100): array
{
return $this->entityTaxonomyRepository->getUnvalidatedMappings($limit);
}
/**
* Get usage statistics for a specific taxonomy term.
*
* @return array{
* term: array|null,
* chunk_count: int,
* entity_count: int,
* chunks: array<array{chunk_id: int, confidence: float, source: string}>,
* entities: array<array{entity_id: int, relevance: float, validated: bool}>
* }
*/
public function getTaxonomyTermUsage(int $termId): array
{
$term = $this->taxonomyRepository->find($termId);
$chunks = $this->chunkTaxonomyRepository->findByTaxonomyTermId($termId);
$entities = $this->entityTaxonomyRepository->findByTaxonomyTermId($termId);
return [
'term' => $term,
'chunk_count' => count($chunks),
'entity_count' => count($entities),
'chunks' => $chunks,
'entities' => $entities,
];
}
/**
* Get all taxonomy terms with their usage counts.
*
* @return array<array{id: int, name: string, path: string, chunk_count: int, entity_count: int}>
*/
public function getTermsWithUsage(): array
{
$terms = $this->taxonomyRepository->findAll();
$chunkCounts = $this->chunkTaxonomyRepository->countByTaxonomyTerm();
$result = [];
foreach ($terms as $term) {
$termId = $term['id'];
$entityMappings = $this->entityTaxonomyRepository->findByTaxonomyTermId($termId);
$result[] = [
'id' => $termId,
'name' => $term['name'],
'path' => $term['path'],
'chunk_count' => $chunkCounts[$termId] ?? 0,
'entity_count' => count($entityMappings),
];
}
return $result;
}
/**
* Calculate chunk coverage statistics.
*
* @return array{total: int, mapped: int, percentage: float}
*/
private function calculateChunkCoverage(): array
{
$taxonomyStats = $this->taxonomyRepository->getStats();
$mappedChunks = $taxonomyStats['tagged_chunks'];
// Get total chunks from unmapped query (limit 0 would give us count)
// For efficiency, we estimate based on the stats
$unmappedSample = $this->chunkTaxonomyRepository->getUnmappedChunks(1);
$hasUnmapped = count($unmappedSample) > 0;
// Use a heuristic: if there are unmapped chunks, estimate total
// In production, this would be a dedicated count query
$total = $hasUnmapped ? max($mappedChunks + 1, $mappedChunks) : $mappedChunks;
$percentage = $total > 0 ? round(($mappedChunks / $total) * 100, 2) : 100.0;
return [
'total' => $total,
'mapped' => $mappedChunks,
'percentage' => $percentage,
];
}
}
Vollständig herunterladen
Aktionen
Andere Versionen dieser Datei
| ID |
Version |
Typ |
Größe |
Datum |
| 1820 |
7 |
modified |
4.9 KB |
2025-12-27 23:15 |
| 1819 |
6 |
modified |
4.9 KB |
2025-12-27 23:15 |
| 1818 |
5 |
modified |
4.9 KB |
2025-12-27 23:15 |
| 1817 |
4 |
modified |
4.8 KB |
2025-12-27 23:14 |
| 1522 |
3 |
modified |
4.8 KB |
2025-12-25 20:19 |
| 1517 |
2 |
modified |
4.8 KB |
2025-12-25 20:16 |
| 1516 |
1 |
modified |
4.9 KB |
2025-12-25 20:16 |
← Zurück zur Übersicht