-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d99da7
commit 70be90e
Showing
13 changed files
with
2,322 additions
and
145 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
.vscode | ||
*.txt | ||
data.json | ||
!*/keywords/*.txt | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
|
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import regex | ||
from pathlib import Path | ||
from typing import Set | ||
|
||
|
||
def load_adult_keywords(filename: str = "combined-keywords.txt") -> Set[str]: | ||
"""Load adult keywords from the keywords file.""" | ||
keywords_file = Path(__file__).parent / "keywords" / filename | ||
keywords = set() | ||
|
||
with open(keywords_file, "r") as f: | ||
for line in f: | ||
keyword = line.strip() | ||
if keyword and not keyword.isspace(): | ||
keywords.add(regex.escape(keyword)) | ||
|
||
return keywords | ||
|
||
def create_adult_pattern() -> regex.Pattern: | ||
"""Create a compiled regex pattern for adult content detection.""" | ||
keywords = load_adult_keywords() | ||
return regex.compile( | ||
r'\b(' + '|'.join(keywords) + r')\b', | ||
regex.IGNORECASE | ||
) |
This file contains 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
This file contains 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
Oops, something went wrong.