Search in sources :

Example 16 with TrpRegionType

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);
    }
}
Also used : TrpTextRegionType(eu.transkribus.core.model.beans.pagecontent_trp.TrpTextRegionType) TextRegionType(eu.transkribus.core.model.beans.pagecontent.TextRegionType) TrpTextRegionType(eu.transkribus.core.model.beans.pagecontent_trp.TrpTextRegionType) TrpRegionType(eu.transkribus.core.model.beans.pagecontent_trp.TrpRegionType) RegionType(eu.transkribus.core.model.beans.pagecontent.RegionType) TextRegionType(eu.transkribus.core.model.beans.pagecontent.TextRegionType) TableRegionType(eu.transkribus.core.model.beans.pagecontent.TableRegionType) TrpRegionType(eu.transkribus.core.model.beans.pagecontent_trp.TrpRegionType) HashMap(java.util.HashMap)

Aggregations

TrpRegionType (eu.transkribus.core.model.beans.pagecontent_trp.TrpRegionType)16 RegionType (eu.transkribus.core.model.beans.pagecontent.RegionType)15 TrpTextRegionType (eu.transkribus.core.model.beans.pagecontent_trp.TrpTextRegionType)14 TextRegionType (eu.transkribus.core.model.beans.pagecontent.TextRegionType)13 TrpTableRegionType (eu.transkribus.core.model.beans.pagecontent_trp.TrpTableRegionType)8 TableRegionType (eu.transkribus.core.model.beans.pagecontent.TableRegionType)5 UnknownRegionType (eu.transkribus.core.model.beans.pagecontent.UnknownRegionType)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 TextLineType (eu.transkribus.core.model.beans.pagecontent.TextLineType)3 TrpTextLineType (eu.transkribus.core.model.beans.pagecontent_trp.TrpTextLineType)3 Point (java.awt.Point)3 Rectangle (java.awt.Rectangle)3 HashMap (java.util.HashMap)3 List (java.util.List)3 PdfContentByte (com.itextpdf.text.pdf.PdfContentByte)2 JAXBPageTranscript (eu.transkribus.core.model.beans.JAXBPageTranscript)2 TrpPage (eu.transkribus.core.model.beans.TrpPage)2 TrpTranscriptMetadata (eu.transkribus.core.model.beans.TrpTranscriptMetadata)2 PcGtsType (eu.transkribus.core.model.beans.pagecontent.PcGtsType)2