当前位置: 首页>>代码示例>>Python>>正文


Python titlecase.titlecase方法代码示例

本文整理汇总了Python中titlecase.titlecase方法的典型用法代码示例。如果您正苦于以下问题:Python titlecase.titlecase方法的具体用法?Python titlecase.titlecase怎么用?Python titlecase.titlecase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在titlecase的用法示例。


在下文中一共展示了titlecase.titlecase方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: maybe_recapitalize_title

# 需要导入模块: import titlecase [as 别名]
# 或者: from titlecase import titlecase [as 别名]
def maybe_recapitalize_title(title):
    """
    Recapitalize a title if it is mostly uppercase
    (number of uppercase letters > number of lowercase letters)

    >>> maybe_recapitalize_title('THIS IS CALLED SCREAMING')
    'This Is Called Screaming'
    >>> maybe_recapitalize_title('This is just a normal title')
    'This is just a normal title'
    >>> maybe_recapitalize_title('THIS IS JUST QUITE Awkward')
    'THIS IS JUST QUITE Awkward'
    """
    nb_upper, nb_lower = 0, 0
    for letter in title:
        if letter.isupper():
            nb_upper += 1
        elif letter.islower():
            nb_lower += 1

    if nb_upper > nb_lower:
        return titlecase(title)
    else:
        return title

# HTML sanitizing for the title 
开发者ID:dissemin,项目名称:dissemin,代码行数:27,代码来源:utils.py

示例2: prettify

# 需要导入模块: import titlecase [as 别名]
# 或者: from titlecase import titlecase [as 别名]
def prettify(value):

    """
    Prettify a field value for display.

    Args:
        value (str)

    Returns: str
    """

    punct = set(list(string.punctuation + string.whitespace))

    # Strip everything off left side.
    value = value.lstrip(''.join(punct))

    # Allow ), ], and . on right.
    value = value.rstrip(''.join(punct - set(list(')].'))))

    # Strip '.' unless last character is uppercase.
    if not re.search('\s[a-z]{1}\.$', value, re.I):
        value = value.rstrip('.')

    return titlecase(value) 
开发者ID:davidmcclure,项目名称:open-syllabus-project,代码行数:26,代码来源:utils.py

示例3: race

# 需要导入模块: import titlecase [as 别名]
# 或者: from titlecase import titlecase [as 别名]
def race(self, text):
        if not text:
            return None

        text = text.upper()

        if text in RACE_LOOKUP:
            return titlecase(RACE_LOOKUP[text])
        else:
            return titlecase(text) 
开发者ID:codeforamerica,项目名称:comport,代码行数:12,代码来源:cleaners.py

示例4: sex

# 需要导入模块: import titlecase [as 别名]
# 或者: from titlecase import titlecase [as 别名]
def sex(self, text):
        if not text:
            return None

        text = text.upper()

        if text in GENDER_LOOKUP:
            return titlecase(GENDER_LOOKUP[text])
        else:
            return titlecase(text) 
开发者ID:codeforamerica,项目名称:comport,代码行数:12,代码来源:cleaners.py

示例5: capitalize

# 需要导入模块: import titlecase [as 别名]
# 或者: from titlecase import titlecase [as 别名]
def capitalize(self, value):
        def abbreviations(word, **kwargs):
            upd = word.upper()
            if upd in CAPITALIZE_LIST or upd.lstrip("(").rstrip(")") in CAPITALIZE_LIST:
                return upd

        if type(value) is not str:
            return value
        return titlecase(value.strip().lower(), callback=abbreviations) 
开发者ID:codeforamerica,项目名称:comport,代码行数:11,代码来源:cleaners.py

示例6: test_capitalization

# 需要导入模块: import titlecase [as 别名]
# 或者: from titlecase import titlecase [as 别名]
def test_capitalization(self):
        ''' A phrase is title-cased with expected exceptions.
        '''
        cleaner = Cleaners()
        in_sentence = "I thought I would sail about a little and see the watery part of the world"
        titlecased_sentence = titlecase(in_sentence)
        send = " ".join(i.lower() + " " + j.lower() for i, j in zip(in_sentence.split(" "), CAPITALIZE_LIST))
        check = " ".join(i + " " + j for i, j in zip(titlecased_sentence.split(" "), CAPITALIZE_LIST))
        result = cleaner.capitalize(send)
        assert check == result 
开发者ID:codeforamerica,项目名称:comport,代码行数:12,代码来源:test_cleaners.py

示例7: test_capitalization_inside_parentheses

# 需要导入模块: import titlecase [as 别名]
# 或者: from titlecase import titlecase [as 别名]
def test_capitalization_inside_parentheses(self):
        ''' Words are left titlecased even if they're inside parentheses
        '''
        cleaner = Cleaners()
        in_sentence = "I thought I would sail about a little and see the watery part of the world"
        titlecased_sentence = titlecase(in_sentence)
        send = " ".join(i.lower() + " (" + j.lower() + ")" for i, j in zip(in_sentence.split(" "), CAPITALIZE_LIST))
        check = " ".join(i + " (" + j + ")" for i, j in zip(titlecased_sentence.split(" "), CAPITALIZE_LIST))
        result = cleaner.capitalize(send)
        assert check == result 
开发者ID:codeforamerica,项目名称:comport,代码行数:12,代码来源:test_cleaners.py

示例8: og_description

# 需要导入模块: import titlecase [as 别名]
# 或者: from titlecase import titlecase [as 别名]
def og_description(self) -> str:
        p = inflect.engine()
        fmt = titlecase.titlecase(p.a(self.format_name))
        description = '{fmt} match.'.format(fmt=fmt)
        return description 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:7,代码来源:match_view.py

示例9: normalize

# 需要导入模块: import titlecase [as 别名]
# 或者: from titlecase import titlecase [as 别名]
def normalize(d: Deck) -> str:
    try:
        name = d.original_name
        name = name.lower()
        name = replace_space_alternatives(name)
        name = remove_extra_spaces(name)
        name = remove_pd(name)
        name = remove_hashtags(name)
        name = remove_brackets(name)
        name = strip_leading_punctuation(name)
        name = remove_leading_deck(name)
        name = remove_extraneous_hyphens(name)
        unabbreviated = expand_common_abbreviations(name)
        if unabbreviated != name or name in ABBREVIATIONS.values():
            name = unabbreviated
        elif whitelisted(name):
            pass
        elif name and d.get('archetype_name') and name == d.get('archetype_name', '').lower():
            pass
        else:
            name = remove_profanity(name)
            name = add_colors_if_no_deckname(name, d.get('colors'))
            name = normalize_colors(name, d.get('colors'))
            name = add_archetype_if_just_colors(name, d.get('archetype_name'))
            name = remove_mono_if_not_first_word(name)
        name = ucase_trailing_roman_numerals(name)
        name = titlecase.titlecase(name)
        return correct_case_of_color_names(name)
    except ValueError:
        raise InvalidDataException('Failed to normalize {d}'.format(d=repr(d))) 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:32,代码来源:deck_name.py

示例10: correct_case_of_color_names

# 需要导入模块: import titlecase [as 别名]
# 或者: from titlecase import titlecase [as 别名]
def correct_case_of_color_names(name: str) -> str:
    for k in COLOR_COMBINATIONS:
        titlecase_k = titlecase.titlecase(k)
        name = name.replace(titlecase_k, k)
    return name 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:7,代码来源:deck_name.py

示例11: og_description

# 需要导入模块: import titlecase [as 别名]
# 或者: from titlecase import titlecase [as 别名]
def og_description(self) -> str:
        if self.public() and self.archetype_name:
            p = inflect.engine()
            archetype_s = titlecase.titlecase(p.a(self.archetype_name))
        else:
            archetype_s = 'A'
        description = '{archetype_s} deck by {author}'.format(archetype_s=archetype_s, author=self.person)
        return description 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:10,代码来源:deck.py

示例12: __init__

# 需要导入模块: import titlecase [as 别名]
# 或者: from titlecase import titlecase [as 别名]
def __init__(self, person: ps.Person, cards: List[Card], archetypes: List[Archetype], all_archetypes: List[Archetype], matchups: List[Container], your_cards: Dict[str, List[str]], season_id: Optional[int]) -> None:
        super().__init__()
        min_matches_for_matchups_grid = 10
        self.all_archetypes = all_archetypes
        self.person = person
        self.people = [person]
        self.decks = person.decks
        self.archetypes = archetypes
        self.hide_person = True
        self.cards = cards
        for record in person.head_to_head:
            record.show_record = True
            record.opp_url = url_for('.person', mtgo_username=record.opp_mtgo_username)
        self.show_head_to_head = len(person.head_to_head) > 0
        self.show_seasons = True
        self.displayed_achievements = [{'title': a.title, 'detail': titlecase.titlecase(a.display(self.person))} for a in Achievement.all_achievements if a.display(self.person)]
        self.achievements_url = url_for('.achievements')
        self.person_achievements_url = url_for('.person_achievements', person_id=person.id)
        colors: Dict[str, int] = {}
        for d in self.decks:
            for c in d.colors:
                colors[c] = colors.get(c, 0) + 1
        self.charts = [
            {
                'title': 'Colors Played',
                'type': 'horizontalBar',
                'labels': json.dumps(['White', 'Blue', 'Black', 'Red', 'Green', 'Colorless']),
                'series': json.dumps([colors.get('W'), colors.get('U'), colors.get('B'), colors.get('R'), colors.get('G'), colors.get('C')]),
                'options': json.dumps({'responsive': True, 'scales': {'xAxes': [{'ticks': {'precision': 0}}]}}) # Only display whole numbers on x axis.
            }
        ]
        self.add_note_url = url_for('post_player_note')
        self.matches_url = url_for('.person_matches', person_id=person.id, season_id=season_id)
        self.is_person_page = True
        self.trailblazer_cards = your_cards['trailblazer']
        self.has_trailblazer_cards = len(self.trailblazer_cards) > 0
        self.unique_cards = your_cards['unique']
        self.has_unique_cards = len(self.unique_cards) > 0
        self.setup_matchups(self.all_archetypes, matchups, min_matches_for_matchups_grid) 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:41,代码来源:person.py

示例13: admin_menu

# 需要导入模块: import titlecase [as 别名]
# 或者: from titlecase import titlecase [as 别名]
def admin_menu() -> List[Dict[str, str]]:
    m = []
    endpoints = sorted([rule.endpoint for rule in APP.url_map.iter_rules() if 'GET' in rule.methods and rule.rule.startswith('/admin')])
    for endpoint in endpoints:
        name = titlecase.titlecase(endpoint.replace('_', ' ')) if endpoint else 'Admin Home'
        m.append({'name': name, 'endpoint': endpoint, 'url': url_for(endpoint)})
    if (rotation.next_rotation() - dtutil.now()) < datetime.timedelta(7):
        m.append({'name': gettext('Rotation Tracking'), 'endpoint': 'rotation'})
    m.append({'name': gettext('Rotation Speculation'), 'endpoint': 'rotation_speculation'})
    return m 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:12,代码来源:admin.py

示例14: titlecase

# 需要导入模块: import titlecase [as 别名]
# 或者: from titlecase import titlecase [as 别名]
def titlecase(s):
        return s.title() 
开发者ID:billzorn,项目名称:mtgencode,代码行数:4,代码来源:cardlib.py

示例15: update_field_label_titlecase

# 需要导入模块: import titlecase [as 别名]
# 或者: from titlecase import titlecase [as 别名]
def update_field_label_titlecase(self, field_num):
        """ Puts a field lable into Title Case """
        self.get_field_num_list(field_num)
        act_fields = ImportField.objects\
                                .filter(source_id=self.source_id,
                                        field_num__in=self.field_num_list)
        for act_field in act_fields:
            tc_label = titlecase(act_field.label.replace('_', ' '))
            act_field.label = tc_label
            act_field.save() 
开发者ID:ekansa,项目名称:open-context-py,代码行数:12,代码来源:describe.py


注:本文中的titlecase.titlecase方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。