refactor(training): extract kurrentLabels helper + clarify query comments
Extract repeated `new java.util.HashSet<>(Set.of(TrainingLabel.KURRENT_RECOGNITION))` into a `kurrentLabels()` helper in TrainingBlockQueryTest and add `import java.util.HashSet`. Add clarifying comments on the two person-scoped queries in TranscriptionBlockRepository explaining that they use `MEMBER OF d.trainingLabels` — aligned with the pre-existing `findEligibleKurrentBlocks()` pattern. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -60,6 +60,8 @@ public interface TranscriptionBlockRepository extends JpaRepository<Transcriptio
|
|||||||
""")
|
""")
|
||||||
List<TranscriptionBlock> findSegmentationBlocks();
|
List<TranscriptionBlock> findSegmentationBlocks();
|
||||||
|
|
||||||
|
// Uses 'KURRENT_RECOGNITION' MEMBER OF d.trainingLabels — aligned with findEligibleKurrentBlocks()
|
||||||
|
// which already used this form (changed from d.scriptType = 'KURRENT' in the original queries).
|
||||||
@Query("""
|
@Query("""
|
||||||
SELECT COUNT(b) FROM TranscriptionBlock b
|
SELECT COUNT(b) FROM TranscriptionBlock b
|
||||||
JOIN Document d ON d.id = b.documentId
|
JOIN Document d ON d.id = b.documentId
|
||||||
@@ -69,6 +71,8 @@ public interface TranscriptionBlockRepository extends JpaRepository<Transcriptio
|
|||||||
""")
|
""")
|
||||||
long countManualKurrentBlocksByPerson(@Param("personId") UUID personId);
|
long countManualKurrentBlocksByPerson(@Param("personId") UUID personId);
|
||||||
|
|
||||||
|
// Uses 'KURRENT_RECOGNITION' MEMBER OF d.trainingLabels — aligned with findEligibleKurrentBlocks()
|
||||||
|
// which already used this form (changed from d.scriptType = 'KURRENT' in the original queries).
|
||||||
@Query("""
|
@Query("""
|
||||||
SELECT b FROM TranscriptionBlock b
|
SELECT b FROM TranscriptionBlock b
|
||||||
JOIN Document d ON d.id = b.documentId
|
JOIN Document d ON d.id = b.documentId
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.raddatz.familienarchiv.PostgresContainerConfig;
|
import org.raddatz.familienarchiv.PostgresContainerConfig;
|
||||||
import org.raddatz.familienarchiv.config.FlywayConfig;
|
import org.raddatz.familienarchiv.config.FlywayConfig;
|
||||||
import org.raddatz.familienarchiv.model.*;
|
import org.raddatz.familienarchiv.model.*;
|
||||||
import java.util.Set;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.jdbc.test.autoconfigure.AutoConfigureTestDatabase;
|
import org.springframework.boot.jdbc.test.autoconfigure.AutoConfigureTestDatabase;
|
||||||
import org.springframework.boot.data.jpa.test.autoconfigure.DataJpaTest;
|
import org.springframework.boot.data.jpa.test.autoconfigure.DataJpaTest;
|
||||||
@@ -13,6 +12,7 @@ import org.springframework.context.annotation.Import;
|
|||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
@@ -38,7 +38,7 @@ class TrainingBlockQueryTest {
|
|||||||
.title("Kurrent Brief")
|
.title("Kurrent Brief")
|
||||||
.originalFilename("kurrent.pdf")
|
.originalFilename("kurrent.pdf")
|
||||||
.status(DocumentStatus.UPLOADED)
|
.status(DocumentStatus.UPLOADED)
|
||||||
.trainingLabels(new HashSet<>(Set.of(TrainingLabel.KURRENT_RECOGNITION)))
|
.trainingLabels(kurrentLabels())
|
||||||
.build());
|
.build());
|
||||||
kurrentDocId = kurrentDoc.getId();
|
kurrentDocId = kurrentDoc.getId();
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ class TrainingBlockQueryTest {
|
|||||||
.originalFilename("karl.pdf")
|
.originalFilename("karl.pdf")
|
||||||
.status(DocumentStatus.UPLOADED)
|
.status(DocumentStatus.UPLOADED)
|
||||||
.sender(sender)
|
.sender(sender)
|
||||||
.trainingLabels(new HashSet<>(Set.of(TrainingLabel.KURRENT_RECOGNITION)))
|
.trainingLabels(kurrentLabels())
|
||||||
.build());
|
.build());
|
||||||
UUID annId = annotationRepository.save(annotation(doc.getId())).getId();
|
UUID annId = annotationRepository.save(annotation(doc.getId())).getId();
|
||||||
blockRepository.save(block(doc.getId(), annId, BlockSource.MANUAL, false));
|
blockRepository.save(block(doc.getId(), annId, BlockSource.MANUAL, false));
|
||||||
@@ -158,7 +158,7 @@ class TrainingBlockQueryTest {
|
|||||||
.originalFilename("karl.pdf")
|
.originalFilename("karl.pdf")
|
||||||
.status(DocumentStatus.UPLOADED)
|
.status(DocumentStatus.UPLOADED)
|
||||||
.sender(sender)
|
.sender(sender)
|
||||||
.trainingLabels(new HashSet<>(Set.of(TrainingLabel.KURRENT_RECOGNITION)))
|
.trainingLabels(kurrentLabels())
|
||||||
.build());
|
.build());
|
||||||
UUID annId = annotationRepository.save(annotation(doc.getId())).getId();
|
UUID annId = annotationRepository.save(annotation(doc.getId())).getId();
|
||||||
blockRepository.save(block(doc.getId(), annId, BlockSource.OCR, false));
|
blockRepository.save(block(doc.getId(), annId, BlockSource.OCR, false));
|
||||||
@@ -177,7 +177,7 @@ class TrainingBlockQueryTest {
|
|||||||
.originalFilename("karl.pdf")
|
.originalFilename("karl.pdf")
|
||||||
.status(DocumentStatus.UPLOADED)
|
.status(DocumentStatus.UPLOADED)
|
||||||
.sender(karl)
|
.sender(karl)
|
||||||
.trainingLabels(new HashSet<>(Set.of(TrainingLabel.KURRENT_RECOGNITION)))
|
.trainingLabels(kurrentLabels())
|
||||||
.build());
|
.build());
|
||||||
UUID annId = annotationRepository.save(annotation(doc.getId())).getId();
|
UUID annId = annotationRepository.save(annotation(doc.getId())).getId();
|
||||||
blockRepository.save(block(doc.getId(), annId, BlockSource.MANUAL, false));
|
blockRepository.save(block(doc.getId(), annId, BlockSource.MANUAL, false));
|
||||||
@@ -195,7 +195,7 @@ class TrainingBlockQueryTest {
|
|||||||
.originalFilename("karl.pdf")
|
.originalFilename("karl.pdf")
|
||||||
.status(DocumentStatus.UPLOADED)
|
.status(DocumentStatus.UPLOADED)
|
||||||
.sender(sender)
|
.sender(sender)
|
||||||
.trainingLabels(new HashSet<>(Set.of(TrainingLabel.KURRENT_RECOGNITION)))
|
.trainingLabels(kurrentLabels())
|
||||||
.build());
|
.build());
|
||||||
UUID annId = annotationRepository.save(annotation(doc.getId())).getId();
|
UUID annId = annotationRepository.save(annotation(doc.getId())).getId();
|
||||||
blockRepository.save(block(doc.getId(), annId, BlockSource.MANUAL, false));
|
blockRepository.save(block(doc.getId(), annId, BlockSource.MANUAL, false));
|
||||||
@@ -218,6 +218,10 @@ class TrainingBlockQueryTest {
|
|||||||
|
|
||||||
// ─── helpers ─────────────────────────────────────────────────────────────
|
// ─── helpers ─────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
private static Set<TrainingLabel> kurrentLabels() {
|
||||||
|
return new HashSet<>(Set.of(TrainingLabel.KURRENT_RECOGNITION));
|
||||||
|
}
|
||||||
|
|
||||||
private DocumentAnnotation annotation(UUID docId) {
|
private DocumentAnnotation annotation(UUID docId) {
|
||||||
return DocumentAnnotation.builder()
|
return DocumentAnnotation.builder()
|
||||||
.documentId(docId)
|
.documentId(docId)
|
||||||
|
|||||||
Reference in New Issue
Block a user