예제 #1
0
def multiScriptor(thing, qty, many_thresh=7):
    if qty == 0: return 'no {} '.format(inflect.plural(thing))
    for i in range(1, many_thresh + 1):
        if qty == i:
            return '{} {} '.format(inflect.number_to_words(i),
                                   inflect.plural(thing, count=i))
    return 'many {} '.format(inflect.plural(thing))
예제 #2
0
    def clean(self, match):
        ws = match.group(2)
        number = match.group(3)
        _proceeding_symbol = match.group(7)

        time_match = TIME_CHECK.match(number)
        if time_match:
            string = ws + inflect.number_to_words(time_match.group(1)) + "{}{}"
            mins = int(time_match.group(2))
            min_string = ""
            if mins != 0:
                min_string = " " + inflect.number_to_words(time_match.group(2))
            ampm_string = ""
            if time_match.group(3):
                ampm_string = " " + time_match.group(3)
            return string.format(min_string, ampm_string)

        ord_match = ORD_CHECK.match(number)
        if ORD_CHECK.match(number):
            return ws + inflect.number_to_words(ord_match.group(0))

        if self.currency is None:
            # Check if it is a currency
            self.currency = match.group(1) or CURRENCY_CHECK.match(number)

        # Check to see if next symbol is a number
        # If it is a number and it has 3 digits, then it is probably a
        # continuation
        three_match = THREE_CHECK.match(match.group(6))
        if three_match:
            self.curr_num.append(number)
            return " "
        # Else we can output
        else:
            # Check for decimals
            whole_num = "".join(self.curr_num) + number
            decimal = None
            decimal_match = DECIMAL_CHECK.search(whole_num)
            if decimal_match:
                decimal = decimal_match.group(1)[1:]
                whole_num = whole_num[:-len(decimal) - 1]
            whole_num = re.sub(r'\.', '', whole_num)
            return ws + self.format_final_number(whole_num, decimal)
예제 #3
0
파일: cleaners.py 프로젝트: zxh263/NeMo
    def format_final_number(self, whole_num, decimal):
        if self.currency:
            return_string = inflect.number_to_words(whole_num)
            return_string += " dollar" if whole_num == 1 else " dollars"
            if decimal:
                return_string += " and " + inflect.number_to_words(decimal)
                return_string += " cent" if whole_num == decimal else " cents"
            self.reset()
            return return_string

        self.reset()
        if decimal:
            whole_num += "." + decimal
            return inflect.number_to_words(whole_num)
        else:
            # Check if there are non-numbers
            def convert_to_word(match):
                return " " + inflect.number_to_words(match.group(0)) + " "
            return re.sub(r'[0-9,]+', convert_to_word, whole_num)
예제 #4
0
 def convert_to_word(match):
     return " " + inflect.number_to_words(match.group(0)) + " "
예제 #5
0
            data.append(
                py.graph_objs.Scatter(
                    x=exchanges,
                    y=endOfRoundAverages,
                    name=fieldNames[j],
                    line=dict(
                        color=colours[colour],
                        dash=lineTypes[lineType],
                        width=1,
                    ),
                ))
            lineType += 1
            colour += 1

        # The day value is converted into the ordinal word form for styling.
        day: str = inflect.number_to_words(inflect.ordinal(daysToVisualise[i]))

        lowx = 0
        highx = 200
        if len(exchanges) > 1:
            lowx = exchanges[0]
            highx = exchanges[-1]

        # Style the graph layout
        layout: any = dict(
            title=dict(
                text='Average consumer satisfaction during the<br>' + day +
                ' day',
                xanchor='center',
                x=0.5,
            ),