Hyphenation of long words

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

theotherbassist
Posts: 114
Joined: Thu Mar 06, 2014 9:29 am
Location: UK

Hyphenation of long words

Post by theotherbassist » Sat Feb 17, 2018 1:46 pm

Does anyone know an easy method for hyphenating words a certain number of characters or longer? I'm flashing words sequentially on screen, but comprehension is too low with very long words. Varying "exposure" time by word length has been ruled out.

Obviously some kind of hyphenation dictionary will have to be used to delineate syllables--anyone have any success with one... or know of a better way of thinking about hyphenation in livecode?

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 2792
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria
Contact:

Re: Hyphenation of long words

Post by richmond62 » Sat Feb 17, 2018 2:48 pm

but comprehension is too low
Presumably this is your comprehension as computers cannot comprehend anything.

theotherbassist
Posts: 114
Joined: Thu Mar 06, 2014 9:29 am
Location: UK

Re: Hyphenation of long words

Post by theotherbassist » Sat Feb 17, 2018 3:07 pm

richmond62 wrote:
Sat Feb 17, 2018 2:48 pm
but comprehension is too low
Presumably this is your comprehension as computers cannot comprehend anything.
Yes, comprehension of the text by humans. Or any other species that can read, I suppose.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 2792
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria
Contact:

Re: Hyphenation of long words

Post by richmond62 » Sat Feb 17, 2018 3:29 pm

This will be completely language-specific.

The first thing you are going to need is a routine to determine if a letter is a consonant is a vowel or a consonant . . .

I assume you have a word in a fld called "fVOX", and you have a fld called "fINDX"

Code: Select all

repeat until fld "fVOX" is empty
         put char 1 of fld "fVOX" into BUKVA
         switch BUKVA
            case "a"
               put "V" after fld "fINDX"
               break
            case "e"
               put "V" after fld "fINDX"
               break
               case "i"
               put "V" after fld "fINDX"
               break
               case "o"
               put "V" after fld "fINDX"
               break
               case "u"
               put "V" after fld "fINDX"
               break
               case "y"
               put "V" after fld "fINDX"
               break
            default
               put "C" after fld "fINDX"
         end switch
         wait 20 ticks
         delete  char 1 of fld "fVOX"
      end repeat
hyph1.png
hyph1.png (7.58 KiB) Viewed 968 times
I have treated "y" as a Vowel . . .

theotherbassist
Posts: 114
Joined: Thu Mar 06, 2014 9:29 am
Location: UK

Re: Hyphenation of long words

Post by theotherbassist » Sat Feb 17, 2018 5:06 pm

I love the idea of using linguistic rules to do it, but I'm not sure how consistent (or computationally efficient) that would be. Maybe with something like Polish it might work better, but I suspect English's lower grapheme-phoneme correspondence would cause problems.

I might run with the idea and see how it works out--am I right in thinking it should be quicker to "buffer" all the syllables beforehand and place results in an array variable indexed by word for lookup, rather than run through the rules in real-time? Each word should only appear for <100ms so the display has to be fast.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 2792
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria
Contact:

Re: Hyphenation of long words

Post by richmond62 » Sat Feb 17, 2018 5:21 pm

I love the idea of using linguistic rules to do it
Well:

1. As a computer doesn't speak a language, but does follow rules . . .

2. My first master's degree is in Linguistics, so . . .

If by:
to "buffer" all the syllables beforehand
you mean to store a database of ALL possible syllables in whichever language you are analysing:
I wish you well . . .

theotherbassist
Posts: 114
Joined: Thu Mar 06, 2014 9:29 am
Location: UK

Re: Hyphenation of long words

Post by theotherbassist » Sat Feb 17, 2018 5:50 pm

Ah, no! You're right, that would be unnecessary. I only meant look ahead at the text of the document/book/article to read and create an index of the words within that. Then you could match against that as you go.

theotherbassist
Posts: 114
Joined: Thu Mar 06, 2014 9:29 am
Location: UK

Re: Hyphenation of long words

Post by theotherbassist » Sat Feb 17, 2018 6:01 pm

richmond62 wrote:
Sat Feb 17, 2018 5:21 pm

2. My first master's degree is in Linguistics
My first master's degree is in psych. But as my second is in ethics, I have too many qualms about the first to properly manipulate anyone and must instead dabble in linguistics :P

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4702
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Hyphenation of long words

Post by jacque » Sat Feb 17, 2018 6:03 pm

If you know ahead of time what words will need hyphenation, a custom dictionary of only the long words would be the fastest way. Put those into an array for quick lookup. A dictionary of all words in the language would be huge, but I don't see any other choice if you don't know what text will be displayed.

I wouldn't use parsing rules, it's not only slower but too prone to error.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

theotherbassist
Posts: 114
Joined: Thu Mar 06, 2014 9:29 am
Location: UK

Re: Hyphenation of long words

Post by theotherbassist » Sat Feb 17, 2018 6:32 pm

jacque wrote:
Sat Feb 17, 2018 6:03 pm
I wouldn't use parsing rules, it's not only slower but too prone to error.
Just as I feared. Soo... anyone know of a great free hyphenation dictionary? Haha. Just kidding, I'll start digging around.

I may also experiment with text resizing, though that wouldn't be ideal as it doesn't solve the comprehension issue.

Thanks everyone.

bogs
Posts: 2377
Joined: Sat Feb 25, 2017 10:45 pm

Re: Hyphenation of long words

Post by bogs » Sat Feb 17, 2018 8:30 pm

theotherbassist wrote:
Sat Feb 17, 2018 6:01 pm
richmond62 wrote:
Sat Feb 17, 2018 5:21 pm

2. My first master's degree is in Linguistics
My first master's degree is in psych. But as my second is in ethics, I have too many qualms about the first to properly manipulate anyone and must instead dabble in linguistics :P
Oh I liked that one :twisted:
Image

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5625
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Hyphenation of long words

Post by dunbarx » Sat Feb 17, 2018 10:46 pm

I am misunderstanding something. Is it not the case that hyphenation only need occur when the word in question is at the end of a line? And that the goal is to more evenly space the text?

Or is it just that you want to hyphenate for readability? Or for fun, or some other sinister purpose?

If the first, what I consider the "normal" case, much more than just splitting words properly will be required to reformat a block of text.

But which way?

Craig Newman

bogs
Posts: 2377
Joined: Sat Feb 25, 2017 10:45 pm

Re: Hyphenation of long words

Post by bogs » Sat Feb 17, 2018 10:52 pm

dunbarx wrote:
Sat Feb 17, 2018 10:46 pm
... or some other sinister purpose?
Ooo, that made my spine tingle :twisted:
Image

theotherbassist
Posts: 114
Joined: Thu Mar 06, 2014 9:29 am
Location: UK

Re: Hyphenation of long words

Post by theotherbassist » Sun Feb 18, 2018 6:55 pm

dunbarx wrote:
Sat Feb 17, 2018 10:46 pm
Or is it just that you want to hyphenate for readability? Or for fun, or some other sinister purpose?
Craig Newman
The sinister purpose :evil: is a speed reading app, which displays only word at a time on-screen. It's been done before... many times since the '70s in fact... and I've even done this before on a very basic level. I'm able to read around 800-1000 wpm when displaying the text sequentially in a mock-up. Comprehension is very good as well--so long as there aren't any words longer than about 10 characters... or numbers with a lot of digits...

Hyphenation would just get rid of the long-words problem by breaking everything up.

I first dynamically sized longer words to fit with code (it's easy to pre-calculate the max textSize for a given character length and card width if you use a monospaced font) but unsurprisingly this didn't help.

Also tried leaving words up on screen for a time proportional to their character lengths, but this broke up the rhythmic nature of the speed reading and wasn't for me.

So hyphenation seems the natural solution. But I haven't been able to find an adequate dictionary so far.

MaxV
Posts: 1542
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Hyphenation of long words

Post by MaxV » Mon Feb 19, 2018 3:41 pm

My function:
########CODE to copy and paste with you mouse#######
function hypnen tText, tSize #all the text, the max number of char of each line
put empty into text2
put 1 into lineC #line count
repeat for each word tWord in tText
put (the number of chars of tWord) + (the number of chars of the line lineC of text2) + 1 into tLline #lenght og the cirrent line
if tLLine < tSize then
put tWord & space after text2
else
put tLLINE - tSize into tDiff
##check
repeat with i=tDiff down to 0
put char 1 to i of tWord into testw
put char (i+1) to -1 of tWord into endtestw
if (char 1 of endtestw is not among the chars of "aeiou") and (char -2 of testw is among the chars of "aeiou") then
put char 1 to i of tWord & "-" & return after text2
put char (i+1) to -1 of tWord & space after text2
add 1 to lineC
exit repeat
end if
if i=0 then
put return & tword & space after text2
add 1 to lineC
end if
end repeat
##end check
end if
end repeat
return text2
end hypnen
#####END OF CODE generated by this livecode app: http://tinyurl.com/j8xf3xq with livecode 9.0.0-dp-11#####

It's not perfect, but it's very close to a good hyphen :wink: .
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”