---
updatedAt: 2025-03-22T00:19:19.000Z
agentTools:
  projectIndex: https://docs.datastreamer.io/llms.txt
---

# Custom Function: Informal and Misspelling Detection

```python Python
import nltk
from nltk.tokenize import word_tokenize
from nltk.corpus import words
nltk.download("words")
nltk.download("punkt")
nltk_vocab = set(words.words())

def detect_informal(text):
    if not text:
        return []
    try:
        if len(text) > 300:
            text = text[:300]  # Truncate to 300 chars
        tokens = {w.lower() for w in word_tokenize(text) if w.isalpha()}  
        unknown_tokens = tokens - nltk_vocab  # Fast set difference
        return list(unknown_tokens)  # Return unknown words directly
    
    except Exception:
        return []
 
def process_document(document):    
    body = document.get("content", {}).get("body", None)    
    if body is not None:        
        document["informal"] = detect_informal(body)
    return [document]

```

# Import NLTK and Textblob

<!-- python@1-4 -->

We use the word corpus from textblob and word tokenize functionality from these libraries.

# Get word lists

<!-- python@4-6 -->



# Detect Informat or Misspellings

<!-- python@8-19 -->



# Prcoess Document

<!-- python@21-25 -->

The Custom Function component within your Pipeline will handle the updating of your existing documents with the extracted informal or misspellings.