Hyphenation of long words
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 115
- Joined: Thu Mar 06, 2014 9:29 am
- Location: UK
Hyphenation of long words
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?
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?
-
- Livecode Opensource Backer
- Posts: 9358
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Hyphenation of long words
Presumably this is your comprehension as computers cannot comprehend anything.but comprehension is too low
-
- Posts: 115
- Joined: Thu Mar 06, 2014 9:29 am
- Location: UK
Re: Hyphenation of long words
Yes, comprehension of the text by humans. Or any other species that can read, I suppose.richmond62 wrote: ↑Sat Feb 17, 2018 2:48 pmPresumably this is your comprehension as computers cannot comprehend anything.but comprehension is too low
-
- Livecode Opensource Backer
- Posts: 9358
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Hyphenation of long words
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"
I have treated "y" as a Vowel . . .
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
-
- Posts: 115
- Joined: Thu Mar 06, 2014 9:29 am
- Location: UK
Re: Hyphenation of long words
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.
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.
-
- Livecode Opensource Backer
- Posts: 9358
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Hyphenation of long words
Well:I love the idea of using linguistic rules to do it
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:
you mean to store a database of ALL possible syllables in whichever language you are analysing:to "buffer" all the syllables beforehand
I wish you well . . .
-
- Posts: 115
- Joined: Thu Mar 06, 2014 9:29 am
- Location: UK
Re: Hyphenation of long words
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.
-
- Posts: 115
- Joined: Thu Mar 06, 2014 9:29 am
- Location: UK
Re: Hyphenation of long words
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
-
- VIP Livecode Opensource Backer
- Posts: 7228
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Hyphenation of long words
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.
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
HyperActive Software | http://www.hyperactivesw.com
-
- Posts: 115
- Joined: Thu Mar 06, 2014 9:29 am
- Location: UK
Re: Hyphenation of long words
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
Oh I liked that onetheotherbassist wrote: ↑Sat Feb 17, 2018 6:01 pmMy 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
-
- VIP Livecode Opensource Backer
- Posts: 9647
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Hyphenation of long words
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
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
-
- Posts: 115
- Joined: Thu Mar 06, 2014 9:29 am
- Location: UK
Re: Hyphenation of long words
The sinister purpose 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
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 .
########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 .
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w