<commit_before>import GDPRUserList from '../utils/GDPRUserList';

const accountsToRemove = GDPRUserList;

const filterAccounts = stateAccounts =>
    Object.keys(stateAccounts)
        .filter(name => !accountsToRemove.includes(name))
        .reduce(
            (acc, cur) => ({
                ...acc,
                [cur]: stateAccounts[cur],
            }),
            {}
        );

const filterContent = stateContent => {
    const contentToRemove = Object.keys(stateContent).filter(key =>
        accountsToRemove.includes(stateContent[key].author)
    );

    const contentToKeep = Object.keys(stateContent).filter(
        key => !accountsToRemove.includes(stateContent[key].author)
    );

    // First, remove content authored by GDPR users.
    const removedByAuthor = contentToKeep.reduce(
        (acc, cur) => ({
            ...acc,
            [cur]: stateContent[cur],
        }),
        {}
    );

    // Finally, remove GDPR-authored replies referenced in other content.
    return Object.keys(removedByAuthor).reduce(
        (acc, cur) => ({
            ...acc,
            [cur]: {
                ...removedByAuthor[cur],
                replies: removedByAuthor[cur].replies.filter(
                    url => !contentToRemove.includes(url)
                ),
            },
        }),
        {}
    );
};

export default function stateCleaner(state) {
    return {
        ...state,
        accounts: filterAccounts(state.accounts),
        content: filterContent(state.content),
    };
}<commit_msg>name fns specific to gdpr<commit_after>import GDPRUserList from '../utils/GDPRUserList';

const accountsToRemove = GDPRUserList;

const gdprFilterAccounts = stateAccounts =>
    Object.keys(stateAccounts)
        .filter(name => !accountsToRemove.includes(name))
        .reduce(
            (acc, cur) => ({
                ...acc,
                [cur]: stateAccounts[cur],
            }),
            {}
        );

const gdprFilterContent = stateContent => {
    const contentToRemove = Object.keys(stateContent).filter(key =>
        accountsToRemove.includes(stateContent[key].author)
    );

    const contentToKeep = Object.keys(stateContent).filter(
        key => !accountsToRemove.includes(stateContent[key].author)
    );

    // First, remove content authored by GDPR users.
    const removedByAuthor = contentToKeep.reduce(
        (acc, cur) => ({
            ...acc,
            [cur]: stateContent[cur],
        }),
        {}
    );

    // Finally, remove GDPR-authored replies referenced in other content.
    return Object.keys(removedByAuthor).reduce(
        (acc, cur) => ({
            ...acc,
            [cur]: {
                ...removedByAuthor[cur],
                replies: removedByAuthor[cur].replies.filter(
                    url => !contentToRemove.includes(url)
                ),
            },
        }),
        {}
    );
};

export default function stateCleaner(state) {
    return {
        ...state,
        accounts: gdprFilterAccounts(state.accounts),
        content: gdprFilterContent(state.content),
    };
}
{'fraction_non_alphanumeric': 0.12815533980582525, 'fraction_numerical': 0.0, 'mean_word_length': 1.918791312559018, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '5976084', 'n_tokens_mistral': 862, 'n_tokens_neox': 848, 'n_words': 154}