Example #1
0
    def spell_time(self, time, relative):
        """\
        Convert a time expression into words (assuming accusative).

        :param time: The 24hr numerical time value in a string, e.g. '8:05'
        :param relative: If true, time is interpreted as relative, i.e. \
                0:15 will generate '15 minutes' and not '0 hours and \
                15 minutes'.
        :return: Czech time string with all numerals written out as words
        """
        if ':' not in time:  # 'now' and similar
            return time
        hours, mins = map(int, time.split(':'))
        time_str = []
        if not (relative and hours == 0):
            hr_id = 'hodin' + self.HR_ENDING.get(hours, '')
            hours = word_for_number(hours, 'F4')
            time_str.extend((hours, hr_id))
        if mins == 0 and (not relative or hours != 0):
            return ' '.join(time_str)
        if time_str:
            time_str.append('a')
        min_id = 'minut' + self.HR_ENDING.get(mins, self.HR_ENDING_DEFAULT)
        mins = word_for_number(mins, 'F4')
        return ' '.join(time_str + [mins, min_id])
Example #2
0
    def spell_time(self, time, relative):
        """\
        Convert a time expression into words (assuming accusative).

        :param time: The 24hr numerical time value in a string, e.g. '8:05'
        :param relative: If true, time is interpreted as relative, i.e. \
                0:15 will generate '15 minutes' and not '0 hours and \
                15 minutes'.
        :return: Czech time string with all numerals written out as words
        """
        if ':' not in time:  # 'now' and similar
            return time
        hours, mins = map(int, time.split(':'))
        time_str = []
        if not (relative and hours == 0):
            hr_id = 'hodin' + self.HR_ENDING.get(hours, '')
            hours = word_for_number(hours, 'F4')
            time_str.extend((hours, hr_id))
        if mins == 0 and (not relative or hours != 0):
            return ' '.join(time_str)
        if time_str:
            time_str.append('a')
        min_id = 'minut' + self.HR_ENDING.get(mins, self.HR_ENDING_DEFAULT)
        mins = word_for_number(mins, 'F4')
        return ' '.join(time_str + [mins, min_id])
Example #3
0
def expand_numbers(stop_name):
    """Spell out all numbers that appear as separate tokens in the word (separated by spaces)."""
    tokens = []
    for token in stop_name.split(' '):
        if NUM_TOKEN.match(token):
            try:
                num_word = word_for_number(int(token), 'F1')
                if token.startswith('0') and len(token) > 1:
                    tokens.append('nula')
                tokens.append(num_word)
            except:
                tokens.append(token)
        else:
            tokens.append(token)
    return ' '.join(tokens)
def expand_numbers(stop_name):
    """Spell out all numbers that appear as separate tokens in the word (separated by spaces)."""
    tokens = []
    for token in stop_name.split(" "):
        if NUM_TOKEN.match(token):
            try:
                num_word = word_for_number(int(token), "F1")
                if token.startswith("0") and len(token) > 1:
                    tokens.append("nula")
                tokens.append(num_word)
            except:
                tokens.append(token)
        else:
            tokens.append(token)
    return " ".join(tokens)
Example #5
0
    def spell_temperature(self, value, interval):
        """Convert a temperature expression into words (assuming nominative).

        :param value: Temperature value (whole number in degrees as string), \
                e.g. '1' or '-10'.
        :param interval: Boolean indicating whether to treat this as a start \
                of an interval, i.e. omit the degrees word.
        :return: Czech temperature expression as string
        """
        ret = ''
        value = int(value)
        if value < 0:
            ret += 'mínus '
            value = abs(value)
        ret += word_for_number(value, 'M1')
        if not interval:
            ret += ' stup' + self.DEG_ENDING.get(value, self.DEG_ENDING_DEFAULT)
        return ret
Example #6
0
    def spell_temperature(self, value, interval):
        """Convert a temperature expression into words (assuming nominative).

        :param value: Temperature value (whole number in degrees as string), \
                e.g. '1' or '-10'.
        :param interval: Boolean indicating whether to treat this as a start \
                of an interval, i.e. omit the degrees word.
        :return: Czech temperature expression as string
        """
        ret = ''
        value = int(value)
        if value < 0:
            ret += 'mínus '
            value = abs(value)
        ret += word_for_number(value, 'M1')
        if not interval:
            ret += ' stup' + self.DEG_ENDING.get(value, self.DEG_ENDING_DEFAULT)
        return ret
Example #7
0
    def __init__(self, *args, **kwargs):
        super(PTICSSLUPreprocessing, self).__init__(*args, **kwargs)

        num_norms = []
        for num in xrange(60):
            num_norms.append(([unicode(num)], [word_for_number(num, 'F1')]))
        self.text_normalization_mapping += num_norms

        self.text_normalization_mapping += [
            (['ve'], ['v']),
            (['ke'], ['k']),
            (['ku'], ['k']),
            (['ze'], ['z']),
            # (['se'], ['s']), # do not use this, FJ
            (['barandov'], ['barrandov']),
            (['litňanská'], ['letňanská']),
            (['ípé', 'pa', 'pavlova'], ['i', 'p', 'pavlova']),
            (['í', 'pé', 'pa', 'pavlova'], ['i', 'p', 'pavlova']),
            (['čaplinovo'], ['chaplinovo']),
            (['čaplinova'], ['chaplinova']),
            (['zologická'], ['zoologická']),
        ]
Example #8
0
    def __init__(self, *args, **kwargs):
        super(PTICSSLUPreprocessing, self).__init__(*args, **kwargs)

        num_norms = []
        for num in xrange(60):
            num_norms.append(([unicode(num)], [word_for_number(num, 'F1')]))
        self.text_normalization_mapping += num_norms

        self.text_normalization_mapping += [
            (['ve'], ['v']),
            (['ke'], ['k']),
            (['ku'], ['k']),
            (['ze'], ['z']),
            # (['se'], ['s']), # do not use this, FJ
            (['barandov'], ['barrandov']),
            (['litňanská'], ['letňanská']),
            (['ípé', 'pa', 'pavlova'], ['i', 'p', 'pavlova']),
            (['í', 'pé', 'pa', 'pavlova'], ['i', 'p', 'pavlova']),
            (['čaplinovo'], ['chaplinovo']),
            (['čaplinova'], ['chaplinova']),
            (['zologická'], ['zoologická']),
        ]