<commit_before># Copyright 2013 <NAME>
# Licensed under the MIT license

import re

from ..lib import *
from ..ent import Message
from .base import Plugin

class Highbrow(Plugin):
    """Gathers metrics related to how intelligent the conversation (or users)
    may be, like swear words used, etc."""

    # a mapping of swears to regexes that match the variants of the word
    swears = {
        'crap': r'crap(s|py|ped)',
        'shit': r'shits?',
        'fuck': r'fuck(s?|ing|ed)',
        'damn': r'damn(n?it|ed)',
        'hell': r'hell',
    }

    # this regex fragment wraps every swear regex
    swear_regex = r'\b%s\b'

    def process_message(self, message):
        if is_bot(message) or not message.content:
            return

        nick = message.nick
        content = message.content.lower()

        if self._swears is None:
            self._swears = {swear: re.compile(self.swear_regex % regex)
                            for swear, regex in self.swears.items()}

        swears = {swear: len(regex.findall(content))
                  for swear, regex in self._swears.items()}
<commit_msg>Add total swear count to highbrow plugin<commit_after># Copyright 2013 <NAME>
# Licensed under the MIT license

import re

from ..lib import *
from ..ent import Message
from .base import Plugin

class Highbrow(Plugin):
    """Gathers metrics related to how intelligent the conversation (or users)
    may be, like swear words used, etc."""

    # a mapping of swears to regexes that match the variants of the word
    swears = {
        'crap': r'crap(s|py|ped)',
        'shit': r'shits?',
        'fuck': r'fuck(s?|ing|ed)',
        'damn': r'damn(n?it|ed)',
        'hell': r'hell',
    }

    # this regex fragment wraps every swear regex
    swear_regex = r'\b%s\b'

    def process_message(self, message):
        if is_bot(message) or not message.content:
            return

        nick = message.nick
        content = message.content.lower()

        if self._swears is None:
            self._swears = {swear: re.compile(self.swear_regex % regex)
                            for swear, regex in self.swears.items()}

        swears = {swear: len(regex.findall(content))
                  for swear, regex in self._swears.items()}
        swears['total'] = sum(swears.values())

{'fraction_non_alphanumeric': 0.1154513888888889, 'fraction_numerical': 0.003472222222222222, 'mean_word_length': 2.3649635036496353, 'pattern_counts': {'":': 0, '<': 5, '<?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': '330553', 'n_tokens_mistral': 716, 'n_tokens_neox': 692, 'n_words': 224}