Search in sources :

Example 1 with CustomTagList

use of eu.transkribus.core.model.beans.customtags.CustomTagList in project TranskribusCore by Transkribus.

the class CustomTagListTest method testSimpleAddOrMergeTagWithTextStyles.

// @Ignore
@Test
public void testSimpleAddOrMergeTagWithTextStyles() {
    TrpTextLineType line = new TrpTextLineType(new TrpTextRegionType(new TrpPageType()));
    line.setUnicodeText("Hello world!", null);
    CustomTagList tl = new CustomTagList(line);
    TextStyleTag tst = new TextStyleTag(0, 10);
    tst.setFontFamily("testFont");
    tl.addOrMergeTag(tst, null);
    TextStyleTag ts1 = new TextStyleTag(2, 5);
    ts1.setBold(true);
    tl.addOrMergeTag(ts1, null);
    logger.trace(tl.toString());
    Assert.assertEquals("Nr of text styles must be 3!", 3, tl.getTags().size());
    TextStyleTag ts2 = new TextStyleTag(3, 4);
    ts2.setItalic(true);
    tl.addOrMergeTag(ts2, null);
    Assert.assertEquals("Nr of text styles must be 4!", 4, tl.getTags().size());
    logger.trace(tl.toString());
    // Assert.assertEquals("Nr of text styles must be 5!", 5, tl.getTags().size());
    Assert.assertTrue("offset = 0", tl.getTags().get(0).getOffset() == 0);
    CustomTag last = tl.getTags().get(tl.getTags().size() - 1);
    Assert.assertTrue("offset+length = 10", (last.getOffset() + last.getLength()) == 10);
}
Also used : TrpTextLineType(eu.transkribus.core.model.beans.pagecontent_trp.TrpTextLineType) TextStyleTag(eu.transkribus.core.model.beans.customtags.TextStyleTag) TrpTextRegionType(eu.transkribus.core.model.beans.pagecontent_trp.TrpTextRegionType) CustomTag(eu.transkribus.core.model.beans.customtags.CustomTag) CustomTagList(eu.transkribus.core.model.beans.customtags.CustomTagList) TrpPageType(eu.transkribus.core.model.beans.pagecontent_trp.TrpPageType) Test(org.junit.Test)

Example 2 with CustomTagList

use of eu.transkribus.core.model.beans.customtags.CustomTagList in project TranskribusCore by Transkribus.

the class TrpXlsxBuilder method writeTagsForShapeElement.

private static void writeTagsForShapeElement(ITrpShapeType element, String context, String doc, String page, String regionID, String lineID, String wordId, Set<String> selectedTags) throws IOException {
    String textStr = element.getUnicodeText();
    CustomTagList cl = element.getCustomTagList();
    if (textStr == null || cl == null)
        throw new IOException("Element has no text or custom tag list: " + element + ", class: " + element.getClass().getName());
    /*
		 * custom tags
		 * alle attribute auslesen und schreiben
		 * wenn 1. row: attribute keys schreiben und values schreiben
		 * wenn n. row: index von key in 1. row (=0) suchen und den value dort hineinschreiben
		 * 
		 */
    for (CustomTag nonIndexedTag : cl.getNonIndexedTags()) {
        if (!nonIndexedTag.getTagName().equals("textStyle") && !nonIndexedTag.getTagName().equals("readingOrder")) {
            nonIndexedTag.getAttributesValuesMap();
        // logger.debug("nonindexed tag found " + nonIndexedTag.getTagName());
        }
    }
    for (CustomTag indexedTag : cl.getIndexedTags()) {
        if (!indexedTag.getTagName().equals("textStyle")) {
            // logger.debug("indexed tag found " + indexedTag.getTagName());
            Sheet firstSheet;
            Sheet currSheet;
            String tagname = indexedTag.getTagName();
            String overview = "Overview";
            if (!selectedTags.contains(tagname)) {
                break;
            }
            /*
				 *first Excel page is the overview -> all tags without their special tag attributes
				 */
            if (wb.getSheet(overview) != null) {
                firstSheet = wb.getSheet(overview);
            } else {
                firstSheet = wb.createSheet(WorkbookUtil.createSafeSheetName(overview));
            }
            // either find existent sheet or create new one
            if (wb.getSheet(tagname) != null) {
                currSheet = wb.getSheet(tagname);
            // logger.debug("existent sheet " + tagname);
            } else {
                currSheet = wb.createSheet(WorkbookUtil.createSafeSheetName(tagname));
            // logger.debug("new sheet " + tagname);
            }
            CreationHelper crHelper = wb.getCreationHelper();
            Map<String, Object> attributes = indexedTag.getAttributeNamesValuesMap();
            Iterator<String> attributeIterator = attributes.keySet().iterator();
            int offset = (int) attributes.get("offset");
            int length = (int) attributes.get("length");
            // logger.debug("text string " + textStr + " length " +textStr.length() + " offset " + offset + " length of substring " + length);
            String tmpTextStr = textStr.substring(offset, offset + length);
            int lastRowIdxOfFirstSheet = firstSheet.getLastRowNum();
            if (lastRowIdxOfFirstSheet == 0) {
                fillFirstOverviewRow(firstSheet);
            }
            int lastRowIdx = currSheet.getLastRowNum();
            // logger.debug("lastRowIdx " + lastRowIdx);
            if (lastRowIdx == 0) {
                fillFirstRow(currSheet, attributes, crHelper);
            }
            /*
				 * the first (overview) sheet shows all custom tags of the doc - tag attributes are stored as a list in one cell
				 */
            Row nextRowOfFirstSheet = firstSheet.createRow(++lastRowIdxOfFirstSheet);
            int idxHelper = 0;
            nextRowOfFirstSheet.createCell(idxHelper++).setCellValue(tmpTextStr);
            nextRowOfFirstSheet.createCell(idxHelper++).setCellValue(context);
            nextRowOfFirstSheet.createCell(idxHelper++).setCellValue(doc);
            nextRowOfFirstSheet.createCell(idxHelper++).setCellValue(page);
            nextRowOfFirstSheet.createCell(idxHelper++).setCellValue(regionID);
            nextRowOfFirstSheet.createCell(idxHelper++).setCellValue(lineID);
            nextRowOfFirstSheet.createCell(idxHelper++).setCellValue(wordId);
            // all attributes are s
            nextRowOfFirstSheet.createCell(idxHelper++).setCellValue(tagname + " " + attributes.toString());
            /*
				 * subsequent sheets shows all different tags on their own sheet
				 * 
				 */
            Row nextRow = currSheet.createRow(++lastRowIdx);
            int idx = 0;
            nextRow.createCell(idx++).setCellValue(tmpTextStr);
            nextRow.createCell(idx++).setCellValue(context);
            nextRow.createCell(idx++).setCellValue(doc);
            nextRow.createCell(idx++).setCellValue(page);
            nextRow.createCell(idx++).setCellValue(regionID);
            nextRow.createCell(idx++).setCellValue(lineID);
            nextRow.createCell(idx++).setCellValue(wordId);
            // for (int i = 0; i < attributes.size(); i++){
            // String attributeName = attributeIterator.next();
            // logger.debug("attributeName " + attributeName);
            // firstRow.createCell(i+idx).setCellValue(crHelper.createRichTextString(attributeName));
            // Object value = attributes.get(attributeName);
            // logger.debug("attribute value " + value);
            // nextRow.createCell(i+idx).setCellValue(crHelper.createRichTextString(String.valueOf(value)));
            // }
            /*
				 * each attribute of a custom tag is stored in a single cell
				 */
            Row row = currSheet.getRow(0);
            for (int i = 0; i < attributes.size(); i++) {
                String attributeName = attributeIterator.next();
                Object value = attributes.get(attributeName);
                for (int colIdx = 0; colIdx < row.getLastCellNum(); colIdx++) {
                    Cell cell = row.getCell(colIdx);
                    if (cell.getRichStringCellValue().getString().equals(attributeName)) {
                        nextRow.createCell(colIdx).setCellValue(crHelper.createRichTextString(String.valueOf(value)));
                        break;
                    }
                }
            }
        }
    }
}
Also used : CreationHelper(org.apache.poi.ss.usermodel.CreationHelper) CustomTag(eu.transkribus.core.model.beans.customtags.CustomTag) CustomTagList(eu.transkribus.core.model.beans.customtags.CustomTagList) IOException(java.io.IOException) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell)

Example 3 with CustomTagList

use of eu.transkribus.core.model.beans.customtags.CustomTagList in project TranskribusCore by Transkribus.

the class TrpTeiStringBuilder method getTaggedContent.

String getTaggedContent(ITrpShapeType shape) {
    CustomTagList cl = shape.getCustomTagList();
    List<CustomTag> ctList = new ArrayList<CustomTag>();
    // for (CustomTag t : cl.getTags()) {
    for (CustomTag t : cl.getIndexedTags()) {
        ctList.add(t.copy());
    }
    Collections.sort(ctList);
    String text = shape.getUnicodeText();
    // escape the shape text here - later on the tag elements would be escaped too
    String escapedText = escapeShapeText(text, ctList);
    logger.trace("ShapeText = " + text + " escaped: " + escapedText);
    for (CustomTag t : ctList) {
        if (commonPars.isTagSelected(t.getTagName()) || (commonPars.isDoBlackening() && t.getTagName().equals(BlackeningTag.TAG_NAME)) || t.getTagName().equals(TextStyleTag.TAG_NAME)) {
            escapedText = insertTag(escapedText, t, ctList);
        }
    }
    logger.trace("escaped text after tag insertion: " + escapedText);
    // replace blackened text:
    if (commonPars.isDoBlackening()) {
        escapedText = hideBlackenedText(escapedText);
    }
    return escapedText;
}
Also used : ArrayList(java.util.ArrayList) CustomTag(eu.transkribus.core.model.beans.customtags.CustomTag) CustomTagList(eu.transkribus.core.model.beans.customtags.CustomTagList)

Example 4 with CustomTagList

use of eu.transkribus.core.model.beans.customtags.CustomTagList in project TranskribusCore by Transkribus.

the class TrpTableCellType method copyFields.

@Override
public void copyFields(ITrpShapeType src) {
    if (!(src instanceof TrpTableCellType))
        throw new RuntimeException("copyFields - not a TrpTableCellType!");
    TrpTableCellType srcCell = (TrpTableCellType) src;
    this.id = TrpPageType.getUniqueId(getName());
    this.coords = BeanCopyUtils.copyCoordsType(srcCell.coords);
    if (srcCell.textLine != null)
        textLine = new ArrayList<>(srcCell.textLine);
    this.row = srcCell.row;
    this.col = srcCell.col;
    this.rowSpan = srcCell.rowSpan;
    this.colSpan = srcCell.colSpan;
    if (srcCell.getCustomTagList() != null)
        srcCell.getCustomTagList().writeToCustomTag();
    if (srcCell.custom != null)
        custom = new String(srcCell.custom);
    if (srcCell.comments != null)
        comments = new String(srcCell.comments);
    // copy new fields:
    table = srcCell.table;
    data = srcCell.data;
    customTagList = new CustomTagList(this);
}
Also used : ArrayList(java.util.ArrayList) CustomTagList(eu.transkribus.core.model.beans.customtags.CustomTagList)

Example 5 with CustomTagList

use of eu.transkribus.core.model.beans.customtags.CustomTagList in project TranskribusCore by Transkribus.

the class TrpTextLineType method setCustom.

@Override
public void setCustom(String custom) {
    // TODO: catch exceptions (index out of bounds!)
    // logger.debug("setting custom tag to: "+custom);
    this.custom = custom;
    customTagList = new CustomTagList(this);
}
Also used : CustomTagList(eu.transkribus.core.model.beans.customtags.CustomTagList)

Aggregations

CustomTagList (eu.transkribus.core.model.beans.customtags.CustomTagList)19 CustomTag (eu.transkribus.core.model.beans.customtags.CustomTag)9 TextStyleTag (eu.transkribus.core.model.beans.customtags.TextStyleTag)6 ArrayList (java.util.ArrayList)6 TrpPageType (eu.transkribus.core.model.beans.pagecontent_trp.TrpPageType)4 TrpTextLineType (eu.transkribus.core.model.beans.pagecontent_trp.TrpTextLineType)4 TrpTextRegionType (eu.transkribus.core.model.beans.pagecontent_trp.TrpTextRegionType)4 IOException (java.io.IOException)4 Test (org.junit.Test)4 LinkedHashMap (java.util.LinkedHashMap)2 RtfText (com.tutego.jrtf.RtfText)1 TrpTranscriptMetadata (eu.transkribus.core.model.beans.TrpTranscriptMetadata)1 AbbrevTag (eu.transkribus.core.model.beans.customtags.AbbrevTag)1 BlackeningTag (eu.transkribus.core.model.beans.customtags.BlackeningTag)1 CommentTag (eu.transkribus.core.model.beans.customtags.CommentTag)1 GapTag (eu.transkribus.core.model.beans.customtags.GapTag)1 SuppliedTag (eu.transkribus.core.model.beans.customtags.SuppliedTag)1 TextStyleType (eu.transkribus.core.model.beans.pagecontent.TextStyleType)1 TrpObservable (eu.transkribus.core.model.beans.pagecontent_trp.observable.TrpObservable)1 Cell (org.apache.poi.ss.usermodel.Cell)1