Does nice_number work or is it broken?


#1

hi there I being trying to get nice number to work for me but no luck with suggestion from gez-mycroft processing a file that looks like this with a code that looks like that …

`
Ingredients
10 hard-cooked eggs, chopped
6 slices crispy cooked bacon, chopped
1/3 cup creamy salad dressing such as Miracle Whip®, or more
to taste
1/4 cup chopped red onion
2 tablespoons Dijon mustard
1 tablespoon honey mustard
1 tablespoon chopped fresh chives
1 teaspoon lemon juice
1 1/2 teaspoon dill
1/2 teaspoon seasoned salt
6 Kaiser rolls, split

for cnt, line in enumerate(fp):
                     regex = '({\d}* {\d}+\/{\d}+)'
                     fraction = re.search(regex, line)
                     if not fraction:
                         self.speak("{}".format(line))
                         continue
                     formatted_line = re.sub(regex, nice_number(fraction.group(1)), line)
                     self.speak("{}".format(formatted_line))

it output this error when it reaches a interger ie: 10 in this case

File "/home/stephen/mycroft-core/mycroft/skills/core.py", line 1075, in wrapper handler(message) File "/opt/mycroft/skills/recipe-library-skill/__init__.py", line 334, in handle_pick_snrecipe formatted_line = re.sub(regex, nice_number(fraction.group(1)), line) File "/home/stephen/mycroft-core/mycroft/util/format.py", line 262, in nice_number return nice_number_en(number, speech, denominators) File "/home/stephen/mycroft-core/mycroft/util/lang/format_en.py", line 38, in nice_number_en result = convert_to_mixed_fraction(number, denominators) File "/home/stephen/mycroft-core/mycroft/util/lang/format_common.py", line 37, in convert_to_mixed_fraction frac_number = abs(number - int_number) TypeError: unsupported operand type(s) for -: 'str' and 'int'

if I change the integer 10 to a fraction 1/4

then it crash with this error
File "/home/stephen/mycroft-core/mycroft/skills/core.py", line 1075, in wrapper handler(message) File "/opt/mycroft/skills/recipe-library-skill/__init__.py", line 334, in handle_pick_snrecipe formatted_line = re.sub(regex, nice_number(fraction.group(1)), line) File "/home/stephen/mycroft-core/mycroft/util/format.py", line 262, in nice_number return nice_number_en(number, speech, denominators) File "/home/stephen/mycroft-core/mycroft/util/lang/format_en.py", line 38, in nice_number_en result = convert_to_mixed_fraction(number, denominators) File "/home/stephen/mycroft-core/mycroft/util/lang/format_common.py", line 33, in convert_to_mixed_fraction int_number = int(number) ValueError: invalid literal for int() with base 10: '1/4 '

if I try decimal based it gives the same error as the the first example

   TypeError: unsupported operand type(s) for -: 'str' and 'int'  

thank you for your help


#2

Maybe this site can help you figure out the problem.


#3

Ah looks like it’s expecting a float.

You can use

from mycroft.util.parse import extract_number

extract_number(fraction.group(1)) 

This should take “1/2” and return “0.5”


#4

thank you kindly I will try that - i just have to reload a copy again Had a bunch of trouble yesterday and deleted all my skills yesterday from my test rig


#5

still not working – but it seams from the documents that can find nice_number and extract number are not for that purpose. it to convert a float into word and or fraction - so it seams that mycroft should understand a fraction… and probably explains why occasionally it says it as a fraction.

the bit about nice_number

This function formats a float to human understandable functions. Like 4.5 
becomes 4 and a half for speech and 4 1/2 for text :param number: the 
float  to format :type number: int or float :param lang: code for the 
language to use : type lang: str :param speech: format for speech (True) or
display (False) : type speech: bool :param denominators: denominators to
use, default [1 .. 20] :type denominators: iter of ints 

oh well just it a little broke currently… just like i noticed if i use British voice and it comes across a uppercased text ie STONEHENGE it read as such properly , but the American voice will spell it out , it spells out all capitalize words… which is a little annoying in my ebook reader,


#6

Yeah the uppercase spelling was an intentional decision as it seems to be the right choice in the majority of cases. For example we don’t usually write A.P.I however we do want it to be pronounced as an acronym.

Is all the text uppercase, or just specific words for emphasis or something?


#7

well for most written DOCs/books titles and chapters are capitalized. and so are places when say the subjects in the book are reading the name of a place off a sign then others are emphasizing and shouting/yelling. perhaps have a dictionary search of some form that looks for the pronunciation of capitalized words … as I would say perhaps for computer stuff alot of stuff is pronounced as A-P-I but in real world I would say is pronounced phonetically ie SWIFT NOAA NASA INSTEX… or I guess if you want to cheat words 3 characters and under you spell out words over 3 you say phonetically as I personally at the moment I can not think of any acronym that over 3 characters that is spelt out instead of saying it phonetically


#8

That does sound like a sensible approach. If you have time, it would be good to add this as a feature request in the issues on the Mimic 2 repo.