How to use the titlecase.titlecase function in titlecase

To help you get started, we’ve selected a few titlecase examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jclgoodwin / bustimes.org / timetables / txc.py View on Github external
def set_description(self, description):
        if description.isupper():
            description = titlecase(description)
        elif ' via ' in description and description[:description.find(' via ')].isupper():
            parts = description.split(' via ')
            parts[0] = titlecase(parts[0])
            description = ' via '.join(parts)
        self.description = correct_description(description)

        self.via = None
        self.description_parts = list(map(sanitize_description_part, self.description.split(' - ')))
        if ' via ' in self.description_parts[-1]:
            self.description_parts[-1], self.via = self.description_parts[-1].split(' via ', 1)
github DCASE-REPO / dcase_util / dcase_util / tools / bibtex.py View on Github external
abbr_list += ['ASC', 'SED']

            if word.upper() in abbr_list:
                return word_prefix + '{'+word.upper()+'}' + word_postfix

            if word.upper().endswith('S'):
                if word[:-1].upper() in abbr_list:
                    return word_prefix + '{' + word[:-1].upper() + 's}' + word_postfix

            if '-' in word:
                word_list = []
                for w in word.split('-'):
                    if w.upper() in abbr_list:
                        word_list.append('{' + w.upper() + '}')
                    else:
                        word_list.append(titlecase(w))

                return '-'.join(word_list) + word_postfix

            mixed_list = ['FrameCNN', 'LightGBM']
            mixed_list_upper = []
            for i in mixed_list:
                mixed_list_upper.append(i.upper())
            if word.upper() in mixed_list_upper:
                return word_prefix + '{' + mixed_list[mixed_list_upper.index(word.upper())] + '}' + word_postfix

            # titlecase library implements AP-style (where all shorter than 4 letter words are not capitalized)
            # let's make exception for "with"
            lower_exceptions = ['with', 'WITH']
            if word in lower_exceptions:
                return word_prefix + word.lower() + word_postfix
github censusreporter / census-table-metadata / process_merge.py View on Github external
def clean_table_name(table_name):
    """ title case, strip bogus white space, a few observed direct fixes for title casing..."""
    table_name = re.sub(r'\s+', ' ', table_name) # some have multiple white spaces
    table_name = titlecase(table_name.lower())
    for problem,fix in TABLE_NAME_REPLACEMENTS:
        table_name = re.sub(problem,fix,table_name)
    return table_name.strip()
github jclgoodwin / bustimes.org / busstops / management / commands / import_ni_services.py View on Github external
def handle_route_description(cls, line):
        assert line[2:3] == 'N'

        operator = line[3:7].strip().upper()
        route_number = line[7:11].strip().upper()
        # route_direction = line[11:12]
        route_description = line[12:].strip()
        if route_description.isupper():
            route_description = titlecase(route_description)

        service_code = route_number + '_' + operator
        cls.service_code = service_code

        if service_code not in cls.services:
            cls.services[service_code] = {'O': {}, 'I': {}}
            defaults = {
                'region_id': 'NI',
                'date': '2016-11-01',
                'line_name': route_number,
                'description': route_description,
                'mode': 'bus',
                'show_timetable': True,
                'current': True
            }
            service = Service.objects.update_or_create(service_code=service_code, defaults=defaults)[0]
github ebmdatalab / openprescribing / openprescribing / common / utils.py View on Github external
def nhs_titlecase(words):
    if words:
        title_cased = titlecase(words, callback=nhs_abbreviations)
        words = re.sub(r"Dr ([a-z]{2})", "Dr \1", title_cased)
    return words
github mattstevens / sublime-titlecase / Smart Title Case.py View on Github external
def run(self, edit):
        for region in self.view.sel():
            if region.empty():
                region = self.view.line(region)

            s = self.view.substr(region)
            s = titlecase(s)
            self.view.replace(edit, region, s)
github jclgoodwin / bustimes.org / busstops / management / commands / import_stops.py View on Github external
defaults['locality_id'] = row['NptgLocalityRef']
            if not Locality.objects.filter(pk=defaults['locality_id']).exists():
                Locality.objects.create(pk=defaults['locality_id'], admin_area_id=defaults['admin_area_id'])

        for django_field_name, naptan_field_name in self.field_names:
            if naptan_field_name not in row:
                naptan_field_name += '_lang_en'
            if naptan_field_name not in row:
                continue
            value = row[naptan_field_name].strip()
            if django_field_name in ('street', 'crossing', 'landmark', 'indicator', 'common_name'):
                if value.lower() in ('-', '--', '---', '*', 'tba', 'unknown', 'n/a',
                                     'data unavailable'):
                    value = ''
                elif django_field_name != 'indicator' and value.isupper() and value != 'YMCA':
                    value = titlecase(value)
            defaults[django_field_name] = value.replace('`', '\'')  # replace backticks

        if defaults.get('indicator').lower() in INDICATORS_TO_REPLACE:
            defaults['indicator'] = INDICATORS_TO_REPLACE.get(
                defaults['indicator'].lower()
            )
        elif defaults['indicator'].lower() in INDICATORS_TO_PROPER_CASE:
            defaults['indicator'] = INDICATORS_TO_PROPER_CASE.get(
                defaults['indicator'].lower()
            )
        elif defaults['indicator'].startswith('220'):
            defaults['indicator'] = ''

        if defaults['stop_type'] == 'class_undefined':
            defaults['stop_type'] = ''
        if defaults['bus_stop_type'] == 'type_undefined':
github jdumas / autobib / nomenclature.py View on Github external
text (str): input string to convert.

    Returns:
        A titlecased version of the input string.
    """
    def abbreviations(word, **_kwargs):
        if word.upper() in config.uppercase_words:
            return word.upper()
        if word.lower() in config.lowercase_words:
            return word.lower()
        for s in config.mixedcase_words:
            if word.lower() == s.lower():
                return s
        if word and word[0] in ['\\', '$']:
            return word
    return titlecase.titlecase(text, callback=abbreviations)
github shacker / django-todo / todo / management / commands / hopper.py View on Github external
def gen_title(tc=True):
    # faker doesn't provide a way to generate headlines in Title Case, without periods, so make our own.
    # With arg `tc=True`, Title Cases The Generated Text
    fake = Faker()
    thestr = fake.text(max_nb_chars=32).rstrip(".")
    if tc:
        thestr = titlecase(thestr)

    return thestr
github censusreporter / census-table-metadata / table_parse.py View on Github external
def build_pretty_table():
    x = []
    for table_id, table_name, universe, subject_area in load_rows():
        table_id = table_id.strip()     
        table_name = clean_table_name(table_name)
        simple_name = simplified_table_name(table_name)
        universe = titlecase(fix_universe(universe.lower()))
        topics = build_topics(table_name,subject_area)
        topics = '|'.join(topics)
        x.append([table_id,table_name,simple_name,universe,topics])
    return x