Skip to main content

Detects gibberish or mischievous chat messages/string.

Project description

gibberish-chat-detector

A simple Python package to detect gibberish or mischievous messages in chat logs using rule-based features.

🔍 What It Does

This package computes a set of linguistic and statistical features from a chat message and applies a customizable rule-based system to flag potentially gibberish messages.

🚀 Installation

pip install gibberish-chat-detector

🧠 How It Works

The detector extracts features such as repeated characters, punctuation patterns, token lengths, and entropy of characters and letters. These features are then checked against a list of boolean rules to determine if the message is gibberish.

✨ Features Used

The gibberish detector uses the following features:

  • repeat_letter_ratio: Proportion of alphanumeric characters that are repeated consecutively (e.g., "aaa", "111").
  • repeat_group_ratio: Proportion of repeated sequences of letters or digits (e.g., "abcabc", "1212").
  • repeat_punct: Total count of repeated punctuation symbols (e.g., "!!!", "??!!??").
  • letter_token_ratio: Fraction of characters that are alphabetic (useful for spotting symbol-heavy gibberish).
  • max_token_length: Length of the longest token (word-like unit) in the message.
  • avg_token_length: Average length of tokens in the message.
  • std_token_length: Standard deviation of token lengths, indicating variation.
  • count_token: Total number of tokens (words or fragments separated by whitespace).
  • count_total_character: Total number of non-space characters.
  • count_unique_character: Number of unique characters excluding spaces.
  • entropy_letter: Entropy (diversity) of alphabetic characters, indicating randomness or repetitiveness.
  • entropy_character: Entropy of all characters, including symbols, digits, and letters.

🧪 Example Usage

from gibberish_detector import gibberish_detector

text = "aaaaa!!!??"
result = gibberish_detector(text)

print(result["gibberish"])  # 1 if gibberish, 0 otherwise
print(result)  # All feature values

🔧 Customizing Rules

You can pass your own rule string to override the default logic. The rule string should be a Python-style list of boolean expressions using the feature names listed above.

Example:

custom_rule = '''[
    (repeat_letter_ratio >= 0.5 and max_token_length >= 6),
    (repeat_punct >= 6 and count_token < 4 and max_token_length >= 10 and letter_token_ratio <= 0.1),
    (repeat_group_ratio >= 0.5 and max_token_length >= 6),
    (max_token_length >= 16),
    (letter_token_ratio == 0 and max_token_length > 10 and count_token != 1),
    (repeat_letter_ratio == 1 or repeat_group_ratio == 1)
]'''

result = gibberish_detector("aaa!!!", rule=custom_rule)
print(result["gibberish"])

⚠️ Note: The rule string is evaluated using eval() within the context of the feature dictionary, and should only be used in trusted environments.

📬 Output Format

The function returns a dictionary with the following fields:

{
    "gibberish": 1,
    "repeat_letter_ratio": 0.8,
    "repeat_punct": 7,
    "repeat_group_ratio": 0.6,
    "max_token_length": 12,
    "avg_token_length": 6.0,
    "std_token_length": 2.3,
    "count_token": 4,
    "count_total_character": 20,
    "count_unique_character": 10,
    "letter_token_ratio": 0.3,
    "entropy_letter": 2.5,
    "entropy_character": 3.1
}

🛡️ License

MIT License

👤 Author

Developed by Jiangang Hao, June 2025

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gibberish_chat_detector-0.1.2.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gibberish_chat_detector-0.1.2-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file gibberish_chat_detector-0.1.2.tar.gz.

File metadata

  • Download URL: gibberish_chat_detector-0.1.2.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for gibberish_chat_detector-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c913c0ae1e92f2155d7ab51bc62ccb0ff5dbf989649b60f301398502a429f736
MD5 15d4412da40edb5ec0767657f9020fde
BLAKE2b-256 1d153e02f2e3f7a0879dba50d0b66936f3fd56bc94fd14594eec2888a2adc9e2

See more details on using hashes here.

File details

Details for the file gibberish_chat_detector-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for gibberish_chat_detector-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ead929f1fff0c6cb045d8f1be9c36cdd8b5e21af02f89854cbfc7549025f97f9
MD5 f7f7c719a4ed0ffcb9b52d21d7c888d6
BLAKE2b-256 cc25efe16946912507c8b8d3f49021ae058b8a209a889c79624c009d7eb98237

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page