RED-9139: move document to its own module, add TableOfContents and TableOfContentsItem

* update LayoutEngine package
This commit is contained in:
Kilian Schuettler 2024-11-14 13:53:33 +01:00
parent 6ae777c802
commit f8a97f306e
6 changed files with 29 additions and 18 deletions

View File

@ -92,10 +92,7 @@ public class DocumentStructureWrapper implements Serializable {
public Stream<EntryData> streamAllEntries() {
return Stream.concat(Stream.of(documentStructure.getRoot()),
documentStructure.getRoot().getChildrenList()
.stream())
.flatMap(DocumentStructureWrapper::flatten);
return flatten(documentStructure.getRoot());
}

View File

@ -7,7 +7,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import com.iqser.red.service.redaction.v1.server.data.DocumentData;
import com.iqser.red.service.redaction.v1.server.data.DocumentPageProto.AllDocumentPages;
@ -59,10 +58,6 @@ public class DocumentDataMapper {
AllDocumentPositionData allDocumentPositionData = AllDocumentPositionData.newBuilder().addAllDocumentPositionData(atomicPositionBlockData).build();
Set<Long> nonEmptyTextBlocks = documentTextData.stream()
.mapToLong(DocumentTextData::getId).boxed()
.collect(Collectors.toSet());
List<DocumentPage> documentPageData = document.getPages()
.stream()
.map(DocumentDataMapper::toPageData)

View File

@ -24,7 +24,7 @@ public class PropertiesMapper {
public static Map<String, String> buildImageProperties(Image image) {
Map<String, String> properties = new HashMap<>();
properties.put(DocumentStructureWrapper.ImageProperties.IMAGE_TYPE, image.getImageType().toString());
properties.put(DocumentStructureWrapper.ImageProperties.IMAGE_TYPE, image.getImageType().name());
properties.put(DocumentStructureWrapper.ImageProperties.TRANSPARENT, String.valueOf(image.isTransparent()));
properties.put(DocumentStructureWrapper.ImageProperties.POSITION, toString(image.getPosition()));
properties.put(DocumentStructureWrapper.ImageProperties.ID, image.getId());
@ -118,13 +118,11 @@ public class PropertiesMapper {
private static ImageType parseImageType(String imageType) {
return switch (imageType) {
case "LOGO" -> ImageType.LOGO;
case "FORMULA" -> ImageType.FORMULA;
case "SIGNATURE" -> ImageType.SIGNATURE;
case "OCR" -> ImageType.OCR;
default -> ImageType.OTHER;
};
try {
return ImageType.valueOf(imageType.toUpperCase(Locale.ROOT));
} catch (IllegalArgumentException e) {
return ImageType.OTHER;
}
}

View File

@ -111,7 +111,7 @@ public class Image extends AbstractSemanticNode implements IEntity {
@Override
public String toString() {
return getTreeId() + ": " + getValue() + " " + position;
return getTreeId() + ": " + getValue() + " [%.2f,%.2f,%.2f,%.2f]".formatted(position.getX(), position.getY(), position.getWidth(), position.getHeight());
}
@ -169,4 +169,11 @@ public class Image extends AbstractSemanticNode implements IEntity {
visitor.visit(this);
}
@Override
public boolean isLeaf() {
return true;
}
}

View File

@ -37,4 +37,11 @@ public class TableOfContents extends AbstractSemanticNode {
visitor.visit(this);
}
@Override
public String toString() {
return getTreeId() + ": " + NodeType.TABLE_OF_CONTENTS_ITEM + ": " + getTextBlock().buildSummary();
}
}

View File

@ -47,4 +47,11 @@ public class TableOfContentsItem extends AbstractSemanticNode {
return leafTextBlock;
}
@Override
public String toString() {
return getTreeId() + ": " + NodeType.TABLE_OF_CONTENTS_ITEM + ": " + leafTextBlock.buildSummary();
}
}