SqueakyCleanText 0.2.6__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. SqueakyCleanText-0.3.0/PKG-INFO +161 -0
  2. SqueakyCleanText-0.3.0/README.md +139 -0
  3. SqueakyCleanText-0.3.0/SqueakyCleanText.egg-info/PKG-INFO +161 -0
  4. {SqueakyCleanText-0.2.6 → SqueakyCleanText-0.3.0}/SqueakyCleanText.egg-info/requires.txt +1 -0
  5. {SqueakyCleanText-0.2.6 → SqueakyCleanText-0.3.0}/sct/sct.py +50 -12
  6. SqueakyCleanText-0.3.0/sct/utils/ner.py +310 -0
  7. {SqueakyCleanText-0.2.6 → SqueakyCleanText-0.3.0}/setup.py +3 -4
  8. SqueakyCleanText-0.3.0/tests/test_sct.py +565 -0
  9. SqueakyCleanText-0.2.6/PKG-INFO +0 -232
  10. SqueakyCleanText-0.2.6/README.md +0 -208
  11. SqueakyCleanText-0.2.6/SqueakyCleanText.egg-info/PKG-INFO +0 -232
  12. SqueakyCleanText-0.2.6/sct/utils/ner.py +0 -228
  13. SqueakyCleanText-0.2.6/tests/test_sct.py +0 -84
  14. {SqueakyCleanText-0.2.6 → SqueakyCleanText-0.3.0}/LICENSE +0 -0
  15. {SqueakyCleanText-0.2.6 → SqueakyCleanText-0.3.0}/MANIFEST.in +0 -0
  16. {SqueakyCleanText-0.2.6 → SqueakyCleanText-0.3.0}/SqueakyCleanText.egg-info/SOURCES.txt +0 -0
  17. {SqueakyCleanText-0.2.6 → SqueakyCleanText-0.3.0}/SqueakyCleanText.egg-info/dependency_links.txt +0 -0
  18. {SqueakyCleanText-0.2.6 → SqueakyCleanText-0.3.0}/SqueakyCleanText.egg-info/entry_points.txt +0 -0
  19. {SqueakyCleanText-0.2.6 → SqueakyCleanText-0.3.0}/SqueakyCleanText.egg-info/top_level.txt +0 -0
  20. {SqueakyCleanText-0.2.6 → SqueakyCleanText-0.3.0}/sct/__init__.py +0 -0
  21. {SqueakyCleanText-0.2.6 → SqueakyCleanText-0.3.0}/sct/config.py +0 -0
  22. {SqueakyCleanText-0.2.6 → SqueakyCleanText-0.3.0}/sct/scripts/__init__.py +0 -0
  23. {SqueakyCleanText-0.2.6 → SqueakyCleanText-0.3.0}/sct/scripts/download_nltk_stopwords.py +0 -0
  24. {SqueakyCleanText-0.2.6 → SqueakyCleanText-0.3.0}/sct/utils/__init__.py +0 -0
  25. {SqueakyCleanText-0.2.6 → SqueakyCleanText-0.3.0}/sct/utils/constants.py +0 -0
  26. {SqueakyCleanText-0.2.6 → SqueakyCleanText-0.3.0}/sct/utils/contact.py +0 -0
  27. {SqueakyCleanText-0.2.6 → SqueakyCleanText-0.3.0}/sct/utils/datetime.py +0 -0
  28. {SqueakyCleanText-0.2.6 → SqueakyCleanText-0.3.0}/sct/utils/normtext.py +0 -0
  29. {SqueakyCleanText-0.2.6 → SqueakyCleanText-0.3.0}/sct/utils/resources.py +0 -0
  30. {SqueakyCleanText-0.2.6 → SqueakyCleanText-0.3.0}/sct/utils/special.py +0 -0
  31. {SqueakyCleanText-0.2.6 → SqueakyCleanText-0.3.0}/sct/utils/stopwords.py +0 -0
  32. {SqueakyCleanText-0.2.6 → SqueakyCleanText-0.3.0}/setup.cfg +0 -0
  33. {SqueakyCleanText-0.2.6 → SqueakyCleanText-0.3.0}/tests/__init__.py +0 -0
@@ -0,0 +1,161 @@
1
+ Metadata-Version: 2.1
2
+ Name: SqueakyCleanText
3
+ Version: 0.3.0
4
+ Summary: A comprehensive text cleaning and preprocessing pipeline.
5
+ Home-page: https://github.com/rhnfzl/SqueakyCleanText
6
+ Author: Rehan Fazal
7
+ License: MIT
8
+ Keywords: text cleaning,text preprocessing,NLP,natural language processing
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Topic :: Software Development :: Libraries
16
+ Classifier: Topic :: Text Processing
17
+ Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
19
+ Provides-Extra: dev
20
+ Provides-Extra: test
21
+ License-File: LICENSE
22
+
23
+ <div align="center">
24
+
25
+ # SqueakyCleanText
26
+
27
+ [![PyPI](https://img.shields.io/pypi/v/squeakycleantext.svg)](https://pypi.org/project/squeakycleantext/)
28
+ [![PyPI - Downloads](https://img.shields.io/pypi/dm/squeakycleantext)](https://pypistats.org/packages/squeakycleantext)
29
+ [![Python package](https://github.com/rhnfzl/SqueakyCleanText/actions/workflows/python-package.yml/badge.svg)](https://github.com/rhnfzl/SqueakyCleanText/actions/workflows/python-package.yml)
30
+ [![Python Versions](https://img.shields.io/badge/Python-3.10%20|%203.11%20|%203.12-blue)](https://pypi.org/project/squeakycleantext/)
31
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
32
+
33
+ A comprehensive text cleaning and preprocessing pipeline for machine learning and NLP tasks.
34
+ </div>
35
+
36
+ In the world of machine learning and natural language processing, clean and well-structured text data is crucial for building effective downstream models and managing token limits in language models.
37
+
38
+ SqueakyCleanText simplifies the process by automatically addressing common text issues, ensuring your data is clean and well-structured with minimal effort on your part.
39
+
40
+ ### Key Features
41
+ - **Encoding Issues**: Corrects text encoding problems and handles bad Unicode characters.
42
+ - **HTML and URLs**: Removes or replaces HTML tags and URLs with configurable tokens.
43
+ - **Contact Information**: Handles emails, phone numbers, and other contact details with customizable replacement tokens.
44
+ - **Named Entity Recognition (NER)**:
45
+ - Multi-language support (English, Dutch, German, Spanish)
46
+ - Ensemble voting technique for improved accuracy
47
+ - Configurable confidence thresholds
48
+ - Efficient batch processing
49
+ - Automatic text chunking for long documents
50
+ - GPU acceleration support
51
+ - **Text Normalization**:
52
+ - Removes isolated letters and symbols
53
+ - Normalizes whitespace
54
+ - Handles currency symbols
55
+ - Year detection and replacement
56
+ - Number standardization
57
+ - **Language Support**:
58
+ - Automatic language detection
59
+ - Language-specific NER models
60
+ - Language-aware stopword removal
61
+ - **Dual Output Formats**:
62
+ - Language Model format (preserves structure with tokens)
63
+ - Statistical Model format (optimized for classical ML)
64
+ - **Performance Optimization**:
65
+ - Batch processing support
66
+ - Configurable batch sizes
67
+ - Memory-efficient processing of large texts
68
+ - GPU memory management
69
+
70
+ ![Default Flow of cleaning Text](resources/sct_flow.png)
71
+
72
+ ### Benefits
73
+
74
+ #### For Language Models
75
+ - Maintains text structure while anonymizing sensitive information
76
+ - Configurable token replacements
77
+ - Preserves context while removing noise
78
+ - Handles long documents through intelligent chunking
79
+
80
+ #### For Statistical Models
81
+ - Removes stopwords and punctuation
82
+ - Case normalization
83
+ - Special symbol removal
84
+ - Optimized for classification tasks
85
+
86
+ #### Advanced NER Processing
87
+ - Ensemble approach reduces missed entities
88
+ - Language-specific models improve accuracy
89
+ - Confidence thresholds for precision control
90
+ - Efficient batch processing for large datasets
91
+ - Automatic handling of long documents
92
+
93
+ ## Installation
94
+
95
+ ```sh
96
+ pip install SqueakyCleanText
97
+ ```
98
+
99
+ ## Usage
100
+
101
+ ### Basic Usage
102
+ ```python
103
+ from sct import sct
104
+
105
+ # Initialize the TextCleaner
106
+ sx = sct.TextCleaner()
107
+
108
+ # Process single text
109
+ text = "Hey John Doe, email me at john.doe@example.com"
110
+ lm_text, stat_text, language = sx.process(text)
111
+
112
+ # Process multiple texts efficiently
113
+ texts = ["Text 1", "Text 2", "Text 3"]
114
+ results = sx.process_batch(texts, batch_size=2)
115
+ ```
116
+
117
+ ### Advanced Configuration
118
+ ```python
119
+ from sct import sct, config
120
+
121
+ # Customize NER settings
122
+ config.CHECK_NER_PROCESS = True
123
+ config.NER_CONFIDENCE_THRESHOLD = 0.85
124
+ config.POSITIONAL_TAGS = ['PER', 'LOC', 'ORG']
125
+
126
+ # Customize replacement tokens
127
+ config.REPLACE_WITH_URL = "<URL>"
128
+ config.REPLACE_WITH_EMAIL = "<EMAIL>"
129
+ config.REPLACE_WITH_PHONE_NUMBERS = "<PHONE>"
130
+
131
+ # Set known language (skips detection)
132
+ config.LANGUAGE = "ENGLISH" # Options: ENGLISH, DUTCH, GERMAN, SPANISH
133
+
134
+ # Initialize with custom settings
135
+ sx = sct.TextCleaner()
136
+ ```
137
+
138
+ ## API
139
+
140
+ ### `sct.TextCleaner`
141
+
142
+ #### `process(text: str) -> Tuple[str, str, str]`
143
+
144
+ Processes the input text and returns a tuple containing:
145
+ - Cleaned text formatted for language models.
146
+ - Cleaned text formatted for statistical models (stopwords removed).
147
+ - Detected language of the text.
148
+
149
+ ## Contributing
150
+
151
+ Contributions are welcome! Please feel free to submit a Pull Request or open an issue.
152
+
153
+ ## License
154
+
155
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
156
+
157
+ ## Acknowledgements
158
+
159
+ The package took inspirations from the following repo:
160
+
161
+ - [clean-text](https://github.com/jfilter/clean-text)
@@ -0,0 +1,139 @@
1
+ <div align="center">
2
+
3
+ # SqueakyCleanText
4
+
5
+ [![PyPI](https://img.shields.io/pypi/v/squeakycleantext.svg)](https://pypi.org/project/squeakycleantext/)
6
+ [![PyPI - Downloads](https://img.shields.io/pypi/dm/squeakycleantext)](https://pypistats.org/packages/squeakycleantext)
7
+ [![Python package](https://github.com/rhnfzl/SqueakyCleanText/actions/workflows/python-package.yml/badge.svg)](https://github.com/rhnfzl/SqueakyCleanText/actions/workflows/python-package.yml)
8
+ [![Python Versions](https://img.shields.io/badge/Python-3.10%20|%203.11%20|%203.12-blue)](https://pypi.org/project/squeakycleantext/)
9
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
10
+
11
+ A comprehensive text cleaning and preprocessing pipeline for machine learning and NLP tasks.
12
+ </div>
13
+
14
+ In the world of machine learning and natural language processing, clean and well-structured text data is crucial for building effective downstream models and managing token limits in language models.
15
+
16
+ SqueakyCleanText simplifies the process by automatically addressing common text issues, ensuring your data is clean and well-structured with minimal effort on your part.
17
+
18
+ ### Key Features
19
+ - **Encoding Issues**: Corrects text encoding problems and handles bad Unicode characters.
20
+ - **HTML and URLs**: Removes or replaces HTML tags and URLs with configurable tokens.
21
+ - **Contact Information**: Handles emails, phone numbers, and other contact details with customizable replacement tokens.
22
+ - **Named Entity Recognition (NER)**:
23
+ - Multi-language support (English, Dutch, German, Spanish)
24
+ - Ensemble voting technique for improved accuracy
25
+ - Configurable confidence thresholds
26
+ - Efficient batch processing
27
+ - Automatic text chunking for long documents
28
+ - GPU acceleration support
29
+ - **Text Normalization**:
30
+ - Removes isolated letters and symbols
31
+ - Normalizes whitespace
32
+ - Handles currency symbols
33
+ - Year detection and replacement
34
+ - Number standardization
35
+ - **Language Support**:
36
+ - Automatic language detection
37
+ - Language-specific NER models
38
+ - Language-aware stopword removal
39
+ - **Dual Output Formats**:
40
+ - Language Model format (preserves structure with tokens)
41
+ - Statistical Model format (optimized for classical ML)
42
+ - **Performance Optimization**:
43
+ - Batch processing support
44
+ - Configurable batch sizes
45
+ - Memory-efficient processing of large texts
46
+ - GPU memory management
47
+
48
+ ![Default Flow of cleaning Text](resources/sct_flow.png)
49
+
50
+ ### Benefits
51
+
52
+ #### For Language Models
53
+ - Maintains text structure while anonymizing sensitive information
54
+ - Configurable token replacements
55
+ - Preserves context while removing noise
56
+ - Handles long documents through intelligent chunking
57
+
58
+ #### For Statistical Models
59
+ - Removes stopwords and punctuation
60
+ - Case normalization
61
+ - Special symbol removal
62
+ - Optimized for classification tasks
63
+
64
+ #### Advanced NER Processing
65
+ - Ensemble approach reduces missed entities
66
+ - Language-specific models improve accuracy
67
+ - Confidence thresholds for precision control
68
+ - Efficient batch processing for large datasets
69
+ - Automatic handling of long documents
70
+
71
+ ## Installation
72
+
73
+ ```sh
74
+ pip install SqueakyCleanText
75
+ ```
76
+
77
+ ## Usage
78
+
79
+ ### Basic Usage
80
+ ```python
81
+ from sct import sct
82
+
83
+ # Initialize the TextCleaner
84
+ sx = sct.TextCleaner()
85
+
86
+ # Process single text
87
+ text = "Hey John Doe, email me at john.doe@example.com"
88
+ lm_text, stat_text, language = sx.process(text)
89
+
90
+ # Process multiple texts efficiently
91
+ texts = ["Text 1", "Text 2", "Text 3"]
92
+ results = sx.process_batch(texts, batch_size=2)
93
+ ```
94
+
95
+ ### Advanced Configuration
96
+ ```python
97
+ from sct import sct, config
98
+
99
+ # Customize NER settings
100
+ config.CHECK_NER_PROCESS = True
101
+ config.NER_CONFIDENCE_THRESHOLD = 0.85
102
+ config.POSITIONAL_TAGS = ['PER', 'LOC', 'ORG']
103
+
104
+ # Customize replacement tokens
105
+ config.REPLACE_WITH_URL = "<URL>"
106
+ config.REPLACE_WITH_EMAIL = "<EMAIL>"
107
+ config.REPLACE_WITH_PHONE_NUMBERS = "<PHONE>"
108
+
109
+ # Set known language (skips detection)
110
+ config.LANGUAGE = "ENGLISH" # Options: ENGLISH, DUTCH, GERMAN, SPANISH
111
+
112
+ # Initialize with custom settings
113
+ sx = sct.TextCleaner()
114
+ ```
115
+
116
+ ## API
117
+
118
+ ### `sct.TextCleaner`
119
+
120
+ #### `process(text: str) -> Tuple[str, str, str]`
121
+
122
+ Processes the input text and returns a tuple containing:
123
+ - Cleaned text formatted for language models.
124
+ - Cleaned text formatted for statistical models (stopwords removed).
125
+ - Detected language of the text.
126
+
127
+ ## Contributing
128
+
129
+ Contributions are welcome! Please feel free to submit a Pull Request or open an issue.
130
+
131
+ ## License
132
+
133
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
134
+
135
+ ## Acknowledgements
136
+
137
+ The package took inspirations from the following repo:
138
+
139
+ - [clean-text](https://github.com/jfilter/clean-text)
@@ -0,0 +1,161 @@
1
+ Metadata-Version: 2.1
2
+ Name: SqueakyCleanText
3
+ Version: 0.3.0
4
+ Summary: A comprehensive text cleaning and preprocessing pipeline.
5
+ Home-page: https://github.com/rhnfzl/SqueakyCleanText
6
+ Author: Rehan Fazal
7
+ License: MIT
8
+ Keywords: text cleaning,text preprocessing,NLP,natural language processing
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Topic :: Software Development :: Libraries
16
+ Classifier: Topic :: Text Processing
17
+ Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
19
+ Provides-Extra: dev
20
+ Provides-Extra: test
21
+ License-File: LICENSE
22
+
23
+ <div align="center">
24
+
25
+ # SqueakyCleanText
26
+
27
+ [![PyPI](https://img.shields.io/pypi/v/squeakycleantext.svg)](https://pypi.org/project/squeakycleantext/)
28
+ [![PyPI - Downloads](https://img.shields.io/pypi/dm/squeakycleantext)](https://pypistats.org/packages/squeakycleantext)
29
+ [![Python package](https://github.com/rhnfzl/SqueakyCleanText/actions/workflows/python-package.yml/badge.svg)](https://github.com/rhnfzl/SqueakyCleanText/actions/workflows/python-package.yml)
30
+ [![Python Versions](https://img.shields.io/badge/Python-3.10%20|%203.11%20|%203.12-blue)](https://pypi.org/project/squeakycleantext/)
31
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
32
+
33
+ A comprehensive text cleaning and preprocessing pipeline for machine learning and NLP tasks.
34
+ </div>
35
+
36
+ In the world of machine learning and natural language processing, clean and well-structured text data is crucial for building effective downstream models and managing token limits in language models.
37
+
38
+ SqueakyCleanText simplifies the process by automatically addressing common text issues, ensuring your data is clean and well-structured with minimal effort on your part.
39
+
40
+ ### Key Features
41
+ - **Encoding Issues**: Corrects text encoding problems and handles bad Unicode characters.
42
+ - **HTML and URLs**: Removes or replaces HTML tags and URLs with configurable tokens.
43
+ - **Contact Information**: Handles emails, phone numbers, and other contact details with customizable replacement tokens.
44
+ - **Named Entity Recognition (NER)**:
45
+ - Multi-language support (English, Dutch, German, Spanish)
46
+ - Ensemble voting technique for improved accuracy
47
+ - Configurable confidence thresholds
48
+ - Efficient batch processing
49
+ - Automatic text chunking for long documents
50
+ - GPU acceleration support
51
+ - **Text Normalization**:
52
+ - Removes isolated letters and symbols
53
+ - Normalizes whitespace
54
+ - Handles currency symbols
55
+ - Year detection and replacement
56
+ - Number standardization
57
+ - **Language Support**:
58
+ - Automatic language detection
59
+ - Language-specific NER models
60
+ - Language-aware stopword removal
61
+ - **Dual Output Formats**:
62
+ - Language Model format (preserves structure with tokens)
63
+ - Statistical Model format (optimized for classical ML)
64
+ - **Performance Optimization**:
65
+ - Batch processing support
66
+ - Configurable batch sizes
67
+ - Memory-efficient processing of large texts
68
+ - GPU memory management
69
+
70
+ ![Default Flow of cleaning Text](resources/sct_flow.png)
71
+
72
+ ### Benefits
73
+
74
+ #### For Language Models
75
+ - Maintains text structure while anonymizing sensitive information
76
+ - Configurable token replacements
77
+ - Preserves context while removing noise
78
+ - Handles long documents through intelligent chunking
79
+
80
+ #### For Statistical Models
81
+ - Removes stopwords and punctuation
82
+ - Case normalization
83
+ - Special symbol removal
84
+ - Optimized for classification tasks
85
+
86
+ #### Advanced NER Processing
87
+ - Ensemble approach reduces missed entities
88
+ - Language-specific models improve accuracy
89
+ - Confidence thresholds for precision control
90
+ - Efficient batch processing for large datasets
91
+ - Automatic handling of long documents
92
+
93
+ ## Installation
94
+
95
+ ```sh
96
+ pip install SqueakyCleanText
97
+ ```
98
+
99
+ ## Usage
100
+
101
+ ### Basic Usage
102
+ ```python
103
+ from sct import sct
104
+
105
+ # Initialize the TextCleaner
106
+ sx = sct.TextCleaner()
107
+
108
+ # Process single text
109
+ text = "Hey John Doe, email me at john.doe@example.com"
110
+ lm_text, stat_text, language = sx.process(text)
111
+
112
+ # Process multiple texts efficiently
113
+ texts = ["Text 1", "Text 2", "Text 3"]
114
+ results = sx.process_batch(texts, batch_size=2)
115
+ ```
116
+
117
+ ### Advanced Configuration
118
+ ```python
119
+ from sct import sct, config
120
+
121
+ # Customize NER settings
122
+ config.CHECK_NER_PROCESS = True
123
+ config.NER_CONFIDENCE_THRESHOLD = 0.85
124
+ config.POSITIONAL_TAGS = ['PER', 'LOC', 'ORG']
125
+
126
+ # Customize replacement tokens
127
+ config.REPLACE_WITH_URL = "<URL>"
128
+ config.REPLACE_WITH_EMAIL = "<EMAIL>"
129
+ config.REPLACE_WITH_PHONE_NUMBERS = "<PHONE>"
130
+
131
+ # Set known language (skips detection)
132
+ config.LANGUAGE = "ENGLISH" # Options: ENGLISH, DUTCH, GERMAN, SPANISH
133
+
134
+ # Initialize with custom settings
135
+ sx = sct.TextCleaner()
136
+ ```
137
+
138
+ ## API
139
+
140
+ ### `sct.TextCleaner`
141
+
142
+ #### `process(text: str) -> Tuple[str, str, str]`
143
+
144
+ Processes the input text and returns a tuple containing:
145
+ - Cleaned text formatted for language models.
146
+ - Cleaned text formatted for statistical models (stopwords removed).
147
+ - Detected language of the text.
148
+
149
+ ## Contributing
150
+
151
+ Contributions are welcome! Please feel free to submit a Pull Request or open an issue.
152
+
153
+ ## License
154
+
155
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
156
+
157
+ ## Acknowledgements
158
+
159
+ The package took inspirations from the following repo:
160
+
161
+ - [clean-text](https://github.com/jfilter/clean-text)
@@ -13,6 +13,7 @@ hypothesis==6.82.7
13
13
  faker==20.1.0
14
14
  flake8==6.1.0
15
15
  pytest==7.5.0
16
+ timeout-decorator==0.5.0
16
17
 
17
18
  [test]
18
19
  coverage==7.3.1
@@ -5,6 +5,7 @@ which is crucial for natural language processing tasks.
5
5
  """
6
6
  from sct import config
7
7
  from sct.utils import contact, datetime, ner, normtext, resources, special, stopwords
8
+ from typing import List, Any
8
9
 
9
10
  class TextCleaner:
10
11
 
@@ -17,6 +18,7 @@ class TextCleaner:
17
18
  self.GeneralNER = ner.GeneralNER()
18
19
  self.pipeline = []
19
20
  self.language = None
21
+ self.batch_size = 8 # Default batch size for NER
20
22
  self.init_pipeline()
21
23
 
22
24
  def init_pipeline(self):
@@ -32,7 +34,6 @@ class TextCleaner:
32
34
  self.pipeline.append(self.fix_bad_unicode)
33
35
  if config.CHECK_TO_ASCII_UNICODE:
34
36
  self.pipeline.append(self.to_ascii_unicode)
35
-
36
37
  if config.CHECK_REPLACE_HTML:
37
38
  self.pipeline.append(self.replace_html)
38
39
  if config.CHECK_REPLACE_URLS:
@@ -58,19 +59,56 @@ class TextCleaner:
58
59
  if config.CHECK_NORMALIZE_WHITESPACE:
59
60
  self.pipeline.append(self.normalize_whitespace)
60
61
 
61
- def process(self, text):
62
- text = str(text)
62
+ def process_batch(self, texts: List[str], batch_size: int = None) -> List[Any]:
63
+ """Process multiple texts efficiently in batches."""
64
+ if not texts:
65
+ return []
66
+
67
+ results = []
68
+ batch_size = batch_size or self.batch_size
63
69
 
64
- for step in self.pipeline:
65
- text = step(text)
70
+ for text in texts:
71
+ # Validate input type and content
72
+ if not isinstance(text, str):
73
+ raise ValueError(f"Input must be string, got {type(text)}")
74
+
75
+ # Handle empty text case
76
+ if not text or text.isspace():
77
+ results.append(("", "", None))
78
+ continue
79
+
80
+ current_text = text # No need for str() conversion now
81
+
82
+ # Reset language for each text
83
+ self.language = None
84
+
85
+ # Apply non-NER pipeline steps
86
+ for step in [s for s in self.pipeline if s != self.ner_process]:
87
+ current_text = step(current_text)
88
+
89
+ # Batch NER processing if enabled
90
+ if config.CHECK_NER_PROCESS:
91
+ current_text = self.GeneralNER.ner_process(
92
+ current_text,
93
+ positional_tags=config.POSITIONAL_TAGS,
94
+ ner_confidence_threshold=config.NER_CONFIDENCE_THRESHOLD,
95
+ language=self.language
96
+ )
66
97
 
67
- if config.CHECK_STATISTICAL_MODEL_PROCESSING:
68
- stext = self.statistical_model_processing(text)
69
- return text, stext, self.language
70
- elif config.CHECK_DETECT_LANGUAGE:
71
- return text, self.language
72
- else:
73
- return text
98
+ # Format results
99
+ if config.CHECK_STATISTICAL_MODEL_PROCESSING:
100
+ stext = self.statistical_model_processing(current_text)
101
+ results.append((current_text, stext, self.language))
102
+ elif config.CHECK_DETECT_LANGUAGE:
103
+ results.append((current_text, self.language))
104
+ else:
105
+ results.append(current_text)
106
+
107
+ return results
108
+
109
+ def process(self, text: str) -> Any:
110
+ """Process a single text. Maintains backward compatibility."""
111
+ return self.process_batch([text])[0]
74
112
 
75
113
  def detect_language(self, text):
76
114
  self.language = str(resources.DETECTOR.detect_language_of(text)).split(".")[-1]