Search in sources :

Example 1 with TrpElementCoordinatesComparator

use of eu.transkribus.core.model.beans.pagecontent_trp.TrpElementCoordinatesComparator in project TranskribusCore by Transkribus.

the class PageXmlUtils method findLinesByBaseline.

public static List<TextLineType> findLinesByBaseline(PcGtsType pc, String baseline) {
    List<TextRegionType> regions = getTextRegions(pc);
    List<TextLineType> matchingLines = new LinkedList<>();
    for (TextRegionType r : regions) {
        r.getTextLine().stream().filter(// isBaselineInLineBounds(l, baseline, threshold))
        l -> doesIntersect(l, baseline)).forEach(l -> matchingLines.add(l));
    }
    if (matchingLines.size() > 1) {
        TrpElementCoordinatesComparator<TextLineType> comp = new TrpElementCoordinatesComparator<>(true);
        Collections.sort(matchingLines, comp);
    }
    return matchingLines;
}
Also used : TrpTextRegionType(eu.transkribus.core.model.beans.pagecontent_trp.TrpTextRegionType) TextRegionType(eu.transkribus.core.model.beans.pagecontent.TextRegionType) FimgStoreReadConnection(eu.transkribus.core.io.FimgStoreReadConnection) TranscriptionLevel(eu.transkribus.core.model.beans.enums.TranscriptionLevel) URL(java.net.URL) Date(java.util.Date) TextLineType(eu.transkribus.core.model.beans.pagecontent.TextLineType) Rectangle2D(java.awt.geom.Rectangle2D) TrpPageUnmarshalListener(eu.transkribus.core.model.builder.TrpPageUnmarshalListener) LoggerFactory(org.slf4j.LoggerFactory) TrpTextRegionType(eu.transkribus.core.model.beans.pagecontent_trp.TrpTextRegionType) TrpRegionType(eu.transkribus.core.model.beans.pagecontent_trp.TrpRegionType) MarshalException(javax.xml.bind.MarshalException) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) FimgStoreImgMd(org.dea.fimgstoreclient.beans.FimgStoreImgMd) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) Dimension(java.awt.Dimension) List(java.util.List) TrpElementCoordinatesComparator(eu.transkribus.core.model.beans.pagecontent_trp.TrpElementCoordinatesComparator) TrpTextLineType(eu.transkribus.core.model.beans.pagecontent_trp.TrpTextLineType) SAXException(org.xml.sax.SAXException) TrpObjectFactory(eu.transkribus.core.model.beans.pagecontent_trp.TrpObjectFactory) CustomTagUtil(eu.transkribus.core.model.beans.customtags.CustomTagUtil) PcGtsType(eu.transkribus.core.model.beans.pagecontent.PcGtsType) Polygon(java.awt.Polygon) Rectangle(java.awt.Rectangle) TextEquivType(eu.transkribus.core.model.beans.pagecontent.TextEquivType) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TransformerException(javax.xml.transform.TransformerException) CoordsType(eu.transkribus.core.model.beans.pagecontent.CoordsType) TrpPageMarshalListener(eu.transkribus.core.model.builder.TrpPageMarshalListener) Marshaller(javax.xml.bind.Marshaller) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ValidationEventCollector(javax.xml.bind.util.ValidationEventCollector) TrpTranscriptStatistics(eu.transkribus.core.model.beans.TrpTranscriptStatistics) LinkedList(java.util.LinkedList) TrpPage(eu.transkribus.core.model.beans.TrpPage) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) Logger(org.slf4j.Logger) RegionType(eu.transkribus.core.model.beans.pagecontent.RegionType) WordType(eu.transkribus.core.model.beans.pagecontent.WordType) JAXBElement(javax.xml.bind.JAXBElement) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) TrpPageType(eu.transkribus.core.model.beans.pagecontent_trp.TrpPageType) FileInputStream(java.io.FileInputStream) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) XmlFormat(eu.transkribus.core.io.formats.XmlFormat) File(java.io.File) MetadataType(eu.transkribus.core.model.beans.pagecontent.MetadataType) StringReader(java.io.StringReader) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TextRegionType(eu.transkribus.core.model.beans.pagecontent.TextRegionType) TableRegionType(eu.transkribus.core.model.beans.pagecontent.TableRegionType) PrintSpaceType(eu.transkribus.core.model.beans.pagecontent.PrintSpaceType) Collections(java.util.Collections) TrpTranscriptMetadata(eu.transkribus.core.model.beans.TrpTranscriptMetadata) ObjectFactory(eu.transkribus.core.model.beans.pagecontent.ObjectFactory) TrpWordType(eu.transkribus.core.model.beans.pagecontent_trp.TrpWordType) InputStream(java.io.InputStream) TextLineType(eu.transkribus.core.model.beans.pagecontent.TextLineType) TrpTextLineType(eu.transkribus.core.model.beans.pagecontent_trp.TrpTextLineType) TrpElementCoordinatesComparator(eu.transkribus.core.model.beans.pagecontent_trp.TrpElementCoordinatesComparator) LinkedList(java.util.LinkedList)

Example 2 with TrpElementCoordinatesComparator

use of eu.transkribus.core.model.beans.pagecontent_trp.TrpElementCoordinatesComparator in project TranskribusCore by Transkribus.

the class PageXmlUtils method copyTextRegionContent.

private static void copyTextRegionContent(TextRegionType oldTr, TextRegionType newTr) {
    List<TextLineType> oldLines = oldTr.getTextLine();
    List<TextLineType> newLines = newTr.getTextLine();
    if (newLines == null || newLines.isEmpty()) {
        // nothing to do here		for(String id : regIds){
        logger.error("There are no textLines to copy to in new Region " + newTr.getId());
        return;
    }
    TrpElementCoordinatesComparator<TextLineType> comp = new TrpElementCoordinatesComparator<>();
    Collections.sort(oldLines, comp);
    Collections.sort(newLines, comp);
    for (int i = 0; i < oldLines.size(); i++) {
        TextLineType l = oldLines.get(i);
        if (i < newLines.size()) {
            TextLineType nl = newLines.get(i);
            nl.setTextEquiv(l.getTextEquiv());
            nl.setTextStyle(l.getTextStyle());
            if (l.getTextEquiv() != null && l.getTextEquiv().getUnicode() != null) {
                logger.debug("Copy line: " + l.getTextEquiv().getUnicode());
            }
        } else {
            // the new segmentation has less lines than the old one.
            // concat the remaining text in last line
            TextLineType nl = newLines.get(newLines.size() - 1);
            if (nl.getTextEquiv() != null && nl.getTextEquiv().getUnicode() != null && l.getTextEquiv() != null && l.getTextEquiv().getUnicode() != null) {
                final String text = nl.getTextEquiv().getUnicode() + " " + l.getTextEquiv().getUnicode();
                nl.getTextEquiv().setUnicode(text);
                logger.debug("Concat to last line: " + l.getTextEquiv().getUnicode());
            }
        }
    }
}
Also used : TextLineType(eu.transkribus.core.model.beans.pagecontent.TextLineType) TrpTextLineType(eu.transkribus.core.model.beans.pagecontent_trp.TrpTextLineType) TrpElementCoordinatesComparator(eu.transkribus.core.model.beans.pagecontent_trp.TrpElementCoordinatesComparator)

Example 3 with TrpElementCoordinatesComparator

use of eu.transkribus.core.model.beans.pagecontent_trp.TrpElementCoordinatesComparator in project TranskribusCore by Transkribus.

the class PageXmlUtils method getFulltextFromLines.

public static String getFulltextFromLines(PcGtsType pc) {
    List<TextRegionType> regions = PageXmlUtils.getTextRegions(pc);
    TrpElementCoordinatesComparator<TextLineType> comp = new TrpElementCoordinatesComparator<>();
    StringBuilder sb = new StringBuilder();
    for (TextRegionType r : regions) {
        List<TextLineType> lines = r.getTextLine();
        if (lines != null && !lines.isEmpty()) {
            Collections.sort(lines, comp);
            for (TextLineType l : lines) {
                if (l.getTextEquiv() != null && l.getTextEquiv().getUnicode() != null) {
                    sb.append(l.getTextEquiv().getUnicode() + " ");
                }
            }
        }
    }
    return sb.toString();
}
Also used : TrpTextRegionType(eu.transkribus.core.model.beans.pagecontent_trp.TrpTextRegionType) TextRegionType(eu.transkribus.core.model.beans.pagecontent.TextRegionType) TextLineType(eu.transkribus.core.model.beans.pagecontent.TextLineType) TrpTextLineType(eu.transkribus.core.model.beans.pagecontent_trp.TrpTextLineType) TrpElementCoordinatesComparator(eu.transkribus.core.model.beans.pagecontent_trp.TrpElementCoordinatesComparator)

Example 4 with TrpElementCoordinatesComparator

use of eu.transkribus.core.model.beans.pagecontent_trp.TrpElementCoordinatesComparator in project TranskribusCore by Transkribus.

the class FinereaderUtils method addTextStyleToWords.

public static void addTextStyleToWords(TrpDoc doc) throws JAXBException, FileNotFoundException {
    /*
	 * Ich hab im folgenden Ordner das Buch abgelegt, wo die Sprecherangaben automatisiert als „letter-spaced“ zu markieren wären (sofern sich das mit angemessenem Aufwand bewältigen lässt):
		ftp://ftp.uibk.ac.at/private/x3061015_20140902_78e054475d7532953c204ce6d392d8e9/Andy_Barbara_Bettina/zu_bearbeiten/
		dabei handelt es sich um folgende Namen, sofern sie am Zeilenanfang stehen:

		Ernst
		Albrecht
		Preising
		Marschall
		Pappenheim
		Pienzenau
		Bern
		Törring
		Nothafft von Wernberg
		Frauenhoven
		Hans von Läubelfing
		Caspar Bernauer
		Agnes
		Theobald
		Knippeldollinger
		Bürgermeister
		Barbara
		Martha
		Stachus
		Der Kastellan
		Herold
		Legat
		
		FIXME Der Herold
		FIXME Der Legat

	 */
    String[] names = { "Ernst", "Albrecht", "Preising", "Marschall", "Pappenheim", "Pienzenau", "Bern", "Törring", "Nothafft von Wernberg", "Frauenhoven", "Hans von Läubelfing", "Caspar Bernauer", "Agnes", "Theobald", "Knippeldollinger", "Bürgermeister", "Barbara", "Martha", "Stachus", "Der Kastellan", "Der Herold", "Der Legat" };
    List<String[]> nameList = new ArrayList<>(names.length);
    List<String> nameStartList = new ArrayList<>(names.length);
    // List<String> nameSet = new ArrayLilst<>();
    String[] tmp;
    for (int i = 0; i < names.length; i++) {
        String s = names[i];
        tmp = s.split(" ");
        String tmpStr = "{ ";
        for (String t : tmp) {
            tmpStr += t + "|";
        }
        System.out.println(i + "\t- splitting: " + tmpStr + "}");
        nameList.add(i, tmp);
        nameStartList.add(tmp[0]);
    }
    TrpElementCoordinatesComparator<WordType> wordComp = new TrpElementCoordinatesComparator<WordType>();
    for (TrpPage p : doc.getPages()) {
        System.out.println("Processing page: " + p.getPageNr());
        URL url = p.getCurrentTranscript().getUrl();
        final String xmlPath = FileUtils.toFile(url).getAbsolutePath();
        File xmlFile = new File(xmlPath);
        PcGtsType pc = JaxbUtils.unmarshal(xmlFile, PcGtsType.class);
        List<TextRegionType> regions = PageXmlUtils.getTextRegions(pc);
        for (TextRegionType r : regions) {
            // System.out.println("Processing region: " + r.getId());
            List<Integer> candidatesIndex;
            int i;
            for (TextLineType l : r.getTextLine()) {
                candidatesIndex = new LinkedList<>();
                i = 0;
                // System.out.println("Processing line: " + l.getId());
                List<WordType> words = l.getWord();
                if (words != null && !words.isEmpty()) {
                    Collections.sort(words, wordComp);
                    // read first word and iterate to second
                    WordType w1 = words.get(i);
                    // List<Integer> candidates = new LinkedList<>();
                    for (int j = 0; j < nameStartList.size(); j++) {
                        String e = nameStartList.get(j);
                        if (w1.getTextEquiv() != null && w1.getTextEquiv().getUnicode() != null && isMatch(w1.getTextEquiv().getUnicode(), e)) {
                            candidatesIndex.add(j);
                        // System.out.println("Found candidate word: " + j + " - " + w1.getTextEquiv().getUnicode());
                        }
                    }
                    if (!candidatesIndex.isEmpty()) {
                        for (Integer index : candidatesIndex) {
                            String[] name = nameList.get(index);
                            if (name.length == 1) {
                                // Done.
                                w1.getTextStyle().setLetterSpaced(true);
                                System.out.println("OK: " + name[i]);
                                break;
                            } else {
                                List<WordType> wordList = new ArrayList<>(name.length);
                                boolean isName = true;
                                wordList.add(w1);
                                String nameStr = w1.getTextEquiv().getUnicode() + " ";
                                // check subsequent words
                                for (i = 1; i < name.length; i++) {
                                    WordType wi = words.get(i);
                                    if (isMatch(wi.getTextEquiv().getUnicode(), name[i])) {
                                        nameStr += wi.getTextEquiv().getUnicode() + " ";
                                        wordList.add(wi);
                                    } else {
                                        System.out.println("NEGATIVE: " + nameStr + words.get(i).getTextEquiv().getUnicode() + " != " + name[i]);
                                        isName = false;
                                        break;
                                    }
                                }
                                if (isName) {
                                    System.out.println("OK : " + nameStr);
                                    for (WordType w : wordList) {
                                        // System.out.println(w.getTextEquiv().getUnicode());
                                        w.getTextStyle().setLetterSpaced(true);
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        // TODO store pageXML
        JaxbUtils.marshalToFile(pc, xmlFile);
    }
}
Also used : TrpPage(eu.transkribus.core.model.beans.TrpPage) ArrayList(java.util.ArrayList) TrpElementCoordinatesComparator(eu.transkribus.core.model.beans.pagecontent_trp.TrpElementCoordinatesComparator) PcGtsType(eu.transkribus.core.model.beans.pagecontent.PcGtsType) URL(java.net.URL) WordType(eu.transkribus.core.model.beans.pagecontent.WordType) TrpTextRegionType(eu.transkribus.core.model.beans.pagecontent_trp.TrpTextRegionType) TextRegionType(eu.transkribus.core.model.beans.pagecontent.TextRegionType) TextLineType(eu.transkribus.core.model.beans.pagecontent.TextLineType) File(java.io.File)

Aggregations

TextLineType (eu.transkribus.core.model.beans.pagecontent.TextLineType)4 TrpElementCoordinatesComparator (eu.transkribus.core.model.beans.pagecontent_trp.TrpElementCoordinatesComparator)4 TextRegionType (eu.transkribus.core.model.beans.pagecontent.TextRegionType)3 TrpTextLineType (eu.transkribus.core.model.beans.pagecontent_trp.TrpTextLineType)3 TrpTextRegionType (eu.transkribus.core.model.beans.pagecontent_trp.TrpTextRegionType)3 TrpPage (eu.transkribus.core.model.beans.TrpPage)2 PcGtsType (eu.transkribus.core.model.beans.pagecontent.PcGtsType)2 WordType (eu.transkribus.core.model.beans.pagecontent.WordType)2 File (java.io.File)2 URL (java.net.URL)2 FimgStoreReadConnection (eu.transkribus.core.io.FimgStoreReadConnection)1 XmlFormat (eu.transkribus.core.io.formats.XmlFormat)1 TrpTranscriptMetadata (eu.transkribus.core.model.beans.TrpTranscriptMetadata)1 TrpTranscriptStatistics (eu.transkribus.core.model.beans.TrpTranscriptStatistics)1 CustomTagUtil (eu.transkribus.core.model.beans.customtags.CustomTagUtil)1 TranscriptionLevel (eu.transkribus.core.model.beans.enums.TranscriptionLevel)1 CoordsType (eu.transkribus.core.model.beans.pagecontent.CoordsType)1 MetadataType (eu.transkribus.core.model.beans.pagecontent.MetadataType)1 ObjectFactory (eu.transkribus.core.model.beans.pagecontent.ObjectFactory)1 PrintSpaceType (eu.transkribus.core.model.beans.pagecontent.PrintSpaceType)1