<commit_before>"""Miscellaneous tools for data parsing."""

import re
from typing import Tuple


def parse_spec(species: str) -> Tuple[str, int]:
    """Parse a species string into its element and charge."""
    ele = re.match(r"[A-Za-z]+", species).group(0)

    charge_match = re.search(r"\d+", species)
    charge = int(charge_match.group(0)) if charge_match else 0

    if '-' in species:
        charge *= -1

    return ele, charge


def get_sign(charge: int) -> str:
    """Get string representation of a number's sign.

    Args:
        charge: The number whose sign to derive.

    Returns:
        Sign; either '+', '-' or '' for neutral.

    """
    if charge > 0:
        return '+'
    elif charge < 0:
        return '-'
    else:
        return ''
<commit_msg>`unparse_spec` utility<commit_after>"""Miscellaneous tools for data parsing."""

import re
from typing import Tuple


def parse_spec(species: str) -> Tuple[str, int]:
    """Parse a species string into its element and charge."""
    ele = re.match(r"[A-Za-z]+", species).group(0)

    charge_match = re.search(r"\d+", species)
    charge = int(charge_match.group(0)) if charge_match else 0

    if '-' in species:
        charge *= -1

    return ele, charge


def unparse_spec(species: Tuple[str, int]) -> str:
    """Unparse a species into a string representation.

    The analogue of :func:`parse_spec`.

    """
    return f"{species[0]}{abs(species[1])}{get_sign(species[1])}"


def get_sign(charge: int) -> str:
    """Get string representation of a number's sign.

    Args:
        charge: The number whose sign to derive.

    Returns:
        Sign; either '+', '-' or '' for neutral.

    """
    if charge > 0:
        return '+'
    elif charge < 0:
        return '-'
    else:
        return ''

{'fraction_non_alphanumeric': 0.14157806379406826, 'fraction_numerical': 0.008393956351426972, 'mean_word_length': 2.6121212121212123, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, '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': '7575340', 'n_tokens_mistral': 593, 'n_tokens_neox': 548, 'n_words': 179}