use of eu.transkribus.core.model.beans.pagecontent_trp.TrpRegionType in project TranskribusCore by Transkribus.
the class PageXmlUtils method copyTextContent.
public static void copyTextContent(PcGtsType origPc, PcGtsType newPc) {
if (!hasRegions(origPc) || !hasRegions(newPc)) {
return;
}
List<TrpRegionType> origRegs = origPc.getPage().getTextRegionOrImageRegionOrLineDrawingRegion();
List<TrpRegionType> newRegs = newPc.getPage().getTextRegionOrImageRegionOrLineDrawingRegion();
// map the regions where we want to keep the textContent
Map<String, TextRegionType> textMap = new HashMap<>();
// iterate all old regions. Map the ones containing lines
for (RegionType r : origRegs) {
if (!(r instanceof TextRegionType)) {
continue;
}
TextRegionType tr = (TextRegionType) r;
boolean hasTextLines = tr.getTextLine() != null && !tr.getTextLine().isEmpty();
if (hasTextLines) {
textMap.put(tr.getId(), tr);
}
}
// iterate the new regions and move all the line contents from the old one
for (RegionType r : newRegs) {
if (!(r instanceof TextRegionType) || !textMap.containsKey(r.getId())) {
continue;
}
// this region corresponds with an old one
TextRegionType newTr = (TextRegionType) r;
TextRegionType oldTr = textMap.get(newTr.getId());
copyTextRegionContent(oldTr, newTr);
}
}
Aggregations