Merge branch 'RED-7384' into 'main'

Red 7384

See merge request fforesight/layout-parser!140
This commit is contained in:
Kilian Schüttler 2024-04-23 12:13:21 +02:00
commit d38d023485
3 changed files with 15 additions and 15 deletions

View File

@ -13,7 +13,6 @@ import com.knecon.fforesight.service.layoutparser.internal.api.data.redaction.No
import com.knecon.fforesight.service.layoutparser.processor.model.graph.DocumentTree; import com.knecon.fforesight.service.layoutparser.processor.model.graph.DocumentTree;
import com.knecon.fforesight.service.layoutparser.processor.model.graph.entity.RedactionEntity; import com.knecon.fforesight.service.layoutparser.processor.model.graph.entity.RedactionEntity;
import com.knecon.fforesight.service.layoutparser.processor.model.graph.textblock.TextBlock; import com.knecon.fforesight.service.layoutparser.processor.model.graph.textblock.TextBlock;
import com.knecon.fforesight.service.layoutparser.processor.model.graph.textblock.TextBlockCollector;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@ -40,6 +39,8 @@ public class Image implements GenericSemanticNode {
boolean transparent; boolean transparent;
Rectangle2D position; Rectangle2D position;
TextBlock leafTextBlock;
boolean redaction; boolean redaction;
boolean ignored; boolean ignored;
@Builder.Default @Builder.Default
@ -70,9 +71,7 @@ public class Image implements GenericSemanticNode {
@Override @Override
public TextBlock getTextBlock() { public TextBlock getTextBlock() {
return streamAllSubNodes().filter(SemanticNode::isLeaf) return leafTextBlock;
.map(SemanticNode::getLeafTextBlock)
.collect(new TextBlockCollector());
} }
@ -98,4 +97,11 @@ public class Image implements GenericSemanticNode {
return bBoxPerPage; return bBoxPerPage;
} }
@Override
public boolean isLeaf() {
return true;
}
} }

View File

@ -117,19 +117,12 @@ public class DocumentGraphFactory {
} }
public void addImage(Section section, ClassifiedImage image, Context context) { public void addImage(GenericSemanticNode parent, ClassifiedImage image, Context context) {
Image imageNode = createImage(image, context); Image imageNode = createImage(image, context);
List<Integer> treeId = context.getDocumentTree().createNewChildEntryAndReturnId(section, imageNode); List<Integer> treeId = context.getDocumentTree().createNewChildEntryAndReturnId(parent, imageNode);
imageNode.setTreeId(treeId);
}
public void addImage(Document document, ClassifiedImage image, Context context) {
Image imageNode = createImage(image, context);
List<Integer> treeId = context.getDocumentTree().createNewChildEntryAndReturnId(document, imageNode);
imageNode.setTreeId(treeId); imageNode.setTreeId(treeId);
imageNode.setLeafTextBlock(context.textBlockFactory.emptyTextBlock(parent, context, context.getPage(image.getPage())));
} }

View File

@ -17,6 +17,7 @@ import java.util.stream.Collectors;
import org.apache.pdfbox.Loader; import org.apache.pdfbox.Loader;
import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.pdfwriter.compress.CompressParameters;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentCatalog; import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPage;
@ -285,7 +286,7 @@ public class ViewerDocumentService {
Observation.createNotStarted("ViewerDocumentService", registry).contextualName("incremental-save").observe(() -> { Observation.createNotStarted("ViewerDocumentService", registry).contextualName("incremental-save").observe(() -> {
try (var out = new FileOutputStream(outputFile)) { try (var out = new FileOutputStream(outputFile)) {
pdDocument.save(out); pdDocument.save(out, CompressParameters.NO_COMPRESSION);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }