Closed MarkRx closed 3 years ago
@LexiconCode this is a limitation with the dragonfly class that @mrob95 created. I don't think we should address this one in caster, except to properly document the usage. @mrob95 is there potential to modify ShortIntegerRef in dragonfly to allow for longer single-digit utterances?
Would be best to switch it to IntegerRef.
IntegerRef is less general than ShortIntegerRef. ShortIntegerRef is IntegerRef (where you can say "one thousand two hundred and thirty four" with the added feature that you can say "one two three four" for numbers up to 9999
The following parses free dictation to output a single number. Perhaps this can be used as replacement as it is at least as flexible if not more for Python 3.
import re
from text_to_num import text2num
from text_to_num import alpha2digit
def words_to_num(numdict):
print("Raw:{} ".format(numdict))
text_list = numdict.replace(r"\number", "").split() # Remove substring "\number" from DPI formatting
transform_dict = {'one': '1', 'and': '', 'dot':'.', 'oh': 'zero', 'nintey': 'ninety'}
try:
#Simple: words to numbers `five hundred sixty three`
numb = text2num(numdict, "en")
print("text2num:{} ".format(numdict))
except ValueError:
# Reduces complex dictation down to just numerics as a single number
for index, word in enumerate(text_list):
if word in transform_dict.keys():
text_list[index] = transform_dict[word]
text = ' '.join(map(str, text_list))
print("PreProcessed:{} ".format(text))
numb =''.join(re.findall(r"[\d./\-\+]", alpha2digit(text, "en")))
print("Final: {}".format(numb))
#Text(str(numb)).execute()
words_to_num("One zero two three eight")
print(10238)
words_to_num("ten thousand two hundred thirty eight")
print(10238)
words_to_num("ten thousand two hundred and thirty eight")
print(10238)
words_to_num("ten two thirty eight")
print(10238)
words_to_num("one oh two thirty eight dot seven five")
print(10238.75)
words_to_num("one hundred two thirty eight point seventy five")
print(10238.75)
words_to_num("one million two hundred seven thousand eight hundred nintey")
print(1207890)
I can't tell because I don't have text_to_num
locally. Do these work?
One zero two three eight
10238
Ten thousand two hundred thirty eight
10238
Ten thousand two hundred and thirty eight
10238
Ten two thirty eight
10238
One oh two thirty eight dot seven five
10238.75
One hundred two thirty eight point seventy five
10238.75
One million two hundred seven thousand eight hundred nintey
1207890
@MarkRx
1 zero two three eight
numb: 10238
10238
ten thousand two hundred thirty eight
text2num:10238
10238
ten thousand two hundred thirty eight
text2num:10238
10238
ten two thirty eight
numb: 10238
10238
1 zero two thirty eight . seven five
numb: 10238.75
10238.75
1 hundred two thirty eight point seventy five
numb: 110238.75
10238.75
1 million two hundred seven thousand eight hundred ninety
numb: 1207890
1207890
The edge cases have been worked out above. It could allow for operators as well.
ten thousand + two hundred thirty eight
numb: 10000+238
However there are still two edge cases.
num 5+7
yields 5+++++++
which is a part of the punctuation rule. Which produces the + 7 times.Extraneous my cat
1 million two my cat hundred seven thousand eight hundred ninety
alpha2digit: 1 million 2 my cat 107890
numb: 12107890
1207890
@MarkRx @kendonB I have a fix for this in https://github.com/dictation-toolbox/Caster/pull/878 utilizing Dragon's native ShortIntegerRef which allows for greater flexibility than IntegerRef.
Should be fixed, reopen if there's issues.
The following parses free dictation to output a single number. Perhaps this can be used as replacement as it is at least as flexible if not more for Python 3...
Should be fixed, reopen if there's issues.
Is this only fixed if you use Python 3? I'm using Python 2 and I can still reproduce the issue. The following line is what prints if I say numb 1 2 3 4 5 6 7 8 9
:
1234seven eight nine
The caster status window prints:
Numbers: [
] numb , , 1234 Navigation: ( | | ) [(bow|bowel)] [brunt], 6, 0, 6, 0, seven eight
Additional information:
Python 2.7.18
Running DNS/DPI from Dragonfly CLI with Natlink. DPI version 15
My version.py
file says __version__ = "1.7.0"
Describe the bug When using "numb" I am only able to dictate up to 4 numbers. The 5th one is always chopped off.
This might be an issue with how dragonfly deals with numbers.
To Reproduce Steps to reproduce the behavior (be sure to include the exact command phrase you are using):
Expected behavior Output is 12345
System: