Add Thai profanity detection utilities with custom words support - #1183
Merged
Conversation
Co-authored-by: wannaphong <8536487+wannaphong@users.noreply.github.com>
Co-authored-by: wannaphong <8536487+wannaphong@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add profanity detection for Thai language
Add Thai profanity detection utilities
Jan 9, 2026
wannaphong
reviewed
Jan 9, 2026
wannaphong
left a comment
Member
There was a problem hiding this comment.
@copilot I'm reviewed and comment about the task.
- All three functions (contains_profanity, find_profanity, censor_profanity) now accept custom_words parameter - Implemented custom dictionary that merges thai_words and profanity_set for better tokenization - Added comprehensive tests for custom words functionality - All 11 tests pass Co-authored-by: wannaphong <8536487+wannaphong@users.noreply.github.com>
Copilot
AI
changed the title
Add Thai profanity detection utilities
Add Thai profanity detection utilities with custom words support
Jan 9, 2026
wannaphong
marked this pull request as ready for review
January 10, 2026 15:33
Member
|
@copilot Fix This branch has conflicts that must be resolved. |
- Changed FrozenSet[str] to frozenset[str] - Changed List[str] to list[str] - Changed Set[str] to set[str] - Removed unnecessary typing imports - Aligns with dev branch type hint style Co-authored-by: wannaphong <8536487+wannaphong@users.noreply.github.com>
- Resolved merge conflicts in pythainlp/corpus/common.py - Added profanity detection feature to merged codebase - Updated to use Python 3.9+ type hints (lowercase built-in types) - All tests pass (11 profanity tests) Co-authored-by: wannaphong <8536487+wannaphong@users.noreply.github.com>
Contributor
Author
Member
|
@copilot Add docs to docs/api/util.rst |
- Added censor_profanity documentation - Added contains_profanity documentation - Added find_profanity documentation - Functions documented in alphabetical order with descriptions Co-authored-by: wannaphong <8536487+wannaphong@users.noreply.github.com>
Contributor
Author
bact
requested changes
Jan 12, 2026
bact
requested changes
Jan 12, 2026
…] | None - Fixed type hint for custom_words parameter in contains_profanity() - Fixed type hint for custom_words parameter in find_profanity() - Fixed type hint for custom_words parameter in censor_profanity() - All 11 tests pass Co-authored-by: bact <128572+bact@users.noreply.github.com>
bact
requested changes
Jan 12, 2026
|
bact
self-requested a review
January 12, 2026 15:27
wannaphong
approved these changes
Jan 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What does this changes
Adds profanity detection and filtering capabilities for Thai text with three utility functions:
contains_profanity(),find_profanity(), andcensor_profanity(). Users can optionally provide custom profanity words in addition to the default list.What was wrong
PyThaiNLP lacked profanity detection functionality for Thai language content moderation and filtering use cases.
How this fixes it
New corpus data:
profanity_th.txtwith 23 Thai profanity wordsthai_profanity_words()loader incorpus.commonNew utility functions in
pythainlp.util.profanity:contains_profanity(text, custom_words=None, engine="newmm")- Returns bool if profanity detectedfind_profanity(text, custom_words=None, engine="newmm")- Returns list of profanity words foundcensor_profanity(text, replacement="*", custom_words=None, engine="newmm")- Replaces profanity with censoring charactersKey features:
custom_wordsparameter (accepts an optional set of strings, type:set[str] | None)thai_words()and profanity words for better word segmentationUsage:
All functions use word tokenization with a merged custom dictionary (thai_words + profanity words) for accurate Thai text segmentation and support configurable tokenization engines.
Documentation:
docs/api/util.rstCompatibility updates:
frozenset[str],list[str],set[str] | None)set[str] | Noneinstead ofset[str]with None default)Your checklist for this pull request
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.