GetTaxonomyOverviewUseCase.php
- Pfad:
src/UseCases/Taxonomy/GetTaxonomyOverviewUseCase.php
- Namespace: UseCases\Taxonomy
- Zeilen: 149 | Größe: 5,037 Bytes
- Geändert: 2025-12-27 23:15:26 | Gescannt: 2025-12-31 10:22:15
Code Hygiene Score: 99
- Dependencies: 100 (25%)
- LOC: 100 (20%)
- Methods: 100 (20%)
- Secrets: 100 (15%)
- Classes: 100 (10%)
- Magic Numbers: 90 (10%)
Issues 1
| Zeile |
Typ |
Beschreibung |
| 140 |
magic_number |
Magic Number gefunden: 100 |
Dependencies 7
- constructor Domain\Repository\ChunkTaxonomyRepositoryInterface
- constructor Domain\Repository\EntityTaxonomyRepositoryInterface
- constructor Domain\Repository\TaxonomyRepositoryInterface
- use Domain\Constants
- use Domain\Repository\ChunkTaxonomyRepositoryInterface
- use Domain\Repository\EntityTaxonomyRepositoryInterface
- use Domain\Repository\TaxonomyRepositoryInterface
Klassen 1
-
GetTaxonomyOverviewUseCase
class
Zeile 14
Funktionen 7
-
__construct()
public
Zeile 16
-
execute()
public
Zeile 33
-
getUnmappedChunks()
public
Zeile 53
-
getUnvalidatedEntityMappings()
public
Zeile 63
-
getTaxonomyTermUsage()
public
Zeile 79
-
getTermsWithUsage()
public
Zeile 99
-
calculateChunkCoverage()
private
Zeile 126
Versionen 7
-
v7
2025-12-27 23:15 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v6
2025-12-27 23:15 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v5
2025-12-27 23:15 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v4
2025-12-27 23:14 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v3
2025-12-25 20:19 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v2
2025-12-25 20:16 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v1
2025-12-25 20:16 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
Code
<?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 = Constants::DEFAULT_LIMIT): array
{
return $this->chunkTaxonomyRepository->getUnmappedChunks($limit);
}
/**
* Get entity mappings that need validation.
*
* @return array<\Domain\Entity\EntityTaxonomyMapping>
*/
public function getUnvalidatedEntityMappings(int $limit = Constants::DEFAULT_LIMIT): 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) * Constants::PERCENT_FULL, 2) : 100.0;
return [
'total' => $total,
'mapped' => $mappedChunks,
'percentage' => $percentage,
];
}
}