Page 1 of 1

Fractions

Posted: Sat May 02, 2015 10:16 am
by andergraph
I have everything pretty much set up for what I need. Can you provide a Regular Expression code for allowing TA to read fractions correctly? Such as 7/8, 1/2, 5/8.
Thanks

Re: Fractions

Posted: Mon May 04, 2015 11:30 am
by Jim Bretti
To really pronounce the fractions correctly I think you're going to need several regular expressions. Maybe someone else will have some better ideas, but here is what I'm thinking.

1/2, 1/3 and 2/3 would probably work best with one dictionary entry for each fraction. So for these you could use regular expressions or simple text matches, but here are regular expression:

\b1/2\b
one half

\b1/3\b
one third

\b2/3\b
two thirds

Now add another expression, after the above expressions, to handle all fractions of the form 1/n. Should be able to pronounce these as 1 nth, like this:

\b1/(\d{1,2})\b
1 $1th

At this point, if the numerator is > 1, the extra 's' makes things tricky. (2 5ths, 3 7ths, etc). In general I could not get a string like 2 5ths to be pronounced correctly. So I needed individual expressions to substitute the words fourths, fifths, sixths, and so on, like this:

\b([2-9])/4\b
$1 fourths

\b([2-9])/5\b
$1 fifths

So maybe start off with these, and experiment some. You may be able find a way to consolidate the fourths / fifths / sixths expressions. It may depend on the voice you're using as well.

Re: Fractions

Posted: Wed Jun 03, 2015 2:37 pm
by Quantum
I normally pronounce fractions like n1/n2 as "n1 over n2"
For this a simple regex suffices :

regular expression (\d+)[/](\d+)
pronounce as $1 over $2

Hope this helps!

Quantum aka DaveH