fix(ocr): fill empty MANUAL blocks in guided OCR mode
When a user draws annotation boxes to mark OCR regions, the blocks are created with source=MANUAL and empty text. upsertGuidedBlock was protecting all MANUAL blocks unconditionally, so guided OCR silently produced no output for these drawn-but-empty blocks. Changed the guard to only protect non-empty MANUAL blocks — empty ones are treated like OCR blocks and get their text filled in. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -104,8 +104,8 @@ public class TranscriptionService {
|
|||||||
public TranscriptionBlock upsertGuidedBlock(UUID documentId, UUID annotationId,
|
public TranscriptionBlock upsertGuidedBlock(UUID documentId, UUID annotationId,
|
||||||
String text, UUID userId) {
|
String text, UUID userId) {
|
||||||
return blockRepository.findByAnnotationId(annotationId).map(existing -> {
|
return blockRepository.findByAnnotationId(annotationId).map(existing -> {
|
||||||
if (existing.getSource() == BlockSource.MANUAL) {
|
if (existing.getSource() == BlockSource.MANUAL && !existing.getText().isBlank()) {
|
||||||
return existing; // never overwrite manual transcription
|
return existing; // never overwrite non-empty manual transcription
|
||||||
}
|
}
|
||||||
existing.setText(sanitizeText(text));
|
existing.setText(sanitizeText(text));
|
||||||
existing.setUpdatedBy(userId);
|
existing.setUpdatedBy(userId);
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ class TranscriptionServiceGuidedTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void upsertGuidedBlock_doesNotOverwriteManualBlock() {
|
void upsertGuidedBlock_doesNotOverwriteNonEmptyManualBlock() {
|
||||||
TranscriptionBlock manual = TranscriptionBlock.builder()
|
TranscriptionBlock manual = TranscriptionBlock.builder()
|
||||||
.id(UUID.randomUUID())
|
.id(UUID.randomUUID())
|
||||||
.annotationId(annId)
|
.annotationId(annId)
|
||||||
@@ -90,4 +90,22 @@ class TranscriptionServiceGuidedTest {
|
|||||||
assertThat(result.getText()).isEqualTo("manually written");
|
assertThat(result.getText()).isEqualTo("manually written");
|
||||||
verify(blockRepository, never()).save(any());
|
verify(blockRepository, never()).save(any());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void upsertGuidedBlock_fillsEmptyManualBlock_withOcrText() {
|
||||||
|
TranscriptionBlock emptyManual = TranscriptionBlock.builder()
|
||||||
|
.id(UUID.randomUUID())
|
||||||
|
.annotationId(annId)
|
||||||
|
.documentId(docId)
|
||||||
|
.text("")
|
||||||
|
.source(BlockSource.MANUAL)
|
||||||
|
.sortOrder(0)
|
||||||
|
.build();
|
||||||
|
when(blockRepository.findByAnnotationId(annId)).thenReturn(Optional.of(emptyManual));
|
||||||
|
|
||||||
|
TranscriptionBlock result = service.upsertGuidedBlock(docId, annId, "ocr result", userId);
|
||||||
|
|
||||||
|
assertThat(result.getText()).isEqualTo("ocr result");
|
||||||
|
verify(blockRepository).save(any());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user