LinguaCafe icon indicating copy to clipboard operation
LinguaCafe copied to clipboard

Tokenization error for text using chevrons (« and ») to demarcate quotes.

Open cblanken opened this issue 8 months ago • 5 comments

Screenshot_2025-03-26-23-05-08-58_3aea4af51f236e4932235fdada7d1643.jpg

This is an old import, so this may have been fixed if there have been any recent updates to the tokenizer, but I'll have to test some other texts when I have time.

cblanken avatar Mar 27 '25 03:03 cblanken

Can you please copy-paste the text here?

I can check what what the tokenizer outputs. It's likely that the post processing concatenates words which is fixable, but if the tokenizer does not split them I won't be able to fix it.

so this may have been fixed if there have been any recent updates to the tokenizer

I think only your merged PR.

simjanos-dev avatar Mar 30 '25 15:03 simjanos-dev

I can't find the exact page I originally posted, but this one has some examples.

Man hat viel erreicht, wenn einen sein Leben an ein volles Faß erinnert und nicht an einen leeren Eimer.)Danzelot: »Hör zu, mein Junge: Ich habe dir nicht viel zu vermachen, jedenfalls nicht in pekuniärer Hinsicht. Das weißt du. Ich bin keiner von diesen stinkreichen Lindwurmfesteschriftstellern geworden, die ihre Honorare in Säcken im Keller stapeln. Ich werde dir meinen Garten vererben, aber ich weiß, daß du dir nicht viel aus Gemüse machst.«(Das war richtig. Ich als junger Lindwurm konnte mit den Blumenkohlverherrlichungen und den Hymnen an den Rhabarber in Danzelots Gartenbuch herzlich wenig anfangen, und ich machte auch keinen Hehl daraus. Erst in späteren Jahren keimte Danzelots Saat, ich legte mir sogar selber einen Garten an, züchtete Blauen Blumenkohl und holte mir manche Inspiration aus der gezähmten Natur.)Danzelot: »Ich bin also ziemlich klamm zur Zeit ... «(Der bedrückenden Situation zum Trotz konnte ich mir ein Prusten nicht verkneifen, denn die Benutzung des Wortes »klamm« in seinem Zustand hatte etwas unfreiwillig Komisches, ein Fehlgriff in die Schublade des schwarzen Humors - den Danzelot mir in einem Manuskript wohl rot angestrichen hätte. Aber mein Prusten ins Taschentuch konnte auch als tränenersticktes Schneuzen durchgehen.)Danzelot: »... und kann dir daher in materieller Hinsicht nichts vermachen.«(Ich winkte ab und schluchzte, diesmal vor Rührung. Er starb gerade und machte sich gleichzeitig Sorgen um meine Zukunft. Das war ergreifend.)Danzelot: »Aber ich besitze da etwas, das wesentlich wertvoller ist als alle Schätze von Zamonien. Zumindest für einen Schriftsteller.«(Ich sah ihn mit tränengefüllten Augen an.)Danzelot: »Ja, man könnte sagen, daß es wahrscheinlich neben dem Orm das Wertvollste ist, in dessen Besitz ein Schriftsteller in seinem Leben kommen kann.«(Er machte es ziemlich spannend. An seiner Stelle hätte ich mich bemüht, die nötigen Informationen in gebotener Kürze loszuwerden. Ich beugte mich vor.)Danzelot: »Ich bin im Besitz des großartigsten Textes der gesamten zamonischen Literatur.«(Ach herrje, dachte ich. Entweder er fängt an zu delirieren, oder er will mir seine verstaubte Bibliothek vermachen und redet von seiner Erstausgabe des Ritter Hempel, jener uralten Schwarte von Gryphius von Odenhobler, den er als Schriftsteller so vorbildlich und ich so unlesbar fand.)Ich: »Was meinst du damit?«Danzelot: »Vor einiger Zeit sandte mir ein junger zamonischer Dichter von außerhalb der Lindwurmfeste ein Manuskript. Mit dem üblichen verschämten Blabla, daß dies nur ein bescheidener Versuch, ein zaghafter Schritt ins Ungewisse sei und so weiter, und ob ich nicht mal sagen könnte, was ich davon hielt - und vielen Dank im voraus!Nun, ich habe es mir zur Pflicht gemacht, all diese unverlangt eingesandten Manuskripte auch zu lesen, und ich darf mit Fug und Recht behaupten, daß mich diese Lektüre einen nicht unerheblichen Teil meines Lebens und einige Nerven gekostet hat.«(Danzelot hustete ungesund.)Danzelot: »Aber die Geschichte war nicht lang, nur ein paar Seiten, ich saß gerade am Frühstückstisch, hatte mir eine Tasse Kaffee eingeschenkt und die Zeitung schon ausgelesen, also nahm ich mir den Text gleich vor - jeden Tag eine gute Tat, du weißt schon, warum nicht gleich zum Frühstück, dann hatte ich es hinter mir. Ich war durch langjährige Erfahrung auf das übliche Gestammel eines mit Stil, Grammatik, Liebeskummer und Weltekel ringenden Jungschriftstellers vorbereitet, also seufzte ich und begann mit der Lektüre.«(Danzelot seufzte herzzerreißend, und ich wußte nicht, ob es eine Imitation seines damaligen Seufzers war oder mit seinem baldigen Dahinscheiden zusammenhing.)Danzelot: »Als ich ungefähr drei Stunden später wieder zur Tasse griff, war sie immer noch randvoll und der Kaffee eiskalt. Ich hatte für das Lesen der Geschichte aber keine drei Stunden gebraucht, sondern nicht mal fünf Minuten - ich muß die restliche Zeit regungslos dagesessen haben, den Brief in der Hand, in einer Art Schockzustand.

Image

cblanken avatar Mar 30 '25 19:03 cblanken

It is still broken in the current version. I'll check what the tokenizer outputs.

simjanos-dev avatar Apr 07 '25 21:04 simjanos-dev

The tokenizer returns tokens like Lektüre.«(Danzelot. I think the way to fix this is to create a config(there's already one named words_to_skip with a lot of symbols) for symbols that should split into its own words.

This may affect import performance, since we will need to scan each word for each symbol. Don't know how much this would slow down importing, we could also add it as an option.

We could also create a white list for each language, but that would have its own problems, like the imported text having foreign(compared to the target language) words or parts.

Not sure when I'll get to this ticket, I have a 4 day weekend, I want to experiment with stanza and adding languages.

simjanos-dev avatar Apr 17 '25 23:04 simjanos-dev

Okay, I started looking into this a bit, and I think this may be easier to solve by adding an option for EPUB imports to preserve line breaks, paragraphs, etc. like I mentioned in issue #455.

For the sample text I provided that seems to be the main issue anyway.

Original EPUB rendered text

Image

LC parsed text

Image

You can see here that the import has stripped the text of the newline between the two without provided an additional space which smashes together the » and ( of the next line. All the mistaken tokenization I could find from this particular text seemed to be similar.

Original EPUB markup

Image

If you look at the EPUB itself, there's a paragraph tag that should force a linebreak.

As it is, I think there are two reasonable ways to handle this.

  1. Insert a space character or newline between block elements like <p>, <div>, etc.
  2. Extract the text without removing the whitespace in the first place.

This may affect import performance, since we will need to scan each word for each symbol. Don't know how much this would slow down importing, we could also add it as an option.

This approach should avoid any major performance concerns since it won't include any additional scanning for punctuation per word/sentence.

@simjanos-dev I'd be happy to work on this issue if you'd like. Just let me know if you have any preferences on the solution.

cblanken avatar Aug 20 '25 15:08 cblanken