Character-level similarity for overall string comparison
Semantic Relationship Detection: Words are considered related if they:
Have the same normalized form
Share a common root
Have a small edit distance (for typos)
Grouping Algorithm: Uses a threshold-based approach where strings with similarity above the threshold are grouped together.
The function can be customized by:
Adjusting the similarityThreshold parameter (0.0 to 1.0)
Expanding the StopWords set
Adding more entries to WordNormalization for better synonym handling
Modifying the weight balance between word-based and character-based similarity
This approach works well for simple semantic grouping without external dependencies, though it won't match the sophistication of modern NLP libraries that use word embeddings or transformer models.
User
Explain what you did
Assistant
I created a semantic string grouping system that identifies and clusters similar strings based on their meaning rather than exact matches. Here's how each component works:
Core Strategy
The system uses a multi-layered approach to determine if strings are semantically similar:
Word-level analysis - Extracts meaningful words and compares them
Normalization - Maps variations of words to common forms
Fuzzy matching - Handles typos and slight variations
Similarity scoring - Combines multiple metrics to determine relatedness
Key Components
Stop Word Filtering
I remove common words that don't carry semantic meaning like "the", "is", "and". This helps focus on the actual content. For example:
Character-level Similarity (30% weight): Uses Levenshtein distance to catch typos
"programming" vs "programing" would have high character similarity
Semantic Word Matching: Two words are considered the same if they:
Map to the same normalized form
Share the first 4+ characters (simple stemming)
Have edit distance ≤ 1 (for typos)
Grouping Algorithm
The grouping process:
Takes each unprocessed string as a potential group leader
Compares it with all remaining strings
Adds strings with similarity above the threshold (default 0.3) to the group
Marks grouped strings as processed to avoid duplicates
Example Walkthrough
Given: "The quick brown fox jumps" and "A fast brown fox is jumping"
Extract words:
String 1: ["quick", "brown", "fox", "jumps"]
String 2: ["fast", "brown", "fox", "jumping"]
Normalize:
"jumps" → "jump" (not in dictionary, but stemming catches it)
"jumping" → "jump" (via stemming)
Calculate similarity:
Common words: "brown", "fox", "jump" (3 matches)
Union size: 5 words total
Jaccard: 3/5 = 0.6
Character similarity also considered
Final score likely > 0.3 threshold
Result: These strings get grouped together
Limitations and Trade-offs
This approach has limitations compared to modern NLP:
The synonym dictionary is manually curated and limited
It can't understand context (e.g., "bank" as financial vs. river bank)
Complex semantic relationships aren't captured
No understanding of word importance or document structure
However, it provides reasonable results for many use cases without requiring external dependencies, making it suitable for environments where you can't use ML libraries or need a lightweight solution.