<commit_before>from datetime import datetime
from .. import commands

def dump(characters, f, include_metadata=None, metadata_extra={}, **kwargs):
    """
    Create a markdown character listing

    Args:
        characters (list): Character info dicts to show
        f (stream): Output stream
        include_metadata (string|None): Whether to include metadata, and what
            format to use.What kind of metadata to include, if any. Accepts
            values of 'mmd', 'yaml', or 'yfm'. Metadata will always include a
            title and creation date.
        metadata_extra (dict): Additional metadata to insert. Ignored unless
            include_metadata is set. The keys 'title', and 'created' will
            overwrite the generated values for those keys.

    Returns:
        A commands.Result object. Openable will not be set.
    """
    if include_metadata:
        default_metadata = {
            'title': 'NPC Listing',
            'created': datetime.now().isoformat()
        }
        metadata_raw = {**default_metadata, **metadata_extra}
        if include_metadata in 'mmd':
            metadata_lines = ['{}: {}'.format(k.title(), v) for k, v in metadata_raw.items()]
            data = "  \n".join(metadata_lines)
        elif include_metadata in ('yaml', 'yfm'):
            metadata_lines = ['{}: {}'.format(k, v) for k, v in metadata_raw.items()]
            data = "---\n" + "\n".join(metadata_lines) + "\n---\n"
        else:
            return commands.Result(False, errmsg="Unrecognized metadata format option '%s'" % include_metadata, errcode=6)
        f.write(data)

    for c in characters:
        # name (header)
        realname = c['name'][0]
        f.write("# %s" % realname)
        if 'dead' in c:
            f.write(" (Deceased)")
        f.write("\n\n")

        # info block
        info_block = []

        # AKA line (info block)
        if len(c['name']) > 1:
            info_block.append('*AKA %s*' % "; ".join(c['name'][1:]))

        # character type and dependent values (info block)
        info_block.append(_build_character_type(c))

        # subtype information (info block)
        subtype = _build_character_subtype(c)
        if subtype:
            info_block.append(subtype)

        # list all groups (info block)
        secondary_groups = _build_secondary_groups(c)
        if secondary_groups:
            info_block.append('Member of %s' % secondary_groups)
<commit_msg>Add titles to character listing output<commit_after>from datetime import datetime
from .. import commands

def dump(characters, f, include_metadata=None, metadata_extra={}, **kwargs):
    """
    Create a markdown character listing

    Args:
        characters (list): Character info dicts to show
        f (stream): Output stream
        include_metadata (string|None): Whether to include metadata, and what
            format to use.What kind of metadata to include, if any. Accepts
            values of 'mmd', 'yaml', or 'yfm'. Metadata will always include a
            title and creation date.
        metadata_extra (dict): Additional metadata to insert. Ignored unless
            include_metadata is set. The keys 'title', and 'created' will
            overwrite the generated values for those keys.

    Returns:
        A commands.Result object. Openable will not be set.
    """
    if include_metadata:
        default_metadata = {
            'title': 'NPC Listing',
            'created': datetime.now().isoformat()
        }
        metadata_raw = {**default_metadata, **metadata_extra}
        if include_metadata in 'mmd':
            metadata_lines = ['{}: {}'.format(k.title(), v) for k, v in metadata_raw.items()]
            data = "  \n".join(metadata_lines)
        elif include_metadata in ('yaml', 'yfm'):
            metadata_lines = ['{}: {}'.format(k, v) for k, v in metadata_raw.items()]
            data = "---\n" + "\n".join(metadata_lines) + "\n---\n"
        else:
            return commands.Result(False, errmsg="Unrecognized metadata format option '%s'" % include_metadata, errcode=6)
        f.write(data)

    for c in characters:
        # name (header)
        realname = c['name'][0]
        f.write("# %s" % realname)
        if 'dead' in c:
            f.write(" (Deceased)")
        f.write("\n\n")

        # info block
        info_block = []

        # AKA line (info block)
        if len(c['name']) > 1:
            info_block.append('*AKA %s*' % ", ".join(c['name'][1:]))

        #  Titles line (info block)
        if 'title' in c:
            info_block.append(', '.join(c['title']))

        # character type and dependent values (info block)
        info_block.append(_build_character_type(c))

        # subtype information (info block)
        subtype = _build_character_subtype(c)
        if subtype:
            info_block.append(subtype)

        # list all groups (info block)
        secondary_groups = _build_secondary_groups(c)
        if secondary_groups:
            info_block.append('Member of %s' % secondary_groups)

{'fraction_non_alphanumeric': 0.11964285714285715, 'fraction_numerical': 0.0015873015873015873, 'mean_word_length': 2.2543576500968365, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '893530', 'n_tokens_mistral': 1425, 'n_tokens_neox': 1410, 'n_words': 437}