Search in sources :

Example 1 with TextEquivType

use of eu.transkribus.core.model.beans.pagecontent.TextEquivType in project TranskribusCore by Transkribus.

the class TrpShapeTypeUtils method setUnicodeText.

public static void setUnicodeText(ITrpShapeType shape, String unicode, Object who) {
    logger.trace("setting unicode text in " + shape.getName() + ", id: " + shape.getId() + ", text: " + unicode);
    int lBefore = shape.getUnicodeText().length();
    TextEquivType te = new TextEquivType();
    te.setUnicode(unicode);
    shape.setTextEquiv(te);
    shape.getCustomTagList().onTextEdited(0, lBefore, unicode);
    shape.getObservable().setChangedAndNotifyObservers(new TrpTextChangedEvent(who, 0, lBefore, unicode));
}
Also used : TextEquivType(eu.transkribus.core.model.beans.pagecontent.TextEquivType) TrpTextChangedEvent(eu.transkribus.core.model.beans.pagecontent_trp.observable.TrpObserveEvent.TrpTextChangedEvent)

Example 2 with TextEquivType

use of eu.transkribus.core.model.beans.pagecontent.TextEquivType in project TranskribusCore by Transkribus.

the class TrpShapeTypeUtils method editUnicodeText.

public static void editUnicodeText(ITrpShapeType shape, int start, int end, String replacement, Object who) {
    logger.trace("editing unicode text in " + shape.getName() + ", id: " + shape.getId() + ", start/end: " + start + "/" + end + ", text: " + replacement);
    StringBuilder sb = new StringBuilder(shape.getUnicodeText());
    sb.replace(start, end, replacement);
    String unicode = sb.toString();
    if (shape instanceof TrpWordType && unicode.equals(TrpWordType.EMPTY_WORD_FILL)) {
        unicode = "";
        replacement = "";
    }
    TextEquivType te = new TextEquivType();
    te.setUnicode(unicode);
    shape.setTextEquiv(te);
    SebisStopWatch.SW.start();
    shape.getCustomTagList().onTextEdited(start, end, replacement);
    SebisStopWatch.SW.stop(true, "onTextEdited: ", logger);
    shape.getObservable().setChangedAndNotifyObservers(new TrpTextChangedEvent(who, start, end, replacement));
}
Also used : TextEquivType(eu.transkribus.core.model.beans.pagecontent.TextEquivType) TrpTextChangedEvent(eu.transkribus.core.model.beans.pagecontent_trp.observable.TrpObserveEvent.TrpTextChangedEvent)

Example 3 with TextEquivType

use of eu.transkribus.core.model.beans.pagecontent.TextEquivType in project TranskribusCore by Transkribus.

the class KlosterTeiToPageParser method parsePage.

static void parsePage(Node pbNode, boolean save) throws IOException, JAXBException {
    Element pb = (Element) pbNode;
    String imgFn = pb.getAttribute("facs");
    int pageN = Integer.parseInt(pb.getAttribute("n"));
    int pageHeight = Integer.parseInt(pb.getAttribute("xmlns:h"));
    int pageWidth = Integer.parseInt(pb.getAttribute("xmlns:w"));
    PcGtsType page = PageXmlUtils.createEmptyPcGtsType("imgfn", pageWidth, pageHeight);
    TrpTextRegionType region = new TrpTextRegionType();
    region.setId("region_1");
    System.out.println("page data: imgFn = " + imgFn + " n = " + pageN + " pageWidth = " + pageWidth + " pageHeight = " + pageHeight);
    int minX = 999999, minY = 999999, maxX = -1, maxY = -1;
    Node sibling = pbNode.getNextSibling();
    int lineCount = 0;
    while (sibling != null) {
        if (sibling.getNodeName().equals("pb")) {
            break;
        }
        // System.out.println("sibling type: "+sibling.getTextContent());
        if (sibling.getNodeType() == Node.ELEMENT_NODE && sibling.getNodeName().equals("lb")) {
            Element lb = (Element) sibling;
            int n = Integer.parseInt(lb.getAttribute("n"));
            int x = Integer.parseInt(lb.getAttribute("xmlns:x"));
            int y = Integer.parseInt(lb.getAttribute("xmlns:y"));
            int w = Integer.parseInt(lb.getAttribute("xmlns:w"));
            int h = Integer.parseInt(lb.getAttribute("xmlns:h"));
            if (x < minX)
                minX = x;
            if (y < minY)
                minY = y;
            if (x + w > maxX)
                maxX = x + w;
            if (y + h > maxY)
                maxY = y + h;
            String txt = sibling.getNextSibling().getTextContent();
            txt = StringUtils.stripEnd(txt, " \r\n");
            // System.out.println("line: txt = "+txt+" [x,y,w,h] = ["+x+","+y+","+w+","+h+"]");
            System.out.format("line: n = %d, txt = %s, coords = [%d,%d,%d,%d]\n", n, txt, x, y, w, h);
            TrpTextLineType line = new TrpTextLineType();
            line.setCoords(bbToCoords(x, y, w, h));
            TextEquivType te = new TextEquivType();
            te.setUnicode(txt);
            line.setTextEquiv(te);
            line.setId("line_" + (++lineCount));
            // create baseline:
            TrpBaselineType bl = new TrpBaselineType();
            int yBl = (int) (y + 0.7 * h);
            bl.setPoints(x + "," + yBl + " " + (x + w) + "," + yBl);
            line.setBaseline(bl);
            region.getTextLine().add(line);
        }
        sibling = sibling.getNextSibling();
    // System.out.println("sibling node name: "+sibling.getNodeName());
    // if (!sibling.getNodeName().equals("lb"))
    // break;
    }
    if (!region.getTextLine().isEmpty()) {
        region.setCoords(bbToCoords(minX, minY, maxX - minX, maxY - minY));
    } else {
        region.setCoords(bbToCoords(0, 0, pageWidth, pageHeight));
    }
    page.getPage().getTextRegionOrImageRegionOrLineDrawingRegion().add(region);
    if (save && !region.getTextLine().isEmpty()) {
        File xmlFile = new File(PAGE_DIR + FilenameUtils.getBaseName(imgFn) + ".xml");
        PageXmlUtils.marshalToFile(page, xmlFile);
        FileUtils.copyFile(new File(DIR + imgFn), new File(DST_DIR + imgFn));
        System.out.println("written page to: " + xmlFile.getAbsolutePath());
    }
}
Also used : TrpTextLineType(eu.transkribus.core.model.beans.pagecontent_trp.TrpTextLineType) TrpBaselineType(eu.transkribus.core.model.beans.pagecontent_trp.TrpBaselineType) TextEquivType(eu.transkribus.core.model.beans.pagecontent.TextEquivType) TrpTextRegionType(eu.transkribus.core.model.beans.pagecontent_trp.TrpTextRegionType) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) PcGtsType(eu.transkribus.core.model.beans.pagecontent.PcGtsType) File(java.io.File)

Example 4 with TextEquivType

use of eu.transkribus.core.model.beans.pagecontent.TextEquivType in project TranskribusCore by Transkribus.

the class PageXmlUtils method setTextToLine.

public static void setTextToLine(String text, PcGtsType pc, String lineId) {
    TextLineType tl = findLineById(pc, lineId);
    if (tl == null) {
        logger.info("Line does not exist: " + lineId);
        return;
    }
    logger.debug("Setting text in line=" + lineId + ": " + text);
    if (tl.getTextEquiv() == null) {
        logger.debug("Creating new TextEquiv element.");
        TextEquivType textEquiv = new TextEquivType();
        textEquiv.setUnicode(text);
        tl.setTextEquiv(textEquiv);
    } else {
        logger.debug("Setting text in existing TextEquiv element.");
        tl.getTextEquiv().setUnicode(text);
    }
}
Also used : TextEquivType(eu.transkribus.core.model.beans.pagecontent.TextEquivType) TextLineType(eu.transkribus.core.model.beans.pagecontent.TextLineType) TrpTextLineType(eu.transkribus.core.model.beans.pagecontent_trp.TrpTextLineType)

Example 5 with TextEquivType

use of eu.transkribus.core.model.beans.pagecontent.TextEquivType in project TranskribusCore by Transkribus.

the class BeanCopyUtils method copyTextEquivType.

// public static CellCoordsType copyCellCoordsType(CellCoordsType coords) {
// if (coords == null)
// return null;
// 
// CellCoordsType copy = new CellCoordsType();
// copy.setPoints(coords.getPoints());
// copy.setCornerPts(coords.getCornerPts());
// 
// return copy;
// }
public static TextEquivType copyTextEquivType(TextEquivType text) {
    if (text == null)
        return null;
    TextEquivType copy = new TextEquivType();
    copy.setConf(text.getConf());
    copy.setPlainText(text.getPlainText());
    copy.setUnicode(text.getUnicode());
    return copy;
}
Also used : TextEquivType(eu.transkribus.core.model.beans.pagecontent.TextEquivType)

Aggregations

TextEquivType (eu.transkribus.core.model.beans.pagecontent.TextEquivType)5 TrpTextLineType (eu.transkribus.core.model.beans.pagecontent_trp.TrpTextLineType)2 TrpTextChangedEvent (eu.transkribus.core.model.beans.pagecontent_trp.observable.TrpObserveEvent.TrpTextChangedEvent)2 PcGtsType (eu.transkribus.core.model.beans.pagecontent.PcGtsType)1 TextLineType (eu.transkribus.core.model.beans.pagecontent.TextLineType)1 TrpBaselineType (eu.transkribus.core.model.beans.pagecontent_trp.TrpBaselineType)1 TrpTextRegionType (eu.transkribus.core.model.beans.pagecontent_trp.TrpTextRegionType)1 File (java.io.File)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1