ChunkAnalysisService.php
- Pfad:
src/Infrastructure/Docs/ChunkAnalysisService.php - Namespace: Infrastructure\Docs
- Zeilen: 119 | Größe: 3,601 Bytes
- Geändert: 2025-12-27 23:48:35 | Gescannt: 2025-12-31 10:22:15
Code Hygiene Score: 100
- Dependencies: 100 (25%)
- LOC: 100 (20%)
- Methods: 100 (20%)
- Secrets: 100 (15%)
- Classes: 100 (10%)
- Magic Numbers: 100 (10%)
Keine Issues gefunden.
Dependencies 5
- implements Infrastructure\Docs\ChunkProcessorInterface
- constructor Infrastructure\Docs\ChunkDataRepository
- constructor Infrastructure\Docs\ChunkAnalyzer
- use Domain\Constants
- use RuntimeException
Klassen 1
-
ChunkAnalysisServiceclass Zeile 12
Funktionen 6
-
__construct()public Zeile 17 -
analyzeChunk()public Zeile 28 -
process()public Zeile 38 -
analyzeAllPending()Zeile 72 -
processBatch()Zeile 82 -
getStats()Zeile 114
Verwendet von 2
- Doc2VectorPipeline.php constructor
- InfrastructureServiceProvider.php use
Versionen 19
-
v19
2025-12-27 23:48 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v18
2025-12-27 23:47 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v17
2025-12-25 17:28 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v16
2025-12-25 17:00 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v15
2025-12-25 16:59 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v14
2025-12-25 16:59 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v13
2025-12-25 16:58 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v12
2025-12-25 16:58 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v11
2025-12-25 16:58 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v10
2025-12-23 08:46 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v9
2025-12-23 08:46 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v8
2025-12-23 08:05 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v7
2025-12-22 08:49 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v6
2025-12-22 08:49 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v5
2025-12-22 08:08 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v4
2025-12-22 08:08 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v3
2025-12-22 08:08 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v2
2025-12-20 17:23 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v1
2025-12-20 17:18 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
Code
<?php
declare(strict_types=1);
namespace Infrastructure\Docs;
// @responsibility: Orchestriert Chunk-Analyse (koordiniert ChunkAnalyzer + ChunkRepository)
use Domain\Constants;
use RuntimeException;
final class ChunkAnalysisService implements ChunkProcessorInterface
{
private const string TAXONOMY_MODEL = 'gemma3:4b-it-qat';
private const int BATCH_SIZE = 10;
public function __construct(
private ChunkDataRepository $repository,
private ChunkAnalyzer $analyzer
) {
}
/**
* Analyzes a single chunk.
*
* @return array{taxonomy: array<string>, entities: array<array{name: string, type: string}>, keywords: array<string>}
*/
public function analyzeChunk(int $chunkId): array
{
return $this->process($chunkId);
}
/**
* Processes a single chunk (implements ChunkProcessorInterface).
*
* @return array{taxonomy: array<string>, entities: array<array{name: string, type: string}>, keywords: array<string>}
*/
public function process(int $chunkId): array
{
$chunk = $this->repository->findById($chunkId);
if ($chunk === null) {
throw new RuntimeException("Chunk #{$chunkId} not found");
}
// Mark as processing
$this->repository->updateStatus($chunkId, 'processing');
try {
// Get document context
$docContext = $this->repository->getDocumentContext((int) $chunk['dokumentation_id']);
// Perform analysis via ChunkAnalyzer
$analysis = $this->analyzer->analyze($chunk, $docContext);
// Store results
$this->repository->storeAnalysisResults($chunkId, $analysis, self::TAXONOMY_MODEL);
return $analysis;
} catch (RuntimeException $e) {
$this->repository->updateStatus($chunkId, 'failed', $e->getMessage());
throw $e;
}
}
/**
* Analyzes all pending chunks in batches.
*
* @return array{processed: int, failed: int, errors: array<string>}
*/
public function analyzeAllPending(int $limit = Constants::DEFAULT_LIMIT): array
{
return $this->processBatch($limit);
}
/**
* Processes multiple chunks in batch (implements ChunkProcessorInterface).
*
* @return array{processed: int, failed: int, errors: array<string>}
*/
public function processBatch(int $limit): array
{
$results = ['processed' => 0, 'failed' => 0, 'errors' => []];
$chunks = $this->repository->findPending($limit);
foreach ($chunks as $chunk) {
try {
$this->process((int) $chunk['id']);
$results['processed']++;
// Progress output
if ($results['processed'] % self::BATCH_SIZE === 0) {
echo "Analyzed {$results['processed']} chunks...\n";
}
} catch (RuntimeException $e) {
$results['failed']++;
$results['errors'][] = "Chunk #{$chunk['id']}: " . $e->getMessage();
}
}
// Return with legacy key 'analyzed' for backward compatibility
$results['analyzed'] = $results['processed'];
return $results;
}
/**
* Gets analysis statistics (implements ChunkProcessorInterface).
*
* @return array{pending: int, processing: int, completed: int, failed: int, by_category: array<array{category: string, count: int}>}
*/
public function getStats(): array
{
return $this->repository->getStats();
}
}