Page 1 of 2

Hyphenation of long words

Posted: Sat Feb 17, 2018 1:46 pm
by theotherbassist
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?

Re: Hyphenation of long words

Posted: Sat Feb 17, 2018 2:48 pm
by richmond62
but comprehension is too low
Presumably this is your comprehension as computers cannot comprehend anything.

Re: Hyphenation of long words

Posted: Sat Feb 17, 2018 3:07 pm
by theotherbassist
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.

Re: Hyphenation of long words

Posted: Sat Feb 17, 2018 3:29 pm
by richmond62
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 10922 times
I have treated "y" as a Vowel . . .

Re: Hyphenation of long words

Posted: Sat Feb 17, 2018 5:06 pm
by theotherbassist
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.

Re: Hyphenation of long words

Posted: Sat Feb 17, 2018 5:21 pm
by richmond62
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 . . .

Re: Hyphenation of long words

Posted: Sat Feb 17, 2018 5:50 pm
by theotherbassist
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.

Re: Hyphenation of long words

Posted: Sat Feb 17, 2018 6:01 pm
by theotherbassist
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

Re: Hyphenation of long words

Posted: Sat Feb 17, 2018 6:03 pm
by jacque
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.

Re: Hyphenation of long words

Posted: Sat Feb 17, 2018 6:32 pm
by theotherbassist
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.

Re: Hyphenation of long words

Posted: Sat Feb 17, 2018 8:30 pm
by bogs
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:

Re: Hyphenation of long words

Posted: Sat Feb 17, 2018 10:46 pm
by dunbarx
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

Re: Hyphenation of long words

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

Re: Hyphenation of long words

Posted: Sun Feb 18, 2018 6:55 pm
by theotherbassist
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.

Re: Hyphenation of long words

Posted: Mon Feb 19, 2018 3:41 pm
by MaxV
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: .