Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

page__text.xsl is not honoring the reading order #138

Closed
mikegerber opened this issue May 19, 2021 · 8 comments
Closed

page__text.xsl is not honoring the reading order #138

mikegerber opened this issue May 19, 2021 · 8 comments
Labels
bug enhancement Any enhancement on the software itself (excluding new transformations)

Comments

@mikegerber
Copy link
Contributor

page__text.xsl is not honoring the reading order in the PAGE-XML (pc:ReadingOrder), which gives completely false results. For this page, I get this text (shortened):

% docker run --rm -it -v "$PWD":/data ubma/ocr-fileformat ocr-transform page text OCR-D-GT-PAGE/OCR-D-GT-PAGE_00000024.xml | head
               
20
Die
[22.]
[22.]
ein gleies vorgegeben, und ſo gar ſehr viele mahle gegen ae menſlie Mglikeit mit Gewalt for-
ciret worden zu ſeyn, behaupten wi, mithin neb dem Bredekaw, weler (§. 28. 29.)  in aen ſeinen
Auagen wiederſproen, mit der Pœna fal um do gewier zu belegen i, da
ſecund. Farin. Tit. 9. qu. 66. p. m. 320.
die Klage ſo wohl als das Zeugnß vor falſ und erditet mßen gehalten werden.
§. 35) So viel die von der Inquitin
write /dev/stdout: broken pipe

For comparison, dinglehopper-extract gives the correct text:

% dinglehopper-extract OCR-D-GT-PAGE/OCR-D-GT-PAGE_00000024.xml| head
20
rath mit einer Pœna fiſcali angeſehen worden, und ſolche durch des Hrn. Graffen von Königsfeld Vor-
ſpruch, nur aus Gnaden nachgelaſſen erhalten.
Sondern man hat auch dieſen 4. Wochen lang alle Abend bey der Inquiſitin gantz allein gelaſſen.
Binnen welcher gantzer Zeit der Schreiber Bredekaw beſtändig bey Ihme geweſen, und ſich in
der am 13 ten Octobr. a.c. in Judicio gegen ſeinen geweſenen Hrn. introducirter Appellation deſſen Bey-
raths bedienet hat;
§. 33) Dabenebenſt iſt der Schreiber binnen dieſer gantzen Zeit auf freyem Fuß geblieben, und
hat nicht nur durch ſeinen Conſulenten, ſondern auch, weilen der Inquiſitin ſelbſten in Ihrem Gefängnüß
ſo viele Freyheit gelaſſen worden, daß ſie frembden Beſuch von Ihren Anverwandten ohngehindert em-

Image from the ZIP (converted to JPEG), for easier understanding:

OCR-D-IMG_00000024

@stweil
Copy link
Member

stweil commented May 19, 2021

The XSL which is used for that conversion is too simple to handle more complex PAGE XML. I don't know whether a better XSL is available from other projects.

Did you try whether JPageConverter which is already used for the PAGE to ALTO conversion does a better job? As far as I know it can also produce text.

@stweil stweil added the enhancement Any enhancement on the software itself (excluding new transformations) label May 19, 2021
@mikegerber
Copy link
Contributor Author

I would consider this a serious bug, not an enhancement.

@stweil stweil added the bug label May 20, 2021
@stweil
Copy link
Member

stweil commented May 20, 2021

It's both. PAGE XML is complex, so I would never expect a perfect tool which supports all of its features.

@mikegerber
Copy link
Contributor Author

It's not imperfection by not supporting some features, it's producing a wrong result if it's not honoring the reading order, for a lot of real world PAGE XML files.

@stweil
Copy link
Member

stweil commented May 20, 2021

The texts in the XML file also look strange when I look at them with less or vi ("Mglikeit"). Do you use some special encoding? It's not UTF-8!

@mikegerber
Copy link
Contributor Author

The file in #138 (comment) was created (by a SBB contractor) using Aletheia and uses their encoding scheme, which uses a lot of PUA characters, which in part is based on MUFI (See (https://www.primaresearch.org/www/assets/tools/Special%20Characters%20in%20Aletheia.pdf)). So it's UTF-8, but with private characters. But encoding is an entirely different beast :-) (dinglehopper-extract gives different characters due to normalization, but that's not the issue here.)

@bertsky
Copy link
Contributor

bertsky commented Jun 6, 2023

Sry, did not see this earlier. But I had the exact same use case. It's not so difficult to properly handle PAGE reading order in XSLT 1.0. This was solved along with #151.

(You can even pass XSLT parameters for what hierarchy level you want to extract from (default is highest) or what separators to use for concatenation:

<!-- paragraph break -->
<xsl:param name="pb" select="concat($newline,$newline)"/>
<!-- line break -->
<xsl:param name="lb" select="$newline"/>
<!-- text order: by element or by explicit ReadingOrder (reading-order|document) -->
<xsl:param name="order" select="'reading-order'"/>
<!-- hierarchy level to extract text annotation from (region|line|word|glyph|highest) -->
<xsl:param name="level" select="'highest'"/>

See

ocr-transform page text --help-args

@mikegerber
Copy link
Contributor Author

Probably fixed in #151

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug enhancement Any enhancement on the software itself (excluding new transformations)
Projects
None yet
Development

No branches or pull requests

3 participants