Shavian-info / readlex

The Read Lexicon: a spelling dictionary for the Shavian alphabet following the rhotic Received Pronunciation standard.
MIT License
34 stars 8 forks source link

Issue - double punctuation between words (em-dash usage) #66

Open mrshr3d opened 7 months ago

mrshr3d commented 7 months ago

The issue arises when an em-dash is used between 2 words, and where there are other punctuation marks adjacent to the em-dash. i.e. where the first part before the em-dash is exclaimed or is a question etc.

Merriam-Webter does have examples showing this particular usage of the em-dash here https://www.merriam-webster.com/grammar/em-dash-en-dash-how-to-use

Here is an "OK" sample, where the em-dash is the only character (no other adjacent punctuation):

Within its first year, Mabel and Harry had sampled all of the bakeryโ€™s offeringsโ€”all 62 itemsโ€”and had also decided that the exercise was worth repeating.

๐‘ข๐‘ฆ๐‘ž๐‘ฆ๐‘ฏ ๐‘ฆ๐‘‘๐‘• ๐‘“๐‘ป๐‘•๐‘‘ ๐‘˜๐‘ฝ, ยท๐‘ฅ๐‘ฑ๐‘š๐‘ฉ๐‘ค ๐‘ฏ ยท๐‘ฃ๐‘จ๐‘ฎ๐‘ฆ ๐‘ฃ๐‘จ๐‘› ๐‘•๐‘ญ๐‘ฅ๐‘๐‘ฉ๐‘ค๐‘› ๐‘ท๐‘ค ๐‘ ๐‘ž ๐‘š๐‘ฑ๐‘’๐‘ผ๐‘ฆ๐‘Ÿ ๐‘ช๐‘“๐‘ผ๐‘ฆ๐‘™๐‘Ÿโ€”๐‘ท๐‘ค 62 ๐‘ฒ๐‘‘๐‘ฉ๐‘ฅ๐‘Ÿโ€”๐‘ฏ ๐‘ฃ๐‘จ๐‘› ๐‘ท๐‘ค๐‘•๐‘ด ๐‘›๐‘ฆ๐‘•๐‘ฒ๐‘›๐‘ฉ๐‘› ๐‘ž๐‘จ๐‘‘ ๐‘ž ๐‘ง๐‘’๐‘•๐‘ผ๐‘•๐‘ฒ๐‘Ÿ ๐‘ข๐‘ช๐‘Ÿ ๐‘ข๐‘ป๐‘” ๐‘ฎ๐‘ฆ๐‘๐‘ฐ๐‘‘๐‘ฆ๐‘™.

Here is a particular bad sample from Alice:

She waited for some time without hearing anything more: at last came a rumbling of little cartwheels, and the sound of a good many voices all talking together: she made out the words: โ€œWhereโ€™s the other ladder?โ€”Why, I hadnโ€™t to bring but one; Billโ€™s got the otherโ€”Bill! fetch it here, lad!โ€”Here, put โ€™em up at this cornerโ€”No, tie โ€™em together firstโ€”they donโ€™t reach half high enough yetโ€”Oh! theyโ€™ll do well enough; donโ€™t be particularโ€”Here, Bill! catch hold of this ropeโ€”Will the roof bear?โ€”Mind that loose slateโ€”Oh, itโ€™s coming down! Heads below!โ€ (a loud crash)โ€”โ€œNow, who did that?โ€”It was Bill, I fancyโ€”Whoโ€™s to go down the chimney?โ€”Nay, I shanโ€™t! You do it!โ€”That I wonโ€™t, then!โ€”Billโ€™s to go downโ€”Here, Bill! the master says youโ€™re to go down the chimney!โ€

๐‘–๐‘ฐ ๐‘ข๐‘ฑ๐‘‘๐‘ฉ๐‘› ๐‘“ ๐‘•๐‘ณ๐‘ฅ ๐‘‘๐‘ฒ๐‘ฅ ๐‘ข๐‘ฆ๐‘ž๐‘ฌ๐‘‘ ๐‘ฃ๐‘ฝ๐‘ฆ๐‘™ ๐‘ง๐‘ฏ๐‘ฆ๐‘”๐‘ฆ๐‘™ ๐‘ฅ๐‘น: ๐‘จ๐‘‘ ๐‘ค๐‘ญ๐‘•๐‘‘ ๐‘’๐‘ฑ๐‘ฅ ๐‘ฉ ๐‘ฎ๐‘ณ๐‘ฅ๐‘š๐‘ค๐‘ฆ๐‘™ ๐‘ ๐‘ค๐‘ฆ๐‘‘๐‘ฉ๐‘ค ๐‘’๐‘ธ๐‘‘๐‘ข๐‘ฐ๐‘ค๐‘Ÿ, ๐‘ฏ ๐‘ž ๐‘•๐‘ฌ๐‘ฏ๐‘› ๐‘ ๐‘ฉ ๐‘œ๐‘ซ๐‘› ๐‘ฅ๐‘ง๐‘ฏ๐‘ฆ ๐‘๐‘ถ๐‘•๐‘ฉ๐‘Ÿ ๐‘ท๐‘ค ๐‘‘๐‘ท๐‘’๐‘ฆ๐‘™ ๐‘‘๐‘ฉ๐‘œ๐‘ง๐‘ž๐‘ผ: ๐‘–๐‘ฐ ๐‘ฅ๐‘ฑ๐‘› ๐‘ฌ๐‘‘ ๐‘ž ๐‘ข๐‘ป๐‘›๐‘Ÿ: ยซ๐‘ข๐‘บ๐‘Ÿ ๐‘ž ๐‘ณ๐‘ž๐‘ผ ladder?โ€”๐‘ข๐‘ฒ, ๐‘ฒ ๐‘ฃ๐‘จ๐‘›๐‘ฉ๐‘ฏ๐‘‘ ๐‘‘ ๐‘š๐‘ฎ๐‘ฆ๐‘™ ๐‘š๐‘ณ๐‘‘ ๐‘ข๐‘ณ๐‘ฏ; ยท๐‘š๐‘ฆ๐‘ค๐‘Ÿ ๐‘œ๐‘ช๐‘‘ ๐‘ž ๐‘ณ๐‘ž๐‘ผโ€”ยท๐‘š๐‘ฆ๐‘ค! ๐‘“๐‘ง๐‘— ๐‘ฆ๐‘‘ ๐‘ฃ๐‘ฝ, lad!โ€”๐‘ฃ๐‘ฝ, ๐‘๐‘ซ๐‘‘ ๐‘ฉ๐‘ฅ ๐‘ณ๐‘ ๐‘จ๐‘‘ ๐‘ž๐‘ฆ๐‘• ๐‘’๐‘น๐‘ฏ๐‘ผโ€”๐‘ฏ๐‘ด, ๐‘‘๐‘ฒ ๐‘ฉ๐‘ฅ ๐‘‘๐‘ฉ๐‘œ๐‘ง๐‘ž๐‘ผ ๐‘“๐‘ป๐‘•๐‘‘โ€”๐‘ž๐‘ฑ ๐‘›๐‘ด๐‘ฏ๐‘‘ ๐‘ฎ๐‘ฐ๐‘— ๐‘ฃ๐‘ญ๐‘“ ๐‘ฃ๐‘ฒ ๐‘ฆ๐‘ฏ๐‘ณ๐‘“ ๐‘˜๐‘ง๐‘‘โ€”๐‘ด! ๐‘ž๐‘ฑ๐‘ค ๐‘›๐‘ต ๐‘ข๐‘ง๐‘ค ๐‘ฆ๐‘ฏ๐‘ณ๐‘“; ๐‘›๐‘ด๐‘ฏ๐‘‘ ๐‘š๐‘ฐ ๐‘๐‘ผ๐‘‘๐‘ฆ๐‘’๐‘˜๐‘ฉ๐‘ค๐‘ผโ€”๐‘ฃ๐‘ฝ, ยท๐‘š๐‘ฆ๐‘ค! ๐‘’๐‘จ๐‘— ๐‘ฃ๐‘ด๐‘ค๐‘› ๐‘ ๐‘ž๐‘ฆ๐‘• ๐‘ฎ๐‘ด๐‘โ€”๐‘ข๐‘ฆ๐‘ค ๐‘ž ๐‘ฎ๐‘ต๐‘“ bear?โ€”๐‘ฅ๐‘ฒ๐‘ฏ๐‘› ๐‘ž๐‘จ๐‘‘ ๐‘ค๐‘ต๐‘• ๐‘•๐‘ค๐‘ฑ๐‘‘โ€”๐‘ด, ๐‘ฆ๐‘‘๐‘• ๐‘’๐‘ณ๐‘ฅ๐‘ฆ๐‘™ ๐‘›๐‘ฌ๐‘ฏ! ๐‘ฃ๐‘ง๐‘›๐‘Ÿ ๐‘š๐‘ฆ๐‘ค๐‘ด!ยป (๐‘ฉ ๐‘ค๐‘ฌ๐‘› crash)โ€”ยป๐‘ฏ๐‘ฌ, ๐‘ฃ๐‘ต ๐‘›๐‘ฆ๐‘› that?โ€”๐‘ฆ๐‘‘ ๐‘ข๐‘ช๐‘Ÿ ยท๐‘š๐‘ฆ๐‘ค, ๐‘ฒ ๐‘“๐‘จ๐‘ฏ๐‘•๐‘ฆโ€”๐‘ฃ๐‘ต๐‘Ÿ ๐‘‘ ๐‘œ๐‘ด ๐‘›๐‘ฌ๐‘ฏ ๐‘ž chimney?โ€”๐‘ฏ๐‘ฑ, ๐‘ฒ ๐‘–๐‘ญ๐‘ฏ๐‘‘! ๐‘ฟ ๐‘›๐‘ต it!โ€”๐‘ž๐‘จ๐‘‘ ๐‘ฒ ๐‘ข๐‘ด๐‘ฏ๐‘‘, then!โ€”ยท๐‘š๐‘ฆ๐‘ค๐‘Ÿ ๐‘‘ ๐‘œ๐‘ด ๐‘›๐‘ฌ๐‘ฏโ€”๐‘ฃ๐‘ฝ, ยท๐‘š๐‘ฆ๐‘ค! ๐‘ž ๐‘ฅ๐‘ญ๐‘•๐‘‘๐‘ผ ๐‘•๐‘ง๐‘Ÿ ๐‘ฟ๐‘ผ ๐‘‘ ๐‘œ๐‘ด ๐‘›๐‘ฌ๐‘ฏ ๐‘ž ๐‘—๐‘ฆ๐‘ฅ๐‘ฏ๐‘ฆ!ยป

Shavian-info commented 7 months ago

I am aware of the issue but thank you for raising it. It's a problem with the underlying text tagging library (SpaCy). I have tried developing workarounds but so far without success. But I'll look into it further.

mrshr3d commented 7 months ago

Huh.... I thought I had posted a suggested "dirty" fix but I don't see it here in the chat. Work-around is to pad any em-dashes with spaces before conversion, then removing the spaces after conversion. Though this is simple enough to do to my source text before running it through latin2shaw.

def latin2shaw(text):
+    text = text.replace('โ€”', ' โ€” ')

    ...

+    text_shaw = text_shaw.replace(' โ€” ', 'โ€”')
     return text_shaw

Confirmed that re-running latin2shaw with the above 2 lines added fixes it:

๐‘–๐‘ฐ ๐‘ข๐‘ฑ๐‘‘๐‘ฉ๐‘› ๐‘“ ๐‘•๐‘ณ๐‘ฅ ๐‘‘๐‘ฒ๐‘ฅ ๐‘ข๐‘ฆ๐‘ž๐‘ฌ๐‘‘ ๐‘ฃ๐‘ฝ๐‘ฆ๐‘™ ๐‘ง๐‘ฏ๐‘ฆ๐‘”๐‘ฆ๐‘™ ๐‘ฅ๐‘น: ๐‘จ๐‘‘ ๐‘ค๐‘ญ๐‘•๐‘‘ ๐‘’๐‘ฑ๐‘ฅ ๐‘ฉ ๐‘ฎ๐‘ณ๐‘ฅ๐‘š๐‘ค๐‘ฆ๐‘™ ๐‘ ๐‘ค๐‘ฆ๐‘‘๐‘ฉ๐‘ค ๐‘’๐‘ธ๐‘‘๐‘ข๐‘ฐ๐‘ค๐‘Ÿ, ๐‘ฏ ๐‘ž ๐‘•๐‘ฌ๐‘ฏ๐‘› ๐‘ ๐‘ฉ ๐‘œ๐‘ซ๐‘› ๐‘ฅ๐‘ง๐‘ฏ๐‘ฆ ๐‘๐‘ถ๐‘•๐‘ฉ๐‘Ÿ ๐‘ท๐‘ค ๐‘‘๐‘ท๐‘’๐‘ฆ๐‘™ ๐‘‘๐‘ฉ๐‘œ๐‘ง๐‘ž๐‘ผ: ๐‘–๐‘ฐ ๐‘ฅ๐‘ฑ๐‘› ๐‘ฌ๐‘‘ ๐‘ž ๐‘ข๐‘ป๐‘›๐‘Ÿ: ยซ๐‘ข๐‘บ๐‘Ÿ ๐‘ž ๐‘ณ๐‘ž๐‘ผ ๐‘ค๐‘จ๐‘›๐‘ผ?โ€”๐‘ข๐‘ฒ, ๐‘ฒ ๐‘ฃ๐‘จ๐‘›๐‘ฉ๐‘ฏ๐‘‘ ๐‘‘ ๐‘š๐‘ฎ๐‘ฆ๐‘™ ๐‘š๐‘ณ๐‘‘ ๐‘ข๐‘ณ๐‘ฏ; ยท๐‘š๐‘ฆ๐‘ค๐‘Ÿ ๐‘œ๐‘ช๐‘‘ ๐‘ž ๐‘ณ๐‘ž๐‘ผโ€”ยท๐‘š๐‘ฆ๐‘ค! ๐‘“๐‘ง๐‘— ๐‘ฆ๐‘‘ ๐‘ฃ๐‘ฝ, ๐‘ค๐‘จ๐‘›!โ€”๐‘ฃ๐‘ฝ, ๐‘๐‘ซ๐‘‘ ๐‘ฉ๐‘ฅ ๐‘ณ๐‘ ๐‘จ๐‘‘ ๐‘ž๐‘ฆ๐‘• ๐‘’๐‘น๐‘ฏ๐‘ผโ€”๐‘ฏ๐‘ด, ๐‘‘๐‘ฒ ๐‘ฉ๐‘ฅ ๐‘‘๐‘ฉ๐‘œ๐‘ง๐‘ž๐‘ผ ๐‘“๐‘ป๐‘•๐‘‘โ€”๐‘ž๐‘ฑ ๐‘›๐‘ด๐‘ฏ๐‘‘ ๐‘ฎ๐‘ฐ๐‘— ๐‘ฃ๐‘ญ๐‘“ ๐‘ฃ๐‘ฒ ๐‘ฆ๐‘ฏ๐‘ณ๐‘“ ๐‘˜๐‘ง๐‘‘โ€”๐‘ด! ๐‘ž๐‘ฑ๐‘ค ๐‘›๐‘ต ๐‘ข๐‘ง๐‘ค ๐‘ฆ๐‘ฏ๐‘ณ๐‘“; ๐‘›๐‘ด๐‘ฏ๐‘‘ ๐‘š๐‘ฐ ๐‘๐‘ผ๐‘‘๐‘ฆ๐‘’๐‘˜๐‘ฉ๐‘ค๐‘ผโ€”๐‘ฃ๐‘ฝ, ยท๐‘š๐‘ฆ๐‘ค! ๐‘’๐‘จ๐‘— ๐‘ฃ๐‘ด๐‘ค๐‘› ๐‘ ๐‘ž๐‘ฆ๐‘• ๐‘ฎ๐‘ด๐‘โ€”๐‘ข๐‘ฆ๐‘ค ๐‘ž ๐‘ฎ๐‘ต๐‘“ ๐‘š๐‘บ?โ€”๐‘ฅ๐‘ฒ๐‘ฏ๐‘› ๐‘ž๐‘จ๐‘‘ ๐‘ค๐‘ต๐‘• ๐‘•๐‘ค๐‘ฑ๐‘‘โ€”๐‘ด, ๐‘ฆ๐‘‘๐‘• ๐‘’๐‘ณ๐‘ฅ๐‘ฆ๐‘™ ๐‘›๐‘ฌ๐‘ฏ! ๐‘ฃ๐‘ง๐‘›๐‘Ÿ ๐‘š๐‘ฆ๐‘ค๐‘ด!ยป (๐‘ฉ ๐‘ค๐‘ฌ๐‘› ๐‘’๐‘ฎ๐‘จ๐‘–)โ€”ยซ๐‘ฏ๐‘ฌ, ๐‘ฃ๐‘ต ๐‘›๐‘ฆ๐‘› ๐‘ž๐‘จ๐‘‘?โ€”๐‘ฆ๐‘‘ ๐‘ข๐‘ช๐‘Ÿ ยท๐‘š๐‘ฆ๐‘ค, ๐‘ฒ ๐‘“๐‘จ๐‘ฏ๐‘•๐‘ฆโ€”๐‘ฃ๐‘ต๐‘Ÿ ๐‘‘ ๐‘œ๐‘ด ๐‘›๐‘ฌ๐‘ฏ ๐‘ž ๐‘—๐‘ฆ๐‘ฅ๐‘ฏ๐‘ฆ?โ€”๐‘ฏ๐‘ฑ, ๐‘ฒ ๐‘–๐‘ญ๐‘ฏ๐‘‘! ๐‘ฟ ๐‘›๐‘ต ๐‘ฆ๐‘‘!โ€”๐‘ž๐‘จ๐‘‘ ๐‘ฒ ๐‘ข๐‘ด๐‘ฏ๐‘‘, ๐‘ž๐‘ง๐‘ฏ!โ€”ยท๐‘š๐‘ฆ๐‘ค๐‘Ÿ ๐‘‘ ๐‘œ๐‘ด ๐‘›๐‘ฌ๐‘ฏโ€”๐‘ฃ๐‘ฝ, ยท๐‘š๐‘ฆ๐‘ค! ๐‘ž ๐‘ฅ๐‘ญ๐‘•๐‘‘๐‘ผ ๐‘•๐‘ง๐‘Ÿ ๐‘ฟ๐‘ผ ๐‘‘ ๐‘œ๐‘ด ๐‘›๐‘ฌ๐‘ฏ ๐‘ž ๐‘—๐‘ฆ๐‘ฅ๐‘ฏ๐‘ฆ!ยป

Shavian-info commented 7 months ago

Yes, this should work, but it will (I think) mean that if the original text had spaces on either side of the dashes, they will be removed. I believe there is a way to tell the SpaCy tagger to recognise a dash next to punctuation as punctuation but I have so far struggled to make it work. This is what I was thinking to look into again. If that fails, I'll add your suggested workaround.