當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。