Skip to content

Processors

processors


Assembly:                Fonky
Filename:                processors.py
Author:                  Terry D. Eppler
Created:                 05-31-2022

Last Modified By:        Terry D. Eppler
Last Modified On:        05-01-2025

       processors.py
       Copyright ©  2022  Terry Eppler

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

You can contact me at: terryeppler@gmail.com or eppler.terry@epa.gov

Provides text-processing, tokenization, normalization, cleaning, chunking, vectorization, and natural-language processing utilities used by Fonky ingestion and retrieval workflows. Purpose: Centralizes reusable processing routines for plain text, HTML, XML, Markdown, document files, token streams, frequency distributions, vector encodings, and semantic search inputs. The module prepares raw content for downstream loaders, embeddings, analysis, persistence, and model-facing workflows while preserving a consistent project error-wrapping pattern.

Processor

Provide shared processor state.

Purpose

Initializes shared state and reusable NLP helpers used by text-processing subclasses. The class centralizes tokenizer, lemmatizer, stemmer, corpus, chunking, and intermediate text containers that derived processors reuse across cleaning, tokenization, and vectorization workflows.

Attributes:

Name Type Description
lemmatizer Optional[WordNetLemmatizer]

WordNet lemmatizer used by lexical normalization routines.

stemmer Optional[PorterStemmer]

Porter stemmer used by stemming routines.

file_path Optional[str]

Active local file path being processed.

normalized Optional[str]

Most recent normalized text value.

lemmatized Optional[str]

Most recent lemmatized text value.

tokenized Optional[str]

Most recent tokenized text value.

encoding Optional[Encoding]

Active tiktoken encoding instance.

nlp Optional[Language]

Optional spaCy language pipeline.

parts_of_speech Optional[List[Tuple[str, str]]]

Part-of-speech tuples generated by parser operations.

embedddings Optional[List[Tuple[str, str]]]

Embedding vectors generated during vectorization workflows.

chunk_size Optional[int]

Current chunk size used by chunking routines.

corrected Optional[str]

Corrected text retained by spelling or cleanup workflows.

raw_input Optional[str]

Raw text input retained for the active operation.

raw_html Optional[str]

Raw HTML input retained before markup removal.

raw_pages Optional[List[str]]

Raw page strings extracted from a document.

lines Optional[List[str]]

Line strings read from an input file.

tokens Optional[List[str]]

Token strings generated from text.

files Optional[List[str]]

File names or paths collected for batch processing.

pages Optional[List[str]]

Page-level text blocks generated from file content.

paragraphs Optional[List[str]]

Paragraph-level text blocks generated from file content.

ids Optional[List[int]]

Identifier values associated with processed records.

stop_words Optional[set]

Stop-word set used by filtering routines.

vocabulary Optional[set]

Vocabulary generated from tokens or frequency distributions.

corpus Optional[DataFrame]

Tabular corpus representation used by analysis routines.

removed Optional[List[str]]

Values removed by filtering or cleaning routines.

frequency_distribution Optional[DataFrame]

Frequency information generated from token counts.

Source code in processors.py
class Processor( ):
	"""Provide shared processor state.

	Purpose:
	    Initializes shared state and reusable NLP helpers used by text-processing subclasses. The class
	    centralizes tokenizer, lemmatizer, stemmer, corpus, chunking, and intermediate text containers
	    that derived processors reuse across cleaning, tokenization, and vectorization workflows.

	Attributes:
	    lemmatizer: WordNet lemmatizer used by lexical normalization routines.
	    stemmer: Porter stemmer used by stemming routines.
	    file_path: Active local file path being processed.
	    normalized: Most recent normalized text value.
	    lemmatized: Most recent lemmatized text value.
	    tokenized: Most recent tokenized text value.
	    encoding: Active tiktoken encoding instance.
	    nlp: Optional spaCy language pipeline.
	    parts_of_speech: Part-of-speech tuples generated by parser operations.
	    embedddings: Embedding vectors generated during vectorization workflows.
	    chunk_size: Current chunk size used by chunking routines.
	    corrected: Corrected text retained by spelling or cleanup workflows.
	    raw_input: Raw text input retained for the active operation.
	    raw_html: Raw HTML input retained before markup removal.
	    raw_pages: Raw page strings extracted from a document.
	    lines: Line strings read from an input file.
	    tokens: Token strings generated from text.
	    files: File names or paths collected for batch processing.
	    pages: Page-level text blocks generated from file content.
	    paragraphs: Paragraph-level text blocks generated from file content.
	    ids: Identifier values associated with processed records.
	    stop_words: Stop-word set used by filtering routines.
	    vocabulary: Vocabulary generated from tokens or frequency distributions.
	    corpus: Tabular corpus representation used by analysis routines.
	    removed: Values removed by filtering or cleaning routines.
	    frequency_distribution: Frequency information generated from token counts.
	"""
	lemmatizer: Optional[ WordNetLemmatizer ]
	stemmer: Optional[ PorterStemmer ]
	file_path: Optional[ str ]
	normalized: Optional[ str ]
	lemmatized: Optional[ str ]
	tokenized: Optional[ str ]
	encoding: Optional[ Encoding ]
	nlp: Optional[ Language ]
	parts_of_speech: Optional[ List[ Tuple[ str, str ] ] ]
	embeddings: Optional[ List[ np.ndarray ] ]
	chunk_size: Optional[ int ]
	corrected: Optional[ str ]
	raw_input: Optional[ str ]
	raw_html: Optional[ str ]
	raw_pages: Optional[ List[ str ] ]
	lines: Optional[ List[ str ] ]
	tokens: Optional[ List[ str ] ]
	lines: Optional[ List[ str ] ]
	files: Optional[ List[ str ] ]
	pages: Optional[ List[ str ] ]
	paragraphs: Optional[ List[ str ] ]
	ids: Optional[ List[ int ] ]
	stop_words: Optional[ set ]
	vocabulary: Optional[ set ]
	corpus: Optional[ DataFrame ]
	removed: Optional[ List[ str ] ]
	frequency_distribution: Optional[ DataFrame ]

	def __init__( self ) -> None:
		"""Initialize Processor.

		Purpose:
		    Initializes Processor state used by later processing operations. The constructor prepares
		    reusable containers, helper objects, and default runtime values without performing external
		    document processing.

		Returns:
		    None: Constructors initialize instance state and do not return a value.
		"""
		self.lemmatizer = WordNetLemmatizer( )
		self.stemmer = PorterStemmer( )
		self.files = [ ]
		self.lines = [ ]
		self.tokens = [ ]
		self.lines = [ ]
		self.pages = [ ]
		self.ids = [ ]
		self.chunks = [ ]
		self.chunk_size = 0
		self.paragraphs = [ ]
		self.embeddings = [ ]
		self.stop_words = set( )
		self.vocabulary = set( )
		self.frequency_distribution = { }
		self.encoding = None
		self.corrected = None
		self.lowercase = None
		self.raw_html = None
		self.corpus = None
		self.file_path = ''
		self.raw_input = ''
		self.normalized = ''
		self.lemmatized = ''
		self.tokenized = ''
		self.cleaned_text = ''

TextParser

Bases: Processor

Process and normalize text.

Purpose

Provides text-cleaning, markup-removal, tokenization, chunking, vocabulary, frequency, vectorization, and semantic-search utilities for Fonky processing workflows. The class transforms raw file and string inputs into normalized text, tabular artifacts, token lists, embeddings, and dataset-ready chunks.

Attributes:

Name Type Description
lowercase Optional[str]

Lowercase text retained by normalization workflows.

cleaned_text Optional[str]

Most recent cleaned text output.

cleaned_lines Optional[List[str]]

Cleaned line strings.

cleaned_tokens Optional[List[str]]

Cleaned token strings.

cleaned_pages Optional[List[str]]

Cleaned page strings.

cleaned_html Optional[str]

HTML-derived text after tag removal.

conditional_distribution Optional[DataFrame]

Conditional frequency-distribution data.

PUNCTUATION Optional[Set[str]]

Punctuation characters used by filtering routines.

CONTROL_CHARACTERS Optional[Set[str]]

Control characters removed during cleanup.

DELIMITERS Optional[Set[str]]

Delimiter strings used by splitting routines.

DIGITS Optional[Set[str]]

Digit characters used by number filtering routines.

SYMBOLS Optional[Set[str]]

Symbol characters removed by symbol filtering routines.

NUMERALS Optional[str]

Roman-numeral regular expression used by numeral filtering.

Source code in processors.py
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
class TextParser( Processor ):
	"""Process and normalize text.

	Purpose:
	    Provides text-cleaning, markup-removal, tokenization, chunking, vocabulary, frequency,
	    vectorization, and semantic-search utilities for Fonky processing workflows. The class
	    transforms raw file and string inputs into normalized text, tabular artifacts, token lists,
	    embeddings, and dataset-ready chunks.

	Attributes:
	    lowercase: Lowercase text retained by normalization workflows.
	    cleaned_text: Most recent cleaned text output.
	    cleaned_lines: Cleaned line strings.
	    cleaned_tokens: Cleaned token strings.
	    cleaned_pages: Cleaned page strings.
	    cleaned_html: HTML-derived text after tag removal.
	    conditional_distribution: Conditional frequency-distribution data.
	    PUNCTUATION: Punctuation characters used by filtering routines.
	    CONTROL_CHARACTERS: Control characters removed during cleanup.
	    DELIMITERS: Delimiter strings used by splitting routines.
	    DIGITS: Digit characters used by number filtering routines.
	    SYMBOLS: Symbol characters removed by symbol filtering routines.
	    NUMERALS: Roman-numeral regular expression used by numeral filtering.
	"""
	lowercase: Optional[ str ]
	cleaned_text: Optional[ str ]
	cleaned_lines: Optional[ List[ str ] ]
	cleaned_tokens: Optional[ List[ str ] ]
	cleaned_pages: Optional[ List[ str ] ]
	cleaned_html: Optional[ str ]
	conditional_distribution: Optional[ DataFrame ]
	PUNCTUATION: Optional[ Set[ str ] ]
	CONTROL_CHARACTERS: Optional[ Set[ str ] ]
	DELIMITERS: Optional[ Set[ str ] ]
	DIGITS: Optional[ Set[ str ] ]
	SYMBOLS: Optional[ Set[ str ] ]
	NUMERALS: Optional[ str ]

	def __init__( self ) -> None:
		"""Initialize Text Parser.

		Purpose:
		    Initializes TextParser state used by later processing operations. The constructor prepares
		    reusable containers, helper objects, and default runtime values without performing external
		    document processing.

		Returns:
		    None: Constructors initialize instance state and do not return a value.
		"""
		super( ).__init__( )
		self.PUNCTUATION = PUNCTUATION
		self.CONTROL_CHARACTERS = ({ chr( i ) for i in range( 0x00, 0x20 ) } | { chr( 0x7F ) })
		self.DELIMITERS = DELIMITERS
		self.DIGITS = DIGITS
		self.SYMBOLS = SYMBOLS
		self.NUMERALS = NUMERALS
		self.lemmatizer = WordNetLemmatizer( )
		self.stemmer = PorterStemmer( )
		self.encoding = tiktoken.get_encoding( 'cl100k_base' )
		self.lines = [ ]
		self.tokens = [ ]
		self.pages = [ ]
		self.ids = [ ]
		self.paragraphs = [ ]
		self.chunks = [ ]
		self.chunk_size = 10
		self.raw_pages = [ ]
		self.stop_words = set( )
		self.frequency_distribution = { }
		self.file_path = ''
		self.raw_input = ''
		self.normalized = ''
		self.lemmatized = ''
		self.tokenized = ''
		self.cleaned_text = ''
		self.vocabulary = None
		self.corrected = None
		self.lowercase = None
		self.raw_html = None
		self.translator = None
		self.tokenizer = None
		self.vectorizer = None

	def __dir__( self ) -> List[ str ] | None:
		"""Return the public attribute and method names exposed by the object.

		Purpose:
		    Returns a stable list of public attributes and methods for interactive inspection,
		    documentation, and UI discovery. The ordering groups state fields and callable processing
		    operations in a predictable way.

		Returns:
		    List[ str ] | None: List of processed text values when the operation succeeds.
		"""
		return [  # Attributes
			'file_path', 'raw_input', 'raw_pages', 'normalized', 'lemmatized', 'tokenized',
			'corrected', 'cleaned_text', 'words', 'paragraphs', 'words', 'pages', 'chunks',
			'chunk_size', 'stop_words', 'removed', 'lowercase', 'encoding', 'vocabulary',
			'translator', 'lemmatizer', 'stemmer', 'tokenizer', 'vectorizer',
			'conditional_distribution',
			# Methods
			'split_sentences', 'split_pages', 'collapse_whitespace', 'compress_whitespace',
			'remove_punctuation', 'remove_numbers', 'remove_special', 'remove_html',
			'remove_markdown', 'remove_stopwords', 'remove_formatting', 'remove_headers',
			'remove_encodings', 'tiktokenize', 'lemmatize_text', 'normalize_text', 'chunk_text',
			'chunk_sentences', 'chunk_files', 'chunk_data', 'chunk_datasets', 'create_wordbag',
			'clean_file', 'clean_files', 'convert_jsonl', 'speech_tagging', 'split_paragraphs',
			'calculate_frequency_distribution', 'create_vocabulary', 'create_wordbag',
			'create_vectors', 'encode_sentences', 'semantic_search' ]

	def load_text( self, filepath: str ) -> str | None:
		"""Read UTF-8 text from a local file and return the raw string.

		Purpose:
		    Loads a local text file using UTF-8 with ignored decode errors so downstream cleaning routines
		    can operate on a plain string. The method records the active file path and raises a project
		    Error when the file cannot be read.

		Args:
		    filepath: Path to the local source file.

		Returns:
		    str | None: Processed text value when the operation succeeds.

		Raises:
		    FileNotFoundError: If a required local file or matched path does not exist.
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'filepath', filepath )
			if not os.path.exists( filepath ):
				raise FileNotFoundError( f'File not found: {filepath}' )
			else:
				self.file_path = filepath
			raw_text = open( self.file_path, mode='r', encoding='utf-8', errors='ignore' ).read( )
			return raw_text
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = 'load_text( self, file_path: str ) -> str'
			raise exception

	def collapse_whitespace( self, text: str ) -> str | None:
		"""Normalize spacing by lowercasing text and collapsing repeated whitespace.

		Purpose:
		    Creates a compact lowercase representation of text by splitting on whitespace and joining
		    tokens with single spaces. This prepares raw text for deterministic comparison, cleaning, and
		    tokenization steps.

		Args:
		    text: Text value to process.

		Returns:
		    str | None: Processed text value when the operation succeeds.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'text', text )
			_text = text.lower( )
			return ' '.join( _text.split( ) )
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = 'collapse_whitespace( self, path: str ) -> str:'
			raise exception

	def remove_punctuation( self, text: str ) -> str:
		"""Strip punctuation from tokenized text while preserving word and spacing content.

		Purpose:
		    Tokenizes lowercase text and removes punctuation marks from each token. The method preserves
		    alphanumeric token content while returning a whitespace-joined string for later cleaning
		    stages.

		Args:
		    text: Text value to process.

		Returns:
		    str: Processed text value produced by the operation.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'text', text )
			_text = text.lower( )
			_tokens = word_tokenize( _text )
			cleaned_tokens = [ re.sub( r'[^\w\s]', '', t ) for t in _tokens if
			                   re.sub( r'[^\w\s]', '', t ) ]
			return ' '.join( cleaned_tokens )
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = 'remove_punctuation( self, text: str ) -> str:'
			raise exception

	def normalize_text( self, text: str ) -> str | None:
		"""Convert text to lowercase for stable downstream comparison and tokenization.

		Purpose:
		    Converts text to lowercase without otherwise changing content. This provides a simple
		    normalization stage for workflows that need case-insensitive matching or tokenization.

		Args:
		    text: Text value to process.

		Returns:
		    str | None: Processed text value when the operation succeeds.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'text', text )
			return text.lower( )
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = 'normalize_text( self, text: str ) -> str:'
			raise exception

	def remove_errors( self, text: str ) -> str:
		"""Filter tokens against the NLTK English words corpus.

		Purpose:
		    Uses the NLTK English words corpus as a vocabulary filter and keeps only tokens recognized by
		    that corpus. This reduces obvious OCR, spelling, and parsing artifacts before later analysis.

		Args:
		    text: Text value to process.

		Returns:
		    str: Processed text value produced by the operation.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'text', text )
			_vocab = words.words( 'en' )
			_text = text.lower( )
			_tokens = _text.split( )
			_words = [ w for w in _tokens if w in _vocab ]
			_data = ' '.join( _words )
			return _data
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = 'remove_errors( self, text: str  ) -> str'
			raise exception

	def remove_fragments( self, text: str ) -> str | None:
		"""Remove very short token fragments from normalized text.

		Purpose:
		    Removes short text fragments that are unlikely to be useful lexical units. This helps reduce
		    noise produced by OCR, markup stripping, punctuation removal, and aggressive token cleanup.

		Args:
		    text: Text value to process.

		Returns:
		    str | None: Processed text value when the operation succeeds.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'text', text )
			_text = text.lower( )
			_cleaned = [ ]
			_fragments = _text.split( )
			for char in _fragments:
				if len( char ) > 2:
					_cleaned.append( char )
			return ' '.join( _cleaned )
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = 'remove_fragments( self, text: str ) -> str:'
			raise exception

	def remove_symbols( self, text: str ) -> str | None:
		"""Remove configured symbol characters from normalized text.

		Purpose:
		    Removes characters listed in the parser symbol set from lowercase text. This produces cleaner
		    text for tokenization, word-frequency generation, and embedding workflows.

		Args:
		    text: Text value to process.

		Returns:
		    str | None: Processed text value when the operation succeeds.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'text', text )
			_text = text.lower( )
			return ''.join( c for c in _text if c not in self.SYMBOLS )
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = 'remove_symbols( self, text: str ) -> str:'
			raise exception

	def remove_html( self, text: str ) -> str | None:
		"""Extract visible text from HTML markup.

		Purpose:
		    Parses HTML input with BeautifulSoup and extracts visible text content. This allows raw HTML
		    fragments or pages to enter the same cleaning pipeline used for plain text.

		Args:
		    text: Text value to process.

		Returns:
		    str | None: Processed text value when the operation succeeds.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'text', text )
			self.raw_html = text
			cleaned_html = BeautifulSoup( self.raw_html, 'html.parser' ).get_text( )
			return cleaned_html
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = 'remove_html( self, text: str ) -> str'
			raise exception

	def remove_xml( self, text: str ) -> str:
		"""Extract inner text from XML-like markup while recovering malformed fragments when possible.

		Purpose:
		    Wraps XML-like text in a temporary root node, parses it with recovery enabled, and
		    concatenates element text and tail content. This retains readable content while discarding
		    markup structure.

		Args:
		    text: Text value to process.

		Returns:
		    str: Processed text value produced by the operation.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		throw_if( 'text', text )
		try:
			_text = text.lower( )
			wrapped_text = f"<root>{_text}</root>"
			parser = etree.XMLParser( recover=True, remove_comments=True,
				remove_blank_text=False )

			root = etree.fromstring( wrapped_text.encode( "utf-8" ), parser )
			text_parts = [ ]
			for element in root.iter( ):
				if element.text:
					text_parts.append( element.text )
				if element.tail:
					text_parts.append( element.tail )

			return "".join( text_parts )
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = 'remove_xml( self, text: str ) -> str'
			raise exception

	def remove_markdown( self, text: str ) -> str | None:
		"""Remove common Markdown links, image syntax, and formatting markers.

		Purpose:
		    Removes common Markdown link, image, and inline-formatting syntax from lowercase text. This
		    converts README-style or documentation-style content into cleaner text for downstream
		    analysis.

		Args:
		    text: Text value to process.

		Returns:
		    str | None: Processed text value when the operation succeeds.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'text', text )
			self.raw_input = text.lower( )
			_text = re.sub( r'\[.*?]\(.*?\)', ' ', self.raw_input )
			_unmarked = re.sub( r'[`_*#~><-]', ' ', _text )
			self.cleaned_text = re.sub( r'!\[.*?]\(.*?\)', ' ', _unmarked )
			return self.cleaned_text
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = 'remove_markdown( self, path: str ) -> str'
			raise exception

	def remove_stopwords( self, text: str ) -> str | None:
		"""Remove English stop words from tokenized text.

		Purpose:
		    Tokenizes lowercase text and removes standard English stop words. This leaves a reduced token
		    stream better suited for frequency analysis, vocabulary extraction, and embedding preparation.

		Args:
		    text: Text value to process.

		Returns:
		    str | None: Processed text value when the operation succeeds.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'text', text )
			_stop_words = set( stopwords.words( 'english' ) )
			_text = text.lower( )
			_tokens = word_tokenize( _text )
			_filtered = [ token for token in _tokens if
			              token.isalnum( ) and token not in _stop_words ]
			return ' '.join( _filtered )
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = 'remove_stopwords( self, text: str ) -> str'
			raise exception

	def remove_encodings( self, text: str ) -> str | None:
		"""Resolve HTML entities, normalize Unicode characters, and remove control characters.

		Purpose:
		    Decodes common escaped sequences when possible, resolves HTML entities, normalizes Unicode to
		    compatibility form, and strips control characters. This reduces text artifacts from scraped,
		    copied, or encoded sources.

		Args:
		    text: Text value to process.

		Returns:
		    str | None: Processed text value when the operation succeeds.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'text', text )
			try:
				_text = text.lower( )
				text = bytes( _text, 'utf-8' ).decode( 'unicode_escape' )
			except UnicodeDecodeError:
				pass

			self.raw_input = text
			_html = html.unescape( self.raw_input )
			_norm = unicodedata.normalize( 'NFKC', _html )
			_chars = re.sub( r'[\x00-\x1F\x7F]', '', _norm )
			cleaned_text = _chars.strip( )
			return cleaned_text
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = 'remove_encodings( self, text: str ) -> str'
			raise exception

	def remove_headers( self, filepath: str, lines: int=50, headers: int=3,
			footers: int=3 ) -> str | None:
		"""Detect and remove repeated page headers and footers from a text file.

		Purpose:
		    Splits a text file into page-sized blocks and identifies repeated leading and trailing line
		    groups. Matching header and footer blocks are removed to produce cleaner body text for
		    analysis.

		Args:
		    filepath: Path to the local source file.
		    lines: Number of lines treated as one page during header and footer detection.
		    headers: Number of leading lines considered as a repeated page header.
		    footers: Number of trailing lines considered as a repeated page footer.

		Returns:
		    str | None: Processed text value when the operation succeeds.

		Raises:
		    FileNotFoundError: If a required local file or matched path does not exist.
		    ValueError: If a required value is missing, blank, or outside the supported range.
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'filepath', filepath )
			if not os.path.exists( filepath ):
				raise FileNotFoundError( f'File not found: {filepath}' )
			else:
				self.file_path = filepath
			if lines < 6:
				raise ValueError( 'Argument \"lines_per_page\" should be at least 6.' )
			if headers < 0 or footers < 0:
				msg = 'Arguments \"header_lines\" and \"footer_lines\" must be non-negative.'
				raise ValueError( msg )

			with open( self.file_path, 'r', encoding='utf-8', errors='ignore' ) as fh:
				self.lines = fh.readlines( )

			self.pages = [ self.lines[ i: i + lines ] for i in
			               range( 0, len( self.lines ), lines ) ]

			header_counts = { }
			footer_counts = { }
			for page in self.pages:
				n = len( page )
				if n == 0:
					continue

				if headers > 0 and n >= headers:
					hdr = tuple( page[ :headers ] )
					if hdr in header_counts:
						header_counts[ hdr ] += 1
					else:
						header_counts[ hdr ] = 1

				if footers > 0 and n >= footers:
					ftr = tuple( page[ -footers: ] )
					if ftr in footer_counts:
						footer_counts[ ftr ] += 1
					else:
						footer_counts[ ftr ] = 1

			common_header = ( )
			if header_counts:
				common_header = max( header_counts.items( ), key=lambda kv: kv[ 1 ] )[ 0 ]

			common_footer = ( )
			if footer_counts:
				common_footer = max( footer_counts.items( ), key=lambda kv: kv[ 1 ] )[ 0 ]

			cleaned_pages = [ ]
			for page in self.pages:
				lines = list( page )

				if common_header and len( lines ) >= len( common_header ):
					if tuple( lines[ : len( common_header ) ] ) == common_header:
						lines = lines[ len( common_header ): ]

				if common_footer and len( lines ) >= len( common_footer ):
					if tuple( lines[ -len( common_footer ): ] ) == common_footer:
						lines = lines[ : -len( common_footer ) ]

				cleaned_pages.append( ''.join( lines ) )
			return '\n'.join( cleaned_pages )
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = 'remove_headers( self, filepath: str ) -> str'
			raise exception

	def remove_numbers( self, text: str ) -> str | None:
		"""Remove decimal digits from text.

		Purpose:
		    Removes digit sequences from lowercase text. This supports workflows that need lexical content
		    without numeric values.

		Args:
		    text: Text value to process.

		Returns:
		    str | None: Processed text value when the operation succeeds.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'text', text )
			_text = text.lower( )
			return re.sub( r'\d+', '', _text )
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = 'remove_encodings( self, text: str ) -> str'
			raise exception

	def remove_numerals( self, text: str ) -> str | None:
		"""Remove Roman-numeral patterns from text.

		Purpose:
		    Applies the configured Roman-numeral expression to lowercase text and replaces matching
		    numeral tokens with spaces. This reduces numbering artifacts in outlines, headings, and
		    document sections.

		Args:
		    text: Text value to process.

		Returns:
		    str | None: Processed text value when the operation succeeds.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'text', text )
			self.raw_input = text.lower( )
			self.cleaned_text = re.sub( self.NUMERALS, ' ', self.raw_input, flags=re.IGNORECASE, )
			return self.cleaned_text
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = 'remove_numerals( self, text: str ) -> str'
			raise exception

	def remove_images( self, text: str ) -> str:
		"""Remove Markdown image references, HTML image elements, and direct image URLs.

		Purpose:
		    Removes Markdown image syntax, HTML image tags, and direct image URLs from text. This keeps
		    descriptive text while excluding image-only references that do not support text processing.

		Args:
		    text: Text value to process.

		Returns:
		    str: Processed text value produced by the operation.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		throw_if( "text", text )

		try:
			self.raw_input = text

			# Remove Markdown images: ![alt](path)
			without_markdown_images = re.sub(
				r"!\[[^\]]*]\([^)]*\)",
				" ",
				self.raw_input
			)

			# Remove HTML <img> tags
			without_html_images = re.sub(
				r"<img\b[^>]*>",
				" ",
				without_markdown_images,
				flags=re.IGNORECASE
			)

			# Remove standalone image URLs
			self.parsed_text = re.sub(
				r"https?://\S+\.(png|jpg|jpeg|gif|bmp|svg|webp)",
				" ",
				without_html_images,
				flags=re.IGNORECASE
			)

			return self.parsed_text
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = ('remove_formatting( self, text: str ) -> str')
			raise exception

	def tiktokenize( self, text: str, encoding: str = 'cl100k_base' ) -> DataFrame | None:
		"""Encode text with a tiktoken tokenizer and return token identifiers as tabular data.

		Purpose:
		    Encodes lowercase text using the requested tiktoken encoding and returns token identifiers in
		    a pandas DataFrame. This supports token inspection and model-facing preprocessing workflows.

		Args:
		    text: Text value to process.
		    encoding: Tiktoken encoding name used for tokenization.

		Returns:
		    DataFrame | None: Pandas DataFrame containing the processed output when the operation
		    succeeds.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'text', text )
			_text = text.lower( )
			self.encoding = tiktoken.get_encoding( encoding )
			token_ids = self.encoding.encode( _text )
			_data = pd.DataFrame( token_ids )
			return _data
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = ('tiktokenize( self, text, encoding) -> List[ int ]')
			raise exception

	def split_sentences( self, text: str ) -> List[ str ] | None:
		"""Split text into sentence strings using NLTK sentence tokenization.

		Purpose:
		    Applies NLTK sentence tokenization to lowercase text and returns the resulting sentence list.
		    This provides sentence boundaries for chunking, cleaning, and dataset generation workflows.

		Args:
		    text: Text value to process.

		Returns:
		    List[ str ] | None: List of processed text values when the operation succeeds.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'text', text )
			_text = text.lower( )
			_sentences = sent_tokenize( _text )
			return _sentences
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = 'split_sentences( self, text: str ) -> DataFrame'
			raise exception

	def split_pages( self, filepath: str, num: int=50 ) -> List[ str ] | None:
		"""Split a text file into page-sized text blocks.

		Purpose:
		    Reads a plain-text file and splits it into page-sized blocks using form-feed characters when
		    available or fixed line counts otherwise. The resulting list can be used for page- level
		    cleaning and analysis.

		Args:
		    filepath: Path to the local source file.
		    num: Number of lines used as the fallback page boundary.

		Returns:
		    List[ str ] | None: List of processed text values when the operation succeeds.

		Raises:
		    FileNotFoundError: If a required local file or matched path does not exist.
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'filepath', filepath )
			if not os.path.exists( filepath ):
				raise FileNotFoundError( f'File not found: {filepath}' )
			else:
				self.file_path = filepath
			with open( self.file_path, 'r', encoding='utf-8', errors='ignore' ) as file:
				content = file.read( )
			if '\f' in content:
				return [ page.strip( ) for page in content.split( '\f' ) if page.strip( ) ]
			self.lines = content.splitlines( )
			i = 0
			n = len( self.lines )
			while i < n:
				page_lines = self.lines[ i: i + num ]
				page_text = '\n'.join( page_lines ).strip( )
				if page_text:
					self.pages.append( page_text )
				i += num
			return self.pages
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = 'split_pages( file_path )'
			raise exception

	def split_paragraphs( self, filepath: str ) -> DataFrame | None:
		"""Read a text file and return paragraph-like text blocks as tabular data.

		Purpose:
		    Reads a text file and converts separated text blocks into a pandas DataFrame. The fallback
		    Latin-1 branch preserves the ability to process files that fail UTF-8 decoding.

		Args:
		    filepath: Path to the local source file.

		Returns:
		    DataFrame | None: Pandas DataFrame containing the processed output when the operation
		    succeeds.

		Raises:
		    FileNotFoundError: If a required local file or matched path does not exist.
		"""
		try:
			throw_if( 'filepath', filepath )
			if not os.path.exists( filepath ):
				raise FileNotFoundError( f'File not found: {filepath}' )
			else:
				self.file_path = filepath
			with open( self.file_path, 'r', encoding='utf-8', errors='ignore' ) as file:
				_input = file.read( )
				_paragraphs = [ pg.strip( ) for pg in _input.split( ' ' ) if pg.strip( ) ]
				_data = pd.DataFrame( _paragraphs )
				return _data
		except UnicodeDecodeError:
			with open( self.file_path, 'r', encoding='latin1', errors='ignore' ) as file:
				_input = file.read( )
				_paragraphs = [ pg.strip( ) for pg in _input.split( ' ' ) if pg.strip( ) ]
				_data = pd.DataFrame( _paragraphs )
				return _data

	def create_frequency_distribution( self, tokens: List[ str ] ) -> DataFrame | None:
		"""Build a word-frequency table from a token sequence.

		Purpose:
		    Counts token occurrences with NLTK frequency distribution support and returns a labeled pandas
		    DataFrame. The output provides a simple word-frequency table for analysis and reporting.

		Args:
		    tokens: Token sequence used by the processing operation.

		Returns:
		    DataFrame | None: Pandas DataFrame containing the processed output when the operation
		    succeeds.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'tokens', tokens )
			self.tokens = tokens
			_freqdist = FreqDist( dict( Counter( self.tokens ) ) )
			_words = _freqdist.items( )
			_data = pd.DataFrame( _words, columns=[ 'Word', 'Frequency' ] )
			_data.index.name = 'ID'
			return _data
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = 'create_frequency_distribution(self, tokens: List[ str ])->DataFrame'
			raise exception

	def create_vocabulary( self, tokens: List[ str ] ) -> Series | None:
		"""Extract the vocabulary column from a token-frequency table.

		Purpose:
		    Counts token occurrences and returns the unique token column as a pandas Series. This gives
		    downstream routines a vocabulary list derived from the active token stream.

		Args:
		    tokens: Token sequence used by the processing operation.

		Returns:
		    Series | None: Pandas Series containing the processed output when the operation succeeds.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'tokens', tokens )
			self.tokens = tokens
			_freqdist = FreqDist( dict( Counter( self.tokens ) ) )
			_vocab = _freqdist.items( )
			_vocabulary = pd.DataFrame( _vocab, columns=[ 'Word', 'Frequency' ] )
			_words = _vocabulary.iloc[ :, 0 ]
			return _words
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = ('create_vocabulary(self, freq_dist: dict, min: int=1)->List[str]')
			raise exception

	def create_wordbag( self, tokens: List[ str ] ) -> DataFrame | None:
		"""Build a bag-of-words table from a token sequence.

		Purpose:
		    Builds a bag-of-words representation by extracting unique terms from the token frequency
		    distribution. The returned DataFrame supports simple vocabulary inspection and feature
		    preparation.

		Args:
		    tokens: Token sequence used by the processing operation.

		Returns:
		    DataFrame | None: Pandas DataFrame containing the processed output when the operation
		    succeeds.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'tokens', tokens )
			self.tokens = tokens
			_freqdist = FreqDist( dict( Counter( self.tokens ) ) )
			_words = _freqdist.keys( )
			_data = pd.DataFrame( _words )
			return _data
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = 'create_wordbag( self, words: List[ str ] ) -> dict'
			raise exception

	def create_vectors( self, tokens: List[ str ] ) -> DataFrame | None:
		"""Create TF-IDF vectors for token values.

		Purpose:
		    Builds one-token documents, fits a TF-IDF vectorizer, and maps each token to its vector
		    representation. This supplies lightweight vector features for lexical comparison workflows.

		Args:
		    tokens: Token sequence used by the processing operation.

		Returns:
		    DataFrame | None: Pandas DataFrame containing the processed output when the operation
		    succeeds.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			fake_docs = [ [ word ] for word in tokens ]
			joined_docs = [ ' '.join( doc ) for doc in fake_docs ]
			vectorizer = TfidfVectorizer( )
			X = vectorizer.fit_transform( joined_docs )
			feature_names = vectorizer.get_feature_names_out( )
			embeddings = { }
			for idx, word in enumerate( tokens ):
				vector = X[ idx ].toarray( ).flatten( )
				embeddings[ word ] = vector

			_data = pd.DataFrame( data=embeddings, columns=feature_names )
			return embeddings
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = 'create_vectors( self, tokens: List[str]) -> Dict[str, np.ndarray]'
			raise exception

	def clean_file( self, filepath: str ) -> str | None:
		"""Apply the standard Fonky text-cleaning pipeline to a single file.

		Purpose:
		    Runs a single file through the parser cleaning pipeline, including whitespace normalization,
		    encoding cleanup, symbol removal, fragment filtering, lemmatization, and stop-word removal.
		    The method returns the cleaned text instead of writing a file.

		Args:
		    filepath: Path to the local source file.

		Returns:
		    str | None: Processed text value when the operation succeeds.

		Raises:
		    FileNotFoundError: If a required local file or matched path does not exist.
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'filepath', filepath )
			if not os.path.exists( filepath ):
				raise FileNotFoundError( f'File not found: {filepath}' )
			else:
				_sourcepath = filepath
				_text = open( _sourcepath, 'r', encoding='utf-8', errors='ignore' ).read( )
				_collapsed = self.collapse_whitespace( _text )
				_compressed = self.compress_whitespace( _collapsed )
				_normalized = self.normalize_text( _compressed )
				_encoded = self.remove_encodings( _normalized )
				_special = self.remove_symbols( _encoded )
				_cleaned = self.remove_fragments( _special )
				_recompress = self.compress_whitespace( _cleaned )
				_lemmatized = self.lemmatize_text( _recompress )
				_stops = self.remove_stopwords( _lemmatized )
				return _stops
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = 'clean_file( self, src: str ) -> str'
			raise exception

	def clean_files( self, source: str, destination: str ) -> None:
		"""Apply the standard Fonky text-cleaning pipeline to every file in a directory.

		Purpose:
		    Processes every file in a source directory through the standard cleaning pipeline and writes
		    cleaned text to a destination directory. This supports batch preparation of corpora before
		    chunking or dataset creation.

		Args:
		    source: Directory containing source text files.
		    destination: Directory where generated output files are written.

		Returns:
		    None: The operation completes without producing a return value.

		Raises:
		    FileNotFoundError: If a required local file or matched path does not exist.
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'src', source )
			throw_if( 'dest', destination )
			if not os.path.exists( source ):
				raise FileNotFoundError( f'File not found: {source}' )
			elif not os.path.exists( destination ):
				raise FileNotFoundError( f'File not found: {destination}' )
			else:
				_source = source
				_destpath = destination
				_files = os.listdir( _source )
				for f in _files:
					_processed = [ ]
					_filename = os.path.basename( f )
					_sourcepath = _source + '\\' + _filename
					_text = open( _sourcepath, 'r', encoding='utf-8', errors='ignore' ).read( )
					_collapsed = self.collapse_whitespace( _text )
					_compressed = self.compress_whitespace( _collapsed )
					_normalized = self.normalize_text( _compressed )
					_encoded = self.remove_encodings( _normalized )
					_special = self.remove_symbols( _encoded )
					_cleaned = self.remove_fragments( _special )
					_recompress = self.compress_whitespace( _cleaned )
					_lemmatized = self.lemmatize_text( _recompress )
					_stops = self.remove_stopwords( _lemmatized )
					_sentences = self.split_sentences( _stops )
					_destination = _destpath + '\\' + _filename
					_clean = open( _destination, 'wt', encoding='utf-8', errors='ignore' )
					_lines = ' '.join( _sentences )
					_clean.write( _lines )
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = 'clean_files( self, src: str, dest: str )'
			raise exception

	def chunk_files( self, source: str, destination: str ) -> None:
		"""Split text files into sentence chunks and write chunked output files.

		Purpose:
		    Reads each file in a source directory, splits text into sentences, and writes the resulting
		    sentence sequence to matching output files. This prepares cleaned corpora for chunk-based
		    downstream workflows.

		Args:
		    source: Directory containing source text files.
		    destination: Directory where generated output files are written.

		Returns:
		    None: The operation completes without producing a return value.

		Raises:
		    FileNotFoundError: If a required local file or matched path does not exist.
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'src', source )
			throw_if( 'dest', destination )
			if not os.path.exists( source ):
				raise FileNotFoundError( f'File not found: {source}' )
			elif not os.path.exists( destination ):
				raise FileNotFoundError( f'File not found: {destination}' )
			else:
				_source = source
				_destination = destination
				_files = os.listdir( _source )
				_words = [ ]
				for f in _files:
					_processed = [ ]
					_filename = os.path.basename( f )
					_sourcepath = _source + '\\' + _filename
					_text = open( _sourcepath, 'r', encoding='utf-8', errors='ignore' ).read( )
					_sentences = self.split_sentences( _text )
					_datamap = [ ]
					for v in _sentences:
						_datamap.append( v )

					for s in _datamap:
						_processed.append( s )

					_final = _destination + '\\' + _filename
					_clean = open( _final, 'wt', encoding='utf-8', errors='ignore' )
					for p in _processed:
						_clean.write( p )
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = 'chunk_files( self, src: str, dest: str )'
			raise exception

	def chunk_data( self, filepath: str, size: int=10 ) -> DataFrame | None:
		"""Chunk a single text file into fixed-size word groups represented as tabular data.

		Purpose:
		    Reads a single text file, filters recognized English alphabetic tokens, groups them into
		    fixed-size chunks, and returns the chunk rows as a DataFrame. This provides a compact dataset-
		    ready representation of token groups.

		Args:
		    filepath: Path to the local source file.
		    size: Maximum number of tokens or sentences grouped into each chunk.

		Returns:
		    DataFrame | None: Pandas DataFrame containing the processed output when the operation
		    succeeds.

		Raises:
		    FileNotFoundError: If a required local file or matched path does not exist.
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'filepath', filepath )
			if not os.path.exists( filepath ):
				raise FileNotFoundError( f'File not found: {filepath}' )
			else:
				_source = filepath
				_processed = [ ]
				_wordlist = [ ]
				_vocab = words.words( 'en' )
				_text = open( _source, 'r', encoding='utf-8', errors='ignore' ).read( )
				_lower = _text.lower( )
				_tokens = _lower.split( )
				for s in _tokens:
					if s.isalpha( ) and s in _vocab:
						_wordlist.append( s )
				self.chunks = [ _wordlist[ i: i + size ] for i in
				                range( 0, len( _wordlist ), size ) ]
				for i, c in enumerate( self.chunks ):
					_item = '[' + ' '.join( c ) + '],'
					_processed.append( _item )
				_data = pd.DataFrame( _processed )
				return _data
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = 'chunk_data( self, filepath: str, size: int=512  ) -> DataFrame'
			raise exception

	def chunk_datasets( self, source: str, destination: str, size: int=10 ) -> DataFrame:
		"""Clean and chunk a directory of text files into spreadsheet datasets.

		Purpose:
		    Processes all text files in a directory through cleaning, tokenization, fixed-size chunking,
		    and Excel export. This creates spreadsheet datasets suitable for review, labeling, or later
		    ingestion.

		Args:
		    source: Directory containing source text files.
		    destination: Directory where generated output files are written.
		    size: Maximum number of tokens or sentences grouped into each chunk.

		Returns:
		    DataFrame: Pandas DataFrame containing the processed output.

		Raises:
		    FileNotFoundError: If a required local file or matched path does not exist.
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'filepath', source )
			throw_if( 'destination', destination )
			if not os.path.exists( source ):
				raise FileNotFoundError( f'File not found: {source}' )
			elif not os.path.exists( destination ):
				raise FileNotFoundError( f'File not found: {destination}' )
			else:
				_src = source
				_destination = destination
				_files = os.listdir( _src )
				_words = [ ]
				for f in _files:
					_processed = [ ]
					_filename = os.path.basename( f )
					_sourcepath = _src + '\\' + _filename
					_text = open( _sourcepath, 'r', encoding='utf-8', errors='ignore' ).read( )
					_collapsed = self.collapse_whitespace( _text )
					_compressed = self.compress_whitespace( _collapsed )
					_normalized = self.normalize_text( _compressed )
					_encoded = self.remove_encodings( _normalized )
					_special = self.remove_symbols( _encoded )
					_cleaned = self.remove_fragments( _special )
					_recompress = self.compress_whitespace( _cleaned )
					_lemmatized = self.lemmatize_text( _recompress )
					_stops = self.remove_stopwords( _lemmatized )
					_tokens = _stops.split( None )
					_chunks = [ _tokens[ i: i + size ] for i in range( 0, len( _tokens ), size ) ]
					_datamap = [ ]
					for i, c in enumerate( _chunks ):
						_row = ' '.join( c )
						_datamap.append( _row )

					for s in _datamap:
						_processed.append( s )

					_name = _filename.replace( '.txt', '.xlsx' )
					_savepath = (_destination + f'\\' + _name)
					_data = pd.DataFrame( _processed, columns=[ 'Data', ] )
					_data.to_excel( _savepath, sheet_name='Dataset', index=False,
						columns=[ 'Data', ] )
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = 'chunk_data( self, filepath: str, size: int=15  ) -> DataFrame'
			raise exception

	def convert_jsonl( self, source: str, destination: str, size: int=10 ) -> None:
		"""Convert text files into line-oriented JSON-like chunk output.

		Purpose:
		    Splits text files into fixed-size token groups and writes each group using a JSON-like line-
		    oriented representation. This supports quick conversion of raw text corpora into chunked
		    training or testing artifacts.

		Args:
		    source: Directory containing source text files.
		    destination: Directory where generated output files are written.
		    size: Maximum number of tokens or sentences grouped into each chunk.

		Returns:
		    None: The operation completes without producing a return value.

		Raises:
		    FileNotFoundError: If a required local file or matched path does not exist.
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'source', source )
			throw_if( 'destination', destination )
			if not os.path.exists( source ):
				raise FileNotFoundError( f'File not found: {source}' )
			elif not os.path.exists( destination ):
				raise FileNotFoundError( f'File not found: {destination}' )
			else:
				_source = source
				_destpath = destination
				_files = os.listdir( _source )
				_wordlist = [ ]
				for f in _files:
					_processed = [ ]
					_filename = os.path.basename( f )
					_sourcepath = _source + '\\' + _filename
					_text = open( _sourcepath, 'r', encoding='utf-8', errors='ignore' ).read( )
					_tokens = _text.split( ' ' )
					_chunks = [ _tokens[ i: i + size ] for i in range( 0, len( _tokens ), size ) ]
					_datamap = [ ]
					for i, c in enumerate( _chunks ):
						_value = '{ ' + f' {i} : [ ' + ' '.join( c ) + ' ] }, ' + "\n"
						_datamap.append( _value )

					for s in _datamap:
						_processed.append( s )

					_destination = _destpath + '\\' + _filename.replace( '.txt', '.jsonl' )
					_clean = open( _destination, 'wt', encoding='utf-8', errors='ignore' )
					for p in _processed:
						_clean.write( p )
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = 'convert_jsonl( self, source: str, desination: str )'
			raise exception

	def encode_sentences( self, tokens: List[ str ], model: str = 'all-MiniLM-L6-v2' ) -> \
			Tuple[ List[ str ], np.ndarray ]:
		"""Generate sentence-transformer embeddings for normalized token values.

		Purpose:
		    Lemmatizes token values and encodes them with a SentenceTransformer model. The returned tuple
		    pairs token text with a NumPy embedding matrix for semantic-search workflows.

		Args:
		    tokens: Token sequence used by the processing operation.
		    model: Sentence-transformer model used to encode the query or token sequence.

		Returns:
		    Tuple[ List[ str ], np.ndarray ]: Token values paired with the generated embedding matrix.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'tokens', tokens )
			throw_if( 'model', model )
			_transformer = SentenceTransformer( model )
			_tokens = [ self.lemmatizer.lemmatize( t ) for t in tokens ]
			_encoding = _transformer.encode( _tokens, show_progress_bar=True )
			return (self.cleaned_tokens, np.array( _encoding ))
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = 'encode_sentences( self, sentences: List[ str ], model_name ) -> ( )'
			raise exception

	def semantic_search( self, query: str, tokens: List[ str ], embeddings: np.ndarray,
			model: SentenceTransformer, top: int=5 ) -> List[ tuple[ str, float ] ]:
		"""Rank embedded tokens by semantic similarity to a query.

		Purpose:
		    Encodes the query with the supplied model, compares it with the embedding matrix using cosine
		    similarity, and returns the highest-scoring token matches. This supports lightweight semantic
		    retrieval over prepared token embeddings.

		Args:
		    query: Search text or semantic query submitted to the operation.
		    tokens: Token sequence used by the processing operation.
		    embeddings: Precomputed embedding matrix compared against the query vector.
		    model: Sentence-transformer model used to encode the query or token sequence.
		    top: Maximum number of ranked semantic-search matches to return.

		Returns:
		    List[ tuple[ str, float ] ]: Ranked token and similarity-score pairs.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'query', query )
			throw_if( 'tokens', tokens )
			throw_if( 'embedding', embeddings )
			throw_if( 'model', model )
			query_vec = model.encode( [ query ] )
			sims = cosine_similarity( query_vec, embeddings )[ 0 ]
			top_indices = sims.argsort( )[ ::-1 ][ : top ]
			return [ (tokens[ i ], sims[ i ]) for i in top_indices ]
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = ('semantic_search( self, query: str, tokens: List[ str ], '
			                    'embeddings: np.ndarray, model: SentenceTransformer,  '
			                    'top_k: int=5 ) -> List[ tuple[ str, float ] ]')
			raise exception

load_text

load_text(filepath: str) -> str | None

Read UTF-8 text from a local file and return the raw string.

Purpose

Loads a local text file using UTF-8 with ignored decode errors so downstream cleaning routines can operate on a plain string. The method records the active file path and raises a project Error when the file cannot be read.

Parameters:

Name Type Description Default
filepath str

Path to the local source file.

required

Returns:

Type Description
str | None

str | None: Processed text value when the operation succeeds.

Raises:

Type Description
FileNotFoundError

If a required local file or matched path does not exist.

Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def load_text( self, filepath: str ) -> str | None:
	"""Read UTF-8 text from a local file and return the raw string.

	Purpose:
	    Loads a local text file using UTF-8 with ignored decode errors so downstream cleaning routines
	    can operate on a plain string. The method records the active file path and raises a project
	    Error when the file cannot be read.

	Args:
	    filepath: Path to the local source file.

	Returns:
	    str | None: Processed text value when the operation succeeds.

	Raises:
	    FileNotFoundError: If a required local file or matched path does not exist.
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'filepath', filepath )
		if not os.path.exists( filepath ):
			raise FileNotFoundError( f'File not found: {filepath}' )
		else:
			self.file_path = filepath
		raw_text = open( self.file_path, mode='r', encoding='utf-8', errors='ignore' ).read( )
		return raw_text
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = 'load_text( self, file_path: str ) -> str'
		raise exception

collapse_whitespace

collapse_whitespace(text: str) -> str | None

Normalize spacing by lowercasing text and collapsing repeated whitespace.

Purpose

Creates a compact lowercase representation of text by splitting on whitespace and joining tokens with single spaces. This prepares raw text for deterministic comparison, cleaning, and tokenization steps.

Parameters:

Name Type Description Default
text str

Text value to process.

required

Returns:

Type Description
str | None

str | None: Processed text value when the operation succeeds.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def collapse_whitespace( self, text: str ) -> str | None:
	"""Normalize spacing by lowercasing text and collapsing repeated whitespace.

	Purpose:
	    Creates a compact lowercase representation of text by splitting on whitespace and joining
	    tokens with single spaces. This prepares raw text for deterministic comparison, cleaning, and
	    tokenization steps.

	Args:
	    text: Text value to process.

	Returns:
	    str | None: Processed text value when the operation succeeds.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'text', text )
		_text = text.lower( )
		return ' '.join( _text.split( ) )
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = 'collapse_whitespace( self, path: str ) -> str:'
		raise exception

remove_punctuation

remove_punctuation(text: str) -> str

Strip punctuation from tokenized text while preserving word and spacing content.

Purpose

Tokenizes lowercase text and removes punctuation marks from each token. The method preserves alphanumeric token content while returning a whitespace-joined string for later cleaning stages.

Parameters:

Name Type Description Default
text str

Text value to process.

required

Returns:

Name Type Description
str str

Processed text value produced by the operation.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def remove_punctuation( self, text: str ) -> str:
	"""Strip punctuation from tokenized text while preserving word and spacing content.

	Purpose:
	    Tokenizes lowercase text and removes punctuation marks from each token. The method preserves
	    alphanumeric token content while returning a whitespace-joined string for later cleaning
	    stages.

	Args:
	    text: Text value to process.

	Returns:
	    str: Processed text value produced by the operation.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'text', text )
		_text = text.lower( )
		_tokens = word_tokenize( _text )
		cleaned_tokens = [ re.sub( r'[^\w\s]', '', t ) for t in _tokens if
		                   re.sub( r'[^\w\s]', '', t ) ]
		return ' '.join( cleaned_tokens )
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = 'remove_punctuation( self, text: str ) -> str:'
		raise exception

normalize_text

normalize_text(text: str) -> str | None

Convert text to lowercase for stable downstream comparison and tokenization.

Purpose

Converts text to lowercase without otherwise changing content. This provides a simple normalization stage for workflows that need case-insensitive matching or tokenization.

Parameters:

Name Type Description Default
text str

Text value to process.

required

Returns:

Type Description
str | None

str | None: Processed text value when the operation succeeds.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def normalize_text( self, text: str ) -> str | None:
	"""Convert text to lowercase for stable downstream comparison and tokenization.

	Purpose:
	    Converts text to lowercase without otherwise changing content. This provides a simple
	    normalization stage for workflows that need case-insensitive matching or tokenization.

	Args:
	    text: Text value to process.

	Returns:
	    str | None: Processed text value when the operation succeeds.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'text', text )
		return text.lower( )
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = 'normalize_text( self, text: str ) -> str:'
		raise exception

remove_errors

remove_errors(text: str) -> str

Filter tokens against the NLTK English words corpus.

Purpose

Uses the NLTK English words corpus as a vocabulary filter and keeps only tokens recognized by that corpus. This reduces obvious OCR, spelling, and parsing artifacts before later analysis.

Parameters:

Name Type Description Default
text str

Text value to process.

required

Returns:

Name Type Description
str str

Processed text value produced by the operation.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def remove_errors( self, text: str ) -> str:
	"""Filter tokens against the NLTK English words corpus.

	Purpose:
	    Uses the NLTK English words corpus as a vocabulary filter and keeps only tokens recognized by
	    that corpus. This reduces obvious OCR, spelling, and parsing artifacts before later analysis.

	Args:
	    text: Text value to process.

	Returns:
	    str: Processed text value produced by the operation.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'text', text )
		_vocab = words.words( 'en' )
		_text = text.lower( )
		_tokens = _text.split( )
		_words = [ w for w in _tokens if w in _vocab ]
		_data = ' '.join( _words )
		return _data
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = 'remove_errors( self, text: str  ) -> str'
		raise exception

remove_fragments

remove_fragments(text: str) -> str | None

Remove very short token fragments from normalized text.

Purpose

Removes short text fragments that are unlikely to be useful lexical units. This helps reduce noise produced by OCR, markup stripping, punctuation removal, and aggressive token cleanup.

Parameters:

Name Type Description Default
text str

Text value to process.

required

Returns:

Type Description
str | None

str | None: Processed text value when the operation succeeds.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def remove_fragments( self, text: str ) -> str | None:
	"""Remove very short token fragments from normalized text.

	Purpose:
	    Removes short text fragments that are unlikely to be useful lexical units. This helps reduce
	    noise produced by OCR, markup stripping, punctuation removal, and aggressive token cleanup.

	Args:
	    text: Text value to process.

	Returns:
	    str | None: Processed text value when the operation succeeds.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'text', text )
		_text = text.lower( )
		_cleaned = [ ]
		_fragments = _text.split( )
		for char in _fragments:
			if len( char ) > 2:
				_cleaned.append( char )
		return ' '.join( _cleaned )
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = 'remove_fragments( self, text: str ) -> str:'
		raise exception

remove_symbols

remove_symbols(text: str) -> str | None

Remove configured symbol characters from normalized text.

Purpose

Removes characters listed in the parser symbol set from lowercase text. This produces cleaner text for tokenization, word-frequency generation, and embedding workflows.

Parameters:

Name Type Description Default
text str

Text value to process.

required

Returns:

Type Description
str | None

str | None: Processed text value when the operation succeeds.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def remove_symbols( self, text: str ) -> str | None:
	"""Remove configured symbol characters from normalized text.

	Purpose:
	    Removes characters listed in the parser symbol set from lowercase text. This produces cleaner
	    text for tokenization, word-frequency generation, and embedding workflows.

	Args:
	    text: Text value to process.

	Returns:
	    str | None: Processed text value when the operation succeeds.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'text', text )
		_text = text.lower( )
		return ''.join( c for c in _text if c not in self.SYMBOLS )
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = 'remove_symbols( self, text: str ) -> str:'
		raise exception

remove_html

remove_html(text: str) -> str | None

Extract visible text from HTML markup.

Purpose

Parses HTML input with BeautifulSoup and extracts visible text content. This allows raw HTML fragments or pages to enter the same cleaning pipeline used for plain text.

Parameters:

Name Type Description Default
text str

Text value to process.

required

Returns:

Type Description
str | None

str | None: Processed text value when the operation succeeds.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def remove_html( self, text: str ) -> str | None:
	"""Extract visible text from HTML markup.

	Purpose:
	    Parses HTML input with BeautifulSoup and extracts visible text content. This allows raw HTML
	    fragments or pages to enter the same cleaning pipeline used for plain text.

	Args:
	    text: Text value to process.

	Returns:
	    str | None: Processed text value when the operation succeeds.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'text', text )
		self.raw_html = text
		cleaned_html = BeautifulSoup( self.raw_html, 'html.parser' ).get_text( )
		return cleaned_html
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = 'remove_html( self, text: str ) -> str'
		raise exception

remove_xml

remove_xml(text: str) -> str

Extract inner text from XML-like markup while recovering malformed fragments when possible.

Purpose

Wraps XML-like text in a temporary root node, parses it with recovery enabled, and concatenates element text and tail content. This retains readable content while discarding markup structure.

Parameters:

Name Type Description Default
text str

Text value to process.

required

Returns:

Name Type Description
str str

Processed text value produced by the operation.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def remove_xml( self, text: str ) -> str:
	"""Extract inner text from XML-like markup while recovering malformed fragments when possible.

	Purpose:
	    Wraps XML-like text in a temporary root node, parses it with recovery enabled, and
	    concatenates element text and tail content. This retains readable content while discarding
	    markup structure.

	Args:
	    text: Text value to process.

	Returns:
	    str: Processed text value produced by the operation.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	throw_if( 'text', text )
	try:
		_text = text.lower( )
		wrapped_text = f"<root>{_text}</root>"
		parser = etree.XMLParser( recover=True, remove_comments=True,
			remove_blank_text=False )

		root = etree.fromstring( wrapped_text.encode( "utf-8" ), parser )
		text_parts = [ ]
		for element in root.iter( ):
			if element.text:
				text_parts.append( element.text )
			if element.tail:
				text_parts.append( element.tail )

		return "".join( text_parts )
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = 'remove_xml( self, text: str ) -> str'
		raise exception

remove_markdown

remove_markdown(text: str) -> str | None

Remove common Markdown links, image syntax, and formatting markers.

Purpose

Removes common Markdown link, image, and inline-formatting syntax from lowercase text. This converts README-style or documentation-style content into cleaner text for downstream analysis.

Parameters:

Name Type Description Default
text str

Text value to process.

required

Returns:

Type Description
str | None

str | None: Processed text value when the operation succeeds.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def remove_markdown( self, text: str ) -> str | None:
	"""Remove common Markdown links, image syntax, and formatting markers.

	Purpose:
	    Removes common Markdown link, image, and inline-formatting syntax from lowercase text. This
	    converts README-style or documentation-style content into cleaner text for downstream
	    analysis.

	Args:
	    text: Text value to process.

	Returns:
	    str | None: Processed text value when the operation succeeds.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'text', text )
		self.raw_input = text.lower( )
		_text = re.sub( r'\[.*?]\(.*?\)', ' ', self.raw_input )
		_unmarked = re.sub( r'[`_*#~><-]', ' ', _text )
		self.cleaned_text = re.sub( r'!\[.*?]\(.*?\)', ' ', _unmarked )
		return self.cleaned_text
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = 'remove_markdown( self, path: str ) -> str'
		raise exception

remove_stopwords

remove_stopwords(text: str) -> str | None

Remove English stop words from tokenized text.

Purpose

Tokenizes lowercase text and removes standard English stop words. This leaves a reduced token stream better suited for frequency analysis, vocabulary extraction, and embedding preparation.

Parameters:

Name Type Description Default
text str

Text value to process.

required

Returns:

Type Description
str | None

str | None: Processed text value when the operation succeeds.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def remove_stopwords( self, text: str ) -> str | None:
	"""Remove English stop words from tokenized text.

	Purpose:
	    Tokenizes lowercase text and removes standard English stop words. This leaves a reduced token
	    stream better suited for frequency analysis, vocabulary extraction, and embedding preparation.

	Args:
	    text: Text value to process.

	Returns:
	    str | None: Processed text value when the operation succeeds.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'text', text )
		_stop_words = set( stopwords.words( 'english' ) )
		_text = text.lower( )
		_tokens = word_tokenize( _text )
		_filtered = [ token for token in _tokens if
		              token.isalnum( ) and token not in _stop_words ]
		return ' '.join( _filtered )
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = 'remove_stopwords( self, text: str ) -> str'
		raise exception

remove_encodings

remove_encodings(text: str) -> str | None

Resolve HTML entities, normalize Unicode characters, and remove control characters.

Purpose

Decodes common escaped sequences when possible, resolves HTML entities, normalizes Unicode to compatibility form, and strips control characters. This reduces text artifacts from scraped, copied, or encoded sources.

Parameters:

Name Type Description Default
text str

Text value to process.

required

Returns:

Type Description
str | None

str | None: Processed text value when the operation succeeds.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def remove_encodings( self, text: str ) -> str | None:
	"""Resolve HTML entities, normalize Unicode characters, and remove control characters.

	Purpose:
	    Decodes common escaped sequences when possible, resolves HTML entities, normalizes Unicode to
	    compatibility form, and strips control characters. This reduces text artifacts from scraped,
	    copied, or encoded sources.

	Args:
	    text: Text value to process.

	Returns:
	    str | None: Processed text value when the operation succeeds.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'text', text )
		try:
			_text = text.lower( )
			text = bytes( _text, 'utf-8' ).decode( 'unicode_escape' )
		except UnicodeDecodeError:
			pass

		self.raw_input = text
		_html = html.unescape( self.raw_input )
		_norm = unicodedata.normalize( 'NFKC', _html )
		_chars = re.sub( r'[\x00-\x1F\x7F]', '', _norm )
		cleaned_text = _chars.strip( )
		return cleaned_text
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = 'remove_encodings( self, text: str ) -> str'
		raise exception

remove_headers

remove_headers(
    filepath: str,
    lines: int = 50,
    headers: int = 3,
    footers: int = 3,
) -> str | None

Detect and remove repeated page headers and footers from a text file.

Purpose

Splits a text file into page-sized blocks and identifies repeated leading and trailing line groups. Matching header and footer blocks are removed to produce cleaner body text for analysis.

Parameters:

Name Type Description Default
filepath str

Path to the local source file.

required
lines int

Number of lines treated as one page during header and footer detection.

50
headers int

Number of leading lines considered as a repeated page header.

3
footers int

Number of trailing lines considered as a repeated page footer.

3

Returns:

Type Description
str | None

str | None: Processed text value when the operation succeeds.

Raises:

Type Description
FileNotFoundError

If a required local file or matched path does not exist.

ValueError

If a required value is missing, blank, or outside the supported range.

Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def remove_headers( self, filepath: str, lines: int=50, headers: int=3,
		footers: int=3 ) -> str | None:
	"""Detect and remove repeated page headers and footers from a text file.

	Purpose:
	    Splits a text file into page-sized blocks and identifies repeated leading and trailing line
	    groups. Matching header and footer blocks are removed to produce cleaner body text for
	    analysis.

	Args:
	    filepath: Path to the local source file.
	    lines: Number of lines treated as one page during header and footer detection.
	    headers: Number of leading lines considered as a repeated page header.
	    footers: Number of trailing lines considered as a repeated page footer.

	Returns:
	    str | None: Processed text value when the operation succeeds.

	Raises:
	    FileNotFoundError: If a required local file or matched path does not exist.
	    ValueError: If a required value is missing, blank, or outside the supported range.
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'filepath', filepath )
		if not os.path.exists( filepath ):
			raise FileNotFoundError( f'File not found: {filepath}' )
		else:
			self.file_path = filepath
		if lines < 6:
			raise ValueError( 'Argument \"lines_per_page\" should be at least 6.' )
		if headers < 0 or footers < 0:
			msg = 'Arguments \"header_lines\" and \"footer_lines\" must be non-negative.'
			raise ValueError( msg )

		with open( self.file_path, 'r', encoding='utf-8', errors='ignore' ) as fh:
			self.lines = fh.readlines( )

		self.pages = [ self.lines[ i: i + lines ] for i in
		               range( 0, len( self.lines ), lines ) ]

		header_counts = { }
		footer_counts = { }
		for page in self.pages:
			n = len( page )
			if n == 0:
				continue

			if headers > 0 and n >= headers:
				hdr = tuple( page[ :headers ] )
				if hdr in header_counts:
					header_counts[ hdr ] += 1
				else:
					header_counts[ hdr ] = 1

			if footers > 0 and n >= footers:
				ftr = tuple( page[ -footers: ] )
				if ftr in footer_counts:
					footer_counts[ ftr ] += 1
				else:
					footer_counts[ ftr ] = 1

		common_header = ( )
		if header_counts:
			common_header = max( header_counts.items( ), key=lambda kv: kv[ 1 ] )[ 0 ]

		common_footer = ( )
		if footer_counts:
			common_footer = max( footer_counts.items( ), key=lambda kv: kv[ 1 ] )[ 0 ]

		cleaned_pages = [ ]
		for page in self.pages:
			lines = list( page )

			if common_header and len( lines ) >= len( common_header ):
				if tuple( lines[ : len( common_header ) ] ) == common_header:
					lines = lines[ len( common_header ): ]

			if common_footer and len( lines ) >= len( common_footer ):
				if tuple( lines[ -len( common_footer ): ] ) == common_footer:
					lines = lines[ : -len( common_footer ) ]

			cleaned_pages.append( ''.join( lines ) )
		return '\n'.join( cleaned_pages )
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = 'remove_headers( self, filepath: str ) -> str'
		raise exception

remove_numbers

remove_numbers(text: str) -> str | None

Remove decimal digits from text.

Purpose

Removes digit sequences from lowercase text. This supports workflows that need lexical content without numeric values.

Parameters:

Name Type Description Default
text str

Text value to process.

required

Returns:

Type Description
str | None

str | None: Processed text value when the operation succeeds.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def remove_numbers( self, text: str ) -> str | None:
	"""Remove decimal digits from text.

	Purpose:
	    Removes digit sequences from lowercase text. This supports workflows that need lexical content
	    without numeric values.

	Args:
	    text: Text value to process.

	Returns:
	    str | None: Processed text value when the operation succeeds.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'text', text )
		_text = text.lower( )
		return re.sub( r'\d+', '', _text )
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = 'remove_encodings( self, text: str ) -> str'
		raise exception

remove_numerals

remove_numerals(text: str) -> str | None

Remove Roman-numeral patterns from text.

Purpose

Applies the configured Roman-numeral expression to lowercase text and replaces matching numeral tokens with spaces. This reduces numbering artifacts in outlines, headings, and document sections.

Parameters:

Name Type Description Default
text str

Text value to process.

required

Returns:

Type Description
str | None

str | None: Processed text value when the operation succeeds.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def remove_numerals( self, text: str ) -> str | None:
	"""Remove Roman-numeral patterns from text.

	Purpose:
	    Applies the configured Roman-numeral expression to lowercase text and replaces matching
	    numeral tokens with spaces. This reduces numbering artifacts in outlines, headings, and
	    document sections.

	Args:
	    text: Text value to process.

	Returns:
	    str | None: Processed text value when the operation succeeds.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'text', text )
		self.raw_input = text.lower( )
		self.cleaned_text = re.sub( self.NUMERALS, ' ', self.raw_input, flags=re.IGNORECASE, )
		return self.cleaned_text
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = 'remove_numerals( self, text: str ) -> str'
		raise exception

remove_images

remove_images(text: str) -> str

Remove Markdown image references, HTML image elements, and direct image URLs.

Purpose

Removes Markdown image syntax, HTML image tags, and direct image URLs from text. This keeps descriptive text while excluding image-only references that do not support text processing.

Parameters:

Name Type Description Default
text str

Text value to process.

required

Returns:

Name Type Description
str str

Processed text value produced by the operation.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def remove_images( self, text: str ) -> str:
	"""Remove Markdown image references, HTML image elements, and direct image URLs.

	Purpose:
	    Removes Markdown image syntax, HTML image tags, and direct image URLs from text. This keeps
	    descriptive text while excluding image-only references that do not support text processing.

	Args:
	    text: Text value to process.

	Returns:
	    str: Processed text value produced by the operation.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	throw_if( "text", text )

	try:
		self.raw_input = text

		# Remove Markdown images: ![alt](path)
		without_markdown_images = re.sub(
			r"!\[[^\]]*]\([^)]*\)",
			" ",
			self.raw_input
		)

		# Remove HTML <img> tags
		without_html_images = re.sub(
			r"<img\b[^>]*>",
			" ",
			without_markdown_images,
			flags=re.IGNORECASE
		)

		# Remove standalone image URLs
		self.parsed_text = re.sub(
			r"https?://\S+\.(png|jpg|jpeg|gif|bmp|svg|webp)",
			" ",
			without_html_images,
			flags=re.IGNORECASE
		)

		return self.parsed_text
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = ('remove_formatting( self, text: str ) -> str')
		raise exception

tiktokenize

tiktokenize(
    text: str, encoding: str = "cl100k_base"
) -> DataFrame | None

Encode text with a tiktoken tokenizer and return token identifiers as tabular data.

Purpose

Encodes lowercase text using the requested tiktoken encoding and returns token identifiers in a pandas DataFrame. This supports token inspection and model-facing preprocessing workflows.

Parameters:

Name Type Description Default
text str

Text value to process.

required
encoding str

Tiktoken encoding name used for tokenization.

'cl100k_base'

Returns:

Type Description
DataFrame | None

DataFrame | None: Pandas DataFrame containing the processed output when the operation

DataFrame | None

succeeds.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def tiktokenize( self, text: str, encoding: str = 'cl100k_base' ) -> DataFrame | None:
	"""Encode text with a tiktoken tokenizer and return token identifiers as tabular data.

	Purpose:
	    Encodes lowercase text using the requested tiktoken encoding and returns token identifiers in
	    a pandas DataFrame. This supports token inspection and model-facing preprocessing workflows.

	Args:
	    text: Text value to process.
	    encoding: Tiktoken encoding name used for tokenization.

	Returns:
	    DataFrame | None: Pandas DataFrame containing the processed output when the operation
	    succeeds.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'text', text )
		_text = text.lower( )
		self.encoding = tiktoken.get_encoding( encoding )
		token_ids = self.encoding.encode( _text )
		_data = pd.DataFrame( token_ids )
		return _data
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = ('tiktokenize( self, text, encoding) -> List[ int ]')
		raise exception

split_sentences

split_sentences(text: str) -> List[str] | None

Split text into sentence strings using NLTK sentence tokenization.

Purpose

Applies NLTK sentence tokenization to lowercase text and returns the resulting sentence list. This provides sentence boundaries for chunking, cleaning, and dataset generation workflows.

Parameters:

Name Type Description Default
text str

Text value to process.

required

Returns:

Type Description
List[str] | None

List[ str ] | None: List of processed text values when the operation succeeds.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def split_sentences( self, text: str ) -> List[ str ] | None:
	"""Split text into sentence strings using NLTK sentence tokenization.

	Purpose:
	    Applies NLTK sentence tokenization to lowercase text and returns the resulting sentence list.
	    This provides sentence boundaries for chunking, cleaning, and dataset generation workflows.

	Args:
	    text: Text value to process.

	Returns:
	    List[ str ] | None: List of processed text values when the operation succeeds.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'text', text )
		_text = text.lower( )
		_sentences = sent_tokenize( _text )
		return _sentences
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = 'split_sentences( self, text: str ) -> DataFrame'
		raise exception

split_pages

split_pages(
    filepath: str, num: int = 50
) -> List[str] | None

Split a text file into page-sized text blocks.

Purpose

Reads a plain-text file and splits it into page-sized blocks using form-feed characters when available or fixed line counts otherwise. The resulting list can be used for page- level cleaning and analysis.

Parameters:

Name Type Description Default
filepath str

Path to the local source file.

required
num int

Number of lines used as the fallback page boundary.

50

Returns:

Type Description
List[str] | None

List[ str ] | None: List of processed text values when the operation succeeds.

Raises:

Type Description
FileNotFoundError

If a required local file or matched path does not exist.

Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def split_pages( self, filepath: str, num: int=50 ) -> List[ str ] | None:
	"""Split a text file into page-sized text blocks.

	Purpose:
	    Reads a plain-text file and splits it into page-sized blocks using form-feed characters when
	    available or fixed line counts otherwise. The resulting list can be used for page- level
	    cleaning and analysis.

	Args:
	    filepath: Path to the local source file.
	    num: Number of lines used as the fallback page boundary.

	Returns:
	    List[ str ] | None: List of processed text values when the operation succeeds.

	Raises:
	    FileNotFoundError: If a required local file or matched path does not exist.
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'filepath', filepath )
		if not os.path.exists( filepath ):
			raise FileNotFoundError( f'File not found: {filepath}' )
		else:
			self.file_path = filepath
		with open( self.file_path, 'r', encoding='utf-8', errors='ignore' ) as file:
			content = file.read( )
		if '\f' in content:
			return [ page.strip( ) for page in content.split( '\f' ) if page.strip( ) ]
		self.lines = content.splitlines( )
		i = 0
		n = len( self.lines )
		while i < n:
			page_lines = self.lines[ i: i + num ]
			page_text = '\n'.join( page_lines ).strip( )
			if page_text:
				self.pages.append( page_text )
			i += num
		return self.pages
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = 'split_pages( file_path )'
		raise exception

split_paragraphs

split_paragraphs(filepath: str) -> DataFrame | None

Read a text file and return paragraph-like text blocks as tabular data.

Purpose

Reads a text file and converts separated text blocks into a pandas DataFrame. The fallback Latin-1 branch preserves the ability to process files that fail UTF-8 decoding.

Parameters:

Name Type Description Default
filepath str

Path to the local source file.

required

Returns:

Type Description
DataFrame | None

DataFrame | None: Pandas DataFrame containing the processed output when the operation

DataFrame | None

succeeds.

Raises:

Type Description
FileNotFoundError

If a required local file or matched path does not exist.

Source code in processors.py
def split_paragraphs( self, filepath: str ) -> DataFrame | None:
	"""Read a text file and return paragraph-like text blocks as tabular data.

	Purpose:
	    Reads a text file and converts separated text blocks into a pandas DataFrame. The fallback
	    Latin-1 branch preserves the ability to process files that fail UTF-8 decoding.

	Args:
	    filepath: Path to the local source file.

	Returns:
	    DataFrame | None: Pandas DataFrame containing the processed output when the operation
	    succeeds.

	Raises:
	    FileNotFoundError: If a required local file or matched path does not exist.
	"""
	try:
		throw_if( 'filepath', filepath )
		if not os.path.exists( filepath ):
			raise FileNotFoundError( f'File not found: {filepath}' )
		else:
			self.file_path = filepath
		with open( self.file_path, 'r', encoding='utf-8', errors='ignore' ) as file:
			_input = file.read( )
			_paragraphs = [ pg.strip( ) for pg in _input.split( ' ' ) if pg.strip( ) ]
			_data = pd.DataFrame( _paragraphs )
			return _data
	except UnicodeDecodeError:
		with open( self.file_path, 'r', encoding='latin1', errors='ignore' ) as file:
			_input = file.read( )
			_paragraphs = [ pg.strip( ) for pg in _input.split( ' ' ) if pg.strip( ) ]
			_data = pd.DataFrame( _paragraphs )
			return _data

create_frequency_distribution

create_frequency_distribution(
    tokens: List[str],
) -> DataFrame | None

Build a word-frequency table from a token sequence.

Purpose

Counts token occurrences with NLTK frequency distribution support and returns a labeled pandas DataFrame. The output provides a simple word-frequency table for analysis and reporting.

Parameters:

Name Type Description Default
tokens List[str]

Token sequence used by the processing operation.

required

Returns:

Type Description
DataFrame | None

DataFrame | None: Pandas DataFrame containing the processed output when the operation

DataFrame | None

succeeds.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def create_frequency_distribution( self, tokens: List[ str ] ) -> DataFrame | None:
	"""Build a word-frequency table from a token sequence.

	Purpose:
	    Counts token occurrences with NLTK frequency distribution support and returns a labeled pandas
	    DataFrame. The output provides a simple word-frequency table for analysis and reporting.

	Args:
	    tokens: Token sequence used by the processing operation.

	Returns:
	    DataFrame | None: Pandas DataFrame containing the processed output when the operation
	    succeeds.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'tokens', tokens )
		self.tokens = tokens
		_freqdist = FreqDist( dict( Counter( self.tokens ) ) )
		_words = _freqdist.items( )
		_data = pd.DataFrame( _words, columns=[ 'Word', 'Frequency' ] )
		_data.index.name = 'ID'
		return _data
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = 'create_frequency_distribution(self, tokens: List[ str ])->DataFrame'
		raise exception

create_vocabulary

create_vocabulary(tokens: List[str]) -> Series | None

Extract the vocabulary column from a token-frequency table.

Purpose

Counts token occurrences and returns the unique token column as a pandas Series. This gives downstream routines a vocabulary list derived from the active token stream.

Parameters:

Name Type Description Default
tokens List[str]

Token sequence used by the processing operation.

required

Returns:

Type Description
Series | None

Series | None: Pandas Series containing the processed output when the operation succeeds.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def create_vocabulary( self, tokens: List[ str ] ) -> Series | None:
	"""Extract the vocabulary column from a token-frequency table.

	Purpose:
	    Counts token occurrences and returns the unique token column as a pandas Series. This gives
	    downstream routines a vocabulary list derived from the active token stream.

	Args:
	    tokens: Token sequence used by the processing operation.

	Returns:
	    Series | None: Pandas Series containing the processed output when the operation succeeds.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'tokens', tokens )
		self.tokens = tokens
		_freqdist = FreqDist( dict( Counter( self.tokens ) ) )
		_vocab = _freqdist.items( )
		_vocabulary = pd.DataFrame( _vocab, columns=[ 'Word', 'Frequency' ] )
		_words = _vocabulary.iloc[ :, 0 ]
		return _words
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = ('create_vocabulary(self, freq_dist: dict, min: int=1)->List[str]')
		raise exception

create_wordbag

create_wordbag(tokens: List[str]) -> DataFrame | None

Build a bag-of-words table from a token sequence.

Purpose

Builds a bag-of-words representation by extracting unique terms from the token frequency distribution. The returned DataFrame supports simple vocabulary inspection and feature preparation.

Parameters:

Name Type Description Default
tokens List[str]

Token sequence used by the processing operation.

required

Returns:

Type Description
DataFrame | None

DataFrame | None: Pandas DataFrame containing the processed output when the operation

DataFrame | None

succeeds.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def create_wordbag( self, tokens: List[ str ] ) -> DataFrame | None:
	"""Build a bag-of-words table from a token sequence.

	Purpose:
	    Builds a bag-of-words representation by extracting unique terms from the token frequency
	    distribution. The returned DataFrame supports simple vocabulary inspection and feature
	    preparation.

	Args:
	    tokens: Token sequence used by the processing operation.

	Returns:
	    DataFrame | None: Pandas DataFrame containing the processed output when the operation
	    succeeds.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'tokens', tokens )
		self.tokens = tokens
		_freqdist = FreqDist( dict( Counter( self.tokens ) ) )
		_words = _freqdist.keys( )
		_data = pd.DataFrame( _words )
		return _data
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = 'create_wordbag( self, words: List[ str ] ) -> dict'
		raise exception

create_vectors

create_vectors(tokens: List[str]) -> DataFrame | None

Create TF-IDF vectors for token values.

Purpose

Builds one-token documents, fits a TF-IDF vectorizer, and maps each token to its vector representation. This supplies lightweight vector features for lexical comparison workflows.

Parameters:

Name Type Description Default
tokens List[str]

Token sequence used by the processing operation.

required

Returns:

Type Description
DataFrame | None

DataFrame | None: Pandas DataFrame containing the processed output when the operation

DataFrame | None

succeeds.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def create_vectors( self, tokens: List[ str ] ) -> DataFrame | None:
	"""Create TF-IDF vectors for token values.

	Purpose:
	    Builds one-token documents, fits a TF-IDF vectorizer, and maps each token to its vector
	    representation. This supplies lightweight vector features for lexical comparison workflows.

	Args:
	    tokens: Token sequence used by the processing operation.

	Returns:
	    DataFrame | None: Pandas DataFrame containing the processed output when the operation
	    succeeds.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		fake_docs = [ [ word ] for word in tokens ]
		joined_docs = [ ' '.join( doc ) for doc in fake_docs ]
		vectorizer = TfidfVectorizer( )
		X = vectorizer.fit_transform( joined_docs )
		feature_names = vectorizer.get_feature_names_out( )
		embeddings = { }
		for idx, word in enumerate( tokens ):
			vector = X[ idx ].toarray( ).flatten( )
			embeddings[ word ] = vector

		_data = pd.DataFrame( data=embeddings, columns=feature_names )
		return embeddings
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = 'create_vectors( self, tokens: List[str]) -> Dict[str, np.ndarray]'
		raise exception

clean_file

clean_file(filepath: str) -> str | None

Apply the standard Fonky text-cleaning pipeline to a single file.

Purpose

Runs a single file through the parser cleaning pipeline, including whitespace normalization, encoding cleanup, symbol removal, fragment filtering, lemmatization, and stop-word removal. The method returns the cleaned text instead of writing a file.

Parameters:

Name Type Description Default
filepath str

Path to the local source file.

required

Returns:

Type Description
str | None

str | None: Processed text value when the operation succeeds.

Raises:

Type Description
FileNotFoundError

If a required local file or matched path does not exist.

Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def clean_file( self, filepath: str ) -> str | None:
	"""Apply the standard Fonky text-cleaning pipeline to a single file.

	Purpose:
	    Runs a single file through the parser cleaning pipeline, including whitespace normalization,
	    encoding cleanup, symbol removal, fragment filtering, lemmatization, and stop-word removal.
	    The method returns the cleaned text instead of writing a file.

	Args:
	    filepath: Path to the local source file.

	Returns:
	    str | None: Processed text value when the operation succeeds.

	Raises:
	    FileNotFoundError: If a required local file or matched path does not exist.
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'filepath', filepath )
		if not os.path.exists( filepath ):
			raise FileNotFoundError( f'File not found: {filepath}' )
		else:
			_sourcepath = filepath
			_text = open( _sourcepath, 'r', encoding='utf-8', errors='ignore' ).read( )
			_collapsed = self.collapse_whitespace( _text )
			_compressed = self.compress_whitespace( _collapsed )
			_normalized = self.normalize_text( _compressed )
			_encoded = self.remove_encodings( _normalized )
			_special = self.remove_symbols( _encoded )
			_cleaned = self.remove_fragments( _special )
			_recompress = self.compress_whitespace( _cleaned )
			_lemmatized = self.lemmatize_text( _recompress )
			_stops = self.remove_stopwords( _lemmatized )
			return _stops
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = 'clean_file( self, src: str ) -> str'
		raise exception

clean_files

clean_files(source: str, destination: str) -> None

Apply the standard Fonky text-cleaning pipeline to every file in a directory.

Purpose

Processes every file in a source directory through the standard cleaning pipeline and writes cleaned text to a destination directory. This supports batch preparation of corpora before chunking or dataset creation.

Parameters:

Name Type Description Default
source str

Directory containing source text files.

required
destination str

Directory where generated output files are written.

required

Returns:

Name Type Description
None None

The operation completes without producing a return value.

Raises:

Type Description
FileNotFoundError

If a required local file or matched path does not exist.

Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def clean_files( self, source: str, destination: str ) -> None:
	"""Apply the standard Fonky text-cleaning pipeline to every file in a directory.

	Purpose:
	    Processes every file in a source directory through the standard cleaning pipeline and writes
	    cleaned text to a destination directory. This supports batch preparation of corpora before
	    chunking or dataset creation.

	Args:
	    source: Directory containing source text files.
	    destination: Directory where generated output files are written.

	Returns:
	    None: The operation completes without producing a return value.

	Raises:
	    FileNotFoundError: If a required local file or matched path does not exist.
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'src', source )
		throw_if( 'dest', destination )
		if not os.path.exists( source ):
			raise FileNotFoundError( f'File not found: {source}' )
		elif not os.path.exists( destination ):
			raise FileNotFoundError( f'File not found: {destination}' )
		else:
			_source = source
			_destpath = destination
			_files = os.listdir( _source )
			for f in _files:
				_processed = [ ]
				_filename = os.path.basename( f )
				_sourcepath = _source + '\\' + _filename
				_text = open( _sourcepath, 'r', encoding='utf-8', errors='ignore' ).read( )
				_collapsed = self.collapse_whitespace( _text )
				_compressed = self.compress_whitespace( _collapsed )
				_normalized = self.normalize_text( _compressed )
				_encoded = self.remove_encodings( _normalized )
				_special = self.remove_symbols( _encoded )
				_cleaned = self.remove_fragments( _special )
				_recompress = self.compress_whitespace( _cleaned )
				_lemmatized = self.lemmatize_text( _recompress )
				_stops = self.remove_stopwords( _lemmatized )
				_sentences = self.split_sentences( _stops )
				_destination = _destpath + '\\' + _filename
				_clean = open( _destination, 'wt', encoding='utf-8', errors='ignore' )
				_lines = ' '.join( _sentences )
				_clean.write( _lines )
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = 'clean_files( self, src: str, dest: str )'
		raise exception

chunk_files

chunk_files(source: str, destination: str) -> None

Split text files into sentence chunks and write chunked output files.

Purpose

Reads each file in a source directory, splits text into sentences, and writes the resulting sentence sequence to matching output files. This prepares cleaned corpora for chunk-based downstream workflows.

Parameters:

Name Type Description Default
source str

Directory containing source text files.

required
destination str

Directory where generated output files are written.

required

Returns:

Name Type Description
None None

The operation completes without producing a return value.

Raises:

Type Description
FileNotFoundError

If a required local file or matched path does not exist.

Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def chunk_files( self, source: str, destination: str ) -> None:
	"""Split text files into sentence chunks and write chunked output files.

	Purpose:
	    Reads each file in a source directory, splits text into sentences, and writes the resulting
	    sentence sequence to matching output files. This prepares cleaned corpora for chunk-based
	    downstream workflows.

	Args:
	    source: Directory containing source text files.
	    destination: Directory where generated output files are written.

	Returns:
	    None: The operation completes without producing a return value.

	Raises:
	    FileNotFoundError: If a required local file or matched path does not exist.
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'src', source )
		throw_if( 'dest', destination )
		if not os.path.exists( source ):
			raise FileNotFoundError( f'File not found: {source}' )
		elif not os.path.exists( destination ):
			raise FileNotFoundError( f'File not found: {destination}' )
		else:
			_source = source
			_destination = destination
			_files = os.listdir( _source )
			_words = [ ]
			for f in _files:
				_processed = [ ]
				_filename = os.path.basename( f )
				_sourcepath = _source + '\\' + _filename
				_text = open( _sourcepath, 'r', encoding='utf-8', errors='ignore' ).read( )
				_sentences = self.split_sentences( _text )
				_datamap = [ ]
				for v in _sentences:
					_datamap.append( v )

				for s in _datamap:
					_processed.append( s )

				_final = _destination + '\\' + _filename
				_clean = open( _final, 'wt', encoding='utf-8', errors='ignore' )
				for p in _processed:
					_clean.write( p )
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = 'chunk_files( self, src: str, dest: str )'
		raise exception

chunk_data

chunk_data(
    filepath: str, size: int = 10
) -> DataFrame | None

Chunk a single text file into fixed-size word groups represented as tabular data.

Purpose

Reads a single text file, filters recognized English alphabetic tokens, groups them into fixed-size chunks, and returns the chunk rows as a DataFrame. This provides a compact dataset- ready representation of token groups.

Parameters:

Name Type Description Default
filepath str

Path to the local source file.

required
size int

Maximum number of tokens or sentences grouped into each chunk.

10

Returns:

Type Description
DataFrame | None

DataFrame | None: Pandas DataFrame containing the processed output when the operation

DataFrame | None

succeeds.

Raises:

Type Description
FileNotFoundError

If a required local file or matched path does not exist.

Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def chunk_data( self, filepath: str, size: int=10 ) -> DataFrame | None:
	"""Chunk a single text file into fixed-size word groups represented as tabular data.

	Purpose:
	    Reads a single text file, filters recognized English alphabetic tokens, groups them into
	    fixed-size chunks, and returns the chunk rows as a DataFrame. This provides a compact dataset-
	    ready representation of token groups.

	Args:
	    filepath: Path to the local source file.
	    size: Maximum number of tokens or sentences grouped into each chunk.

	Returns:
	    DataFrame | None: Pandas DataFrame containing the processed output when the operation
	    succeeds.

	Raises:
	    FileNotFoundError: If a required local file or matched path does not exist.
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'filepath', filepath )
		if not os.path.exists( filepath ):
			raise FileNotFoundError( f'File not found: {filepath}' )
		else:
			_source = filepath
			_processed = [ ]
			_wordlist = [ ]
			_vocab = words.words( 'en' )
			_text = open( _source, 'r', encoding='utf-8', errors='ignore' ).read( )
			_lower = _text.lower( )
			_tokens = _lower.split( )
			for s in _tokens:
				if s.isalpha( ) and s in _vocab:
					_wordlist.append( s )
			self.chunks = [ _wordlist[ i: i + size ] for i in
			                range( 0, len( _wordlist ), size ) ]
			for i, c in enumerate( self.chunks ):
				_item = '[' + ' '.join( c ) + '],'
				_processed.append( _item )
			_data = pd.DataFrame( _processed )
			return _data
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = 'chunk_data( self, filepath: str, size: int=512  ) -> DataFrame'
		raise exception

chunk_datasets

chunk_datasets(
    source: str, destination: str, size: int = 10
) -> DataFrame

Clean and chunk a directory of text files into spreadsheet datasets.

Purpose

Processes all text files in a directory through cleaning, tokenization, fixed-size chunking, and Excel export. This creates spreadsheet datasets suitable for review, labeling, or later ingestion.

Parameters:

Name Type Description Default
source str

Directory containing source text files.

required
destination str

Directory where generated output files are written.

required
size int

Maximum number of tokens or sentences grouped into each chunk.

10

Returns:

Name Type Description
DataFrame DataFrame

Pandas DataFrame containing the processed output.

Raises:

Type Description
FileNotFoundError

If a required local file or matched path does not exist.

Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def chunk_datasets( self, source: str, destination: str, size: int=10 ) -> DataFrame:
	"""Clean and chunk a directory of text files into spreadsheet datasets.

	Purpose:
	    Processes all text files in a directory through cleaning, tokenization, fixed-size chunking,
	    and Excel export. This creates spreadsheet datasets suitable for review, labeling, or later
	    ingestion.

	Args:
	    source: Directory containing source text files.
	    destination: Directory where generated output files are written.
	    size: Maximum number of tokens or sentences grouped into each chunk.

	Returns:
	    DataFrame: Pandas DataFrame containing the processed output.

	Raises:
	    FileNotFoundError: If a required local file or matched path does not exist.
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'filepath', source )
		throw_if( 'destination', destination )
		if not os.path.exists( source ):
			raise FileNotFoundError( f'File not found: {source}' )
		elif not os.path.exists( destination ):
			raise FileNotFoundError( f'File not found: {destination}' )
		else:
			_src = source
			_destination = destination
			_files = os.listdir( _src )
			_words = [ ]
			for f in _files:
				_processed = [ ]
				_filename = os.path.basename( f )
				_sourcepath = _src + '\\' + _filename
				_text = open( _sourcepath, 'r', encoding='utf-8', errors='ignore' ).read( )
				_collapsed = self.collapse_whitespace( _text )
				_compressed = self.compress_whitespace( _collapsed )
				_normalized = self.normalize_text( _compressed )
				_encoded = self.remove_encodings( _normalized )
				_special = self.remove_symbols( _encoded )
				_cleaned = self.remove_fragments( _special )
				_recompress = self.compress_whitespace( _cleaned )
				_lemmatized = self.lemmatize_text( _recompress )
				_stops = self.remove_stopwords( _lemmatized )
				_tokens = _stops.split( None )
				_chunks = [ _tokens[ i: i + size ] for i in range( 0, len( _tokens ), size ) ]
				_datamap = [ ]
				for i, c in enumerate( _chunks ):
					_row = ' '.join( c )
					_datamap.append( _row )

				for s in _datamap:
					_processed.append( s )

				_name = _filename.replace( '.txt', '.xlsx' )
				_savepath = (_destination + f'\\' + _name)
				_data = pd.DataFrame( _processed, columns=[ 'Data', ] )
				_data.to_excel( _savepath, sheet_name='Dataset', index=False,
					columns=[ 'Data', ] )
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = 'chunk_data( self, filepath: str, size: int=15  ) -> DataFrame'
		raise exception

convert_jsonl

convert_jsonl(
    source: str, destination: str, size: int = 10
) -> None

Convert text files into line-oriented JSON-like chunk output.

Purpose

Splits text files into fixed-size token groups and writes each group using a JSON-like line- oriented representation. This supports quick conversion of raw text corpora into chunked training or testing artifacts.

Parameters:

Name Type Description Default
source str

Directory containing source text files.

required
destination str

Directory where generated output files are written.

required
size int

Maximum number of tokens or sentences grouped into each chunk.

10

Returns:

Name Type Description
None None

The operation completes without producing a return value.

Raises:

Type Description
FileNotFoundError

If a required local file or matched path does not exist.

Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def convert_jsonl( self, source: str, destination: str, size: int=10 ) -> None:
	"""Convert text files into line-oriented JSON-like chunk output.

	Purpose:
	    Splits text files into fixed-size token groups and writes each group using a JSON-like line-
	    oriented representation. This supports quick conversion of raw text corpora into chunked
	    training or testing artifacts.

	Args:
	    source: Directory containing source text files.
	    destination: Directory where generated output files are written.
	    size: Maximum number of tokens or sentences grouped into each chunk.

	Returns:
	    None: The operation completes without producing a return value.

	Raises:
	    FileNotFoundError: If a required local file or matched path does not exist.
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'source', source )
		throw_if( 'destination', destination )
		if not os.path.exists( source ):
			raise FileNotFoundError( f'File not found: {source}' )
		elif not os.path.exists( destination ):
			raise FileNotFoundError( f'File not found: {destination}' )
		else:
			_source = source
			_destpath = destination
			_files = os.listdir( _source )
			_wordlist = [ ]
			for f in _files:
				_processed = [ ]
				_filename = os.path.basename( f )
				_sourcepath = _source + '\\' + _filename
				_text = open( _sourcepath, 'r', encoding='utf-8', errors='ignore' ).read( )
				_tokens = _text.split( ' ' )
				_chunks = [ _tokens[ i: i + size ] for i in range( 0, len( _tokens ), size ) ]
				_datamap = [ ]
				for i, c in enumerate( _chunks ):
					_value = '{ ' + f' {i} : [ ' + ' '.join( c ) + ' ] }, ' + "\n"
					_datamap.append( _value )

				for s in _datamap:
					_processed.append( s )

				_destination = _destpath + '\\' + _filename.replace( '.txt', '.jsonl' )
				_clean = open( _destination, 'wt', encoding='utf-8', errors='ignore' )
				for p in _processed:
					_clean.write( p )
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = 'convert_jsonl( self, source: str, desination: str )'
		raise exception

encode_sentences

encode_sentences(
    tokens: List[str], model: str = "all-MiniLM-L6-v2"
) -> Tuple[List[str], np.ndarray]

Generate sentence-transformer embeddings for normalized token values.

Purpose

Lemmatizes token values and encodes them with a SentenceTransformer model. The returned tuple pairs token text with a NumPy embedding matrix for semantic-search workflows.

Parameters:

Name Type Description Default
tokens List[str]

Token sequence used by the processing operation.

required
model str

Sentence-transformer model used to encode the query or token sequence.

'all-MiniLM-L6-v2'

Returns:

Type Description
Tuple[List[str], ndarray]

Tuple[ List[ str ], np.ndarray ]: Token values paired with the generated embedding matrix.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def encode_sentences( self, tokens: List[ str ], model: str = 'all-MiniLM-L6-v2' ) -> \
		Tuple[ List[ str ], np.ndarray ]:
	"""Generate sentence-transformer embeddings for normalized token values.

	Purpose:
	    Lemmatizes token values and encodes them with a SentenceTransformer model. The returned tuple
	    pairs token text with a NumPy embedding matrix for semantic-search workflows.

	Args:
	    tokens: Token sequence used by the processing operation.
	    model: Sentence-transformer model used to encode the query or token sequence.

	Returns:
	    Tuple[ List[ str ], np.ndarray ]: Token values paired with the generated embedding matrix.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'tokens', tokens )
		throw_if( 'model', model )
		_transformer = SentenceTransformer( model )
		_tokens = [ self.lemmatizer.lemmatize( t ) for t in tokens ]
		_encoding = _transformer.encode( _tokens, show_progress_bar=True )
		return (self.cleaned_tokens, np.array( _encoding ))
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = 'encode_sentences( self, sentences: List[ str ], model_name ) -> ( )'
		raise exception
semantic_search(
    query: str,
    tokens: List[str],
    embeddings: ndarray,
    model: SentenceTransformer,
    top: int = 5,
) -> List[tuple[str, float]]

Rank embedded tokens by semantic similarity to a query.

Purpose

Encodes the query with the supplied model, compares it with the embedding matrix using cosine similarity, and returns the highest-scoring token matches. This supports lightweight semantic retrieval over prepared token embeddings.

Parameters:

Name Type Description Default
query str

Search text or semantic query submitted to the operation.

required
tokens List[str]

Token sequence used by the processing operation.

required
embeddings ndarray

Precomputed embedding matrix compared against the query vector.

required
model SentenceTransformer

Sentence-transformer model used to encode the query or token sequence.

required
top int

Maximum number of ranked semantic-search matches to return.

5

Returns:

Type Description
List[tuple[str, float]]

List[ tuple[ str, float ] ]: Ranked token and similarity-score pairs.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def semantic_search( self, query: str, tokens: List[ str ], embeddings: np.ndarray,
		model: SentenceTransformer, top: int=5 ) -> List[ tuple[ str, float ] ]:
	"""Rank embedded tokens by semantic similarity to a query.

	Purpose:
	    Encodes the query with the supplied model, compares it with the embedding matrix using cosine
	    similarity, and returns the highest-scoring token matches. This supports lightweight semantic
	    retrieval over prepared token embeddings.

	Args:
	    query: Search text or semantic query submitted to the operation.
	    tokens: Token sequence used by the processing operation.
	    embeddings: Precomputed embedding matrix compared against the query vector.
	    model: Sentence-transformer model used to encode the query or token sequence.
	    top: Maximum number of ranked semantic-search matches to return.

	Returns:
	    List[ tuple[ str, float ] ]: Ranked token and similarity-score pairs.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'query', query )
		throw_if( 'tokens', tokens )
		throw_if( 'embedding', embeddings )
		throw_if( 'model', model )
		query_vec = model.encode( [ query ] )
		sims = cosine_similarity( query_vec, embeddings )[ 0 ]
		top_indices = sims.argsort( )[ ::-1 ][ : top ]
		return [ (tokens[ i ], sims[ i ]) for i in top_indices ]
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = ('semantic_search( self, query: str, tokens: List[ str ], '
		                    'embeddings: np.ndarray, model: SentenceTransformer,  '
		                    'top_k: int=5 ) -> List[ tuple[ str, float ] ]')
		raise exception

NltkParser

Bases: Processor

Run NLTK parsing operations.

Purpose

Wraps NLTK tokenization, stemming, lemmatization, part-of-speech tagging, named-entity recognition, and token chunking routines. The class ensures required NLTK resources are available and exposes parser methods that return structured token, sentence, tag, and entity outputs.

Attributes:

Name Type Description
word_tokens Optional[List[str]]

Word tokens produced by NLTK tokenization.

sentence_tokens Optional[List[str]]

Sentence tokens produced by NLTK tokenization.

stemmed_tokens Optional[List[str]]

Tokens produced by stemming.

lemmatized_tokens Optional[List[str]]

Tokens produced by lemmatization.

tagged_tokens Optional[List[Tuple[str, str]]]

Part-of-speech tagged token tuples.

named_entities Optional[List[Tuple[str, str]]]

Named-entity text and label tuples.

Source code in processors.py
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
class NltkParser( Processor ):
	"""Run NLTK parsing operations.

	Purpose:
	    Wraps NLTK tokenization, stemming, lemmatization, part-of-speech tagging, named-entity
	    recognition, and token chunking routines. The class ensures required NLTK resources are
	    available and exposes parser methods that return structured token, sentence, tag, and entity
	    outputs.

	Attributes:
	    word_tokens: Word tokens produced by NLTK tokenization.
	    sentence_tokens: Sentence tokens produced by NLTK tokenization.
	    stemmed_tokens: Tokens produced by stemming.
	    lemmatized_tokens: Tokens produced by lemmatization.
	    tagged_tokens: Part-of-speech tagged token tuples.
	    named_entities: Named-entity text and label tuples.
	"""
	word_tokens: Optional[ List[ str ] ]
	sentence_tokens: Optional[ List[ str ] ]
	stemmed_tokens: Optional[ List[ str ] ]
	lemmatized_tokens: Optional[ List[ str ] ]
	tagged_tokens: Optional[ List[ Tuple[ str, str ] ] ]
	named_entities: Optional[ List[ Tuple[ str, str ] ] ]

	def __init__( self ) -> None:
		"""Initialize Nltk Parser.

		Purpose:
		    Initializes NltkParser state used by later processing operations. The constructor prepares
		    reusable containers, helper objects, and default runtime values without performing external
		    document processing.

		Returns:
		    None: Constructors initialize instance state and do not return a value.
		"""
		super( ).__init__( )
		self.initialize_resources( )
		self.word_tokens = [ ]
		self.sentence_tokens = [ ]
		self.stemmed_tokens = [ ]
		self.lemmatized_tokens = [ ]
		self.tagged_tokens = [ ]
		self.named_entities = [ ]

	def __dir__( self ) -> List[ str ] | None:
		"""Return the public attribute and method names exposed by the object.

		Purpose:
		    Returns a stable list of public attributes and methods for interactive inspection,
		    documentation, and UI discovery. The ordering groups state fields and callable processing
		    operations in a predictable way.

		Returns:
		    List[ str ] | None: List of processed text values when the operation succeeds.
		"""
		return [ 'initialize_resources', 'word_tokenizer', 'sentence_tokenizer', 'word_stemmer',
		         'word_lemmatizer', 'pos_tagger', 'named_entity_recognition', 'word_tokens',
		         'sentence_tokens', 'stemmed_tokens', 'lemmatized_tokens', 'tagged_tokens',
		         'named_entities' ]

	def initialize_resources( self ) -> None:
		"""Ensure the NLTK corpora, tokenizers, taggers, and chunkers required by the parser are available.

		Purpose:
		    Checks for required NLTK resources and downloads missing packages. This prepares tokenization,
		    lemmatization, tagging, and named-entity recognition routines for use by parser methods.

		Returns:
		    None: The operation completes without producing a return value.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			required_resources: List[ Tuple[ str, str ] ] = [
					('tokenizers/punkt', 'punkt'),
					('tokenizers/punkt_tab', 'punkt_tab'),
					('corpora/wordnet', 'wordnet'),
					('corpora/omw-1.4', 'omw-1.4'),
					('taggers/averaged_perceptron_tagger', 'averaged_perceptron_tagger'),
					('taggers/averaged_perceptron_tagger_eng', 'averaged_perceptron_tagger_eng'),
					('chunkers/maxent_ne_chunker', 'maxent_ne_chunker'),
					('chunkers/maxent_ne_chunker_tab', 'maxent_ne_chunker_tab'),
					('corpora/words', 'words'), ]

			for resource_path, resource_name in required_resources:
				try:
					nltk.data.find( resource_path )
				except LookupError:
					nltk.download( resource_name )
		except Exception as e:
			exception = Error( e )
			exception.module = 'processing'
			exception.cause = 'NltkParser'
			exception.method = 'NltkParser._ensure_nltk_resources( self ) -> None'
			raise exception

	def word_tokenizer( self, text: str ) -> List[ str ] | None:
		"""Tokenize text into lowercased word tokens.

		Purpose:
		    Lowercases text and tokenizes it into word tokens with NLTK. The resulting list is also stored
		    on the parser instance for reuse by later NLTK operations.

		Args:
		    text: Text value to process.

		Returns:
		    List[ str ] | None: List of processed text values when the operation succeeds.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'text', text )
			_text = text.lower( )
			self.word_tokens = word_tokenize( _text )
			words = [ token for token in self.word_tokens ]
			return words
		except Exception as e:
			exception = Error( e )
			exception.module = 'processing'
			exception.cause = 'NltkParser'
			exception.method = 'word_tokenizer( self, text: str ) -> List[ str ]'
			raise exception

	def sentence_tokenizer( self, text: str ) -> List[ str ] | None:
		"""Tokenize text into lowercased sentence strings.

		Purpose:
		    Lowercases text and tokenizes it into sentence strings with NLTK. The resulting sentences are
		    stored on the parser instance and returned to the caller.

		Args:
		    text: Text value to process.

		Returns:
		    List[ str ] | None: List of processed text values when the operation succeeds.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'text', text )
			_text = text.lower( )
			self.sentence_tokens = sent_tokenize( _text )
			return self.sentence_tokens
		except Exception as e:
			exception = Error( e )
			exception.module = 'processing'
			exception.cause = 'NltkParser'
			exception.method = 'tokenize_sentences( self, text: str ) -> str'
			raise exception

	def word_stemmer( self, text: str ) -> List[ str ] | None:
		"""Stem lowercased word tokens with the configured Porter stemmer.

		Purpose:
		    Lowercases text, tokenizes it, and applies Porter stemming to each non-empty token. This
		    produces stemmed tokens for lexical normalization workflows.

		Args:
		    text: Text value to process.

		Returns:
		    List[ str ] | None: List of processed text values when the operation succeeds.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'text', text )
			_text = text.lower( )
			self.word_tokens = word_tokenize( _text )
			self.stemmed_tokens = [ self.stemmer.stem( t ) for t in self.word_tokens
			                        if isinstance( t, str ) and t.strip( ) ]

			return self.stemmed_tokens
		except Exception as e:
			exception = Error( e )
			exception.module = 'processing'
			exception.cause = 'NltkParser'
			exception.method = 'stemmer( self, text: str ) -> str'
			raise exception

	def word_lemmatizer( self, text: str ) -> List[ str ] | None:
		"""Lemmatize lowercased word tokens with the configured WordNet lemmatizer.

		Purpose:
		    Lowercases text, tokenizes it, and applies WordNet lemmatization to each non-empty token. This
		    produces normalized lexical forms suitable for downstream analysis.

		Args:
		    text: Text value to process.

		Returns:
		    List[ str ] | None: List of processed text values when the operation succeeds.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'text', text )
			_text = text.lower( )
			self.word_tokens = word_tokenize( _text )
			self.lemmatized_tokens = [ self.lemmatizer.lemmatize( t ) for t in self.word_tokens
			                           if isinstance( t, str ) and t.strip( ) ]

			return self.lemmatized_tokens
		except Exception as e:
			exception = Error( e )
			exception.module = 'processing'
			exception.cause = 'NltkParser'
			exception.method = 'lemmatizer( self, text: str ) -> str'
			raise exception

	def pos_tagger( self, text: str ) -> List[ Tuple[ str, str ] ] | None:
		"""Assign part-of-speech tags to lowercased word tokens.

		Purpose:
		    Lowercases and tokenizes text, then assigns NLTK part-of-speech tags to each token. The tagged
		    sequence is stored on the instance and returned for syntactic analysis.

		Args:
		    text: Text value to process.

		Returns:
		    List[ Tuple[ str, str ] ] | None: List of text and label tuples when the operation succeeds.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'text', text )
			_text = text.lower( )
			self.word_tokens = word_tokenize( _text )
			self.tagged_tokens = nltk.pos_tag( self.word_tokens )
			return self.tagged_tokens
		except Exception as e:
			exception = Error( e )
			exception.module = 'processing'
			exception.cause = 'NltkParser'
			exception.method = 'pos_tagger( self, text: str ) -> str'
			raise exception

	def named_entity_recognition( self, text: str ) -> List[ Tuple[ str, str ] ] | None:
		"""Extract named-entity text and entity labels from tagged tokens.

		Purpose:
		    Lowercases text, tokenizes and tags it, then applies NLTK named-entity chunking. Entity text
		    and labels are collected into tuples for downstream review or extraction workflows.

		Args:
		    text: Text value to process.

		Returns:
		    List[ Tuple[ str, str ] ] | None: List of text and label tuples when the operation succeeds.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'text', text )
			_text = text.lower( )
			self.word_tokens = word_tokenize( _text )
			self.tagged_tokens = nltk.pos_tag( self.word_tokens )
			tree = nltk.ne_chunk( self.tagged_tokens )
			self.named_entities = [ ]
			for node in tree:
				if hasattr( node, 'label' ):
					label = node.label( )
					entity_text = ' '.join( token for token, _ in node.leaves( )
					                        if isinstance( token, str ) and token.strip( ) )

					if entity_text:
						self.named_entities.append( (entity_text, label) )

			return self.named_entities
		except Exception as e:
			exception = Error( e )
			exception.module = 'processing'
			exception.cause = 'NltkParser'
			exception.method = 'named_entity_recogniztion( self, text: str ) -> str'
			raise exception

	def chunk_words( self, text: str, size: int=5 ) -> DataFrame | None:
		"""Group word tokens into fixed-size chunks and return them as tabular data.

		Purpose:
		    Tokenizes lowercase text into words, groups the tokens into fixed-size chunks, and returns a
		    DataFrame of chunk strings. This provides a simple word-level chunking utility for downstream
		    vector or dataset generation.

		Args:
		    text: Text value to process.
		    size: Maximum number of tokens or sentences grouped into each chunk.

		Returns:
		    DataFrame | None: Pandas DataFrame containing the processed output when the operation
		    succeeds.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'text', text )
			_text = text.lower( )
			_tokens = nltk.word_tokenize( _text )
			_sentences = [ _tokens[ i: i + size ] for i in range( 0, len( _tokens ), size ) ]
			_datamap = [ ]
			for index, chunk in enumerate( _sentences ):
				_item = ' '.join( chunk )
				_datamap.append( _item )

			_data = pd.DataFrame( _datamap )
			return _data
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'TextParser'
			exception.method = 'chunk_sentences( self, text: str, max: int=10 ) -> DataFrame'
			raise exception

	def chunk_sentences( self, text: str, size: int=15 ) -> DataFrame | None:
		"""Group sentence tokens into fixed-size chunks and return them as tabular data.

		Purpose:
		    Tokenizes lowercase text into sentences, groups the sentences into fixed-size chunks, and
		    returns a DataFrame of chunk strings. This provides a sentence-level chunking utility for
		    review or dataset preparation.

		Args:
		    text: Text value to process.
		    size: Maximum number of tokens or sentences grouped into each chunk.

		Returns:
		    DataFrame | None: Pandas DataFrame containing the processed output when the operation
		    succeeds.

		Raises:
		    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
		        project error type.
		"""
		try:
			throw_if( 'text', text )
			_text = text.lower( )
			_tokens = sent_tokenize( _text )
			_sentences = [ _tokens[ i: i + size ] for i in range( 0, len( _tokens ), size ) ]
			_datamap = [ ]
			for i, c in enumerate( _sentences ):
				_item = ' '.join( c )
				_datamap.append( _item )

			_data = pd.DataFrame( _datamap )
			return _data
		except Exception as e:
			exception = Error( e )
			exception.module = 'preprocessors'
			exception.cause = 'NltkParser'
			exception.method = 'chunk_sentences( self, text: str, max: int=512 ) -> DataFrame'
			raise exception

initialize_resources

initialize_resources() -> None

Ensure the NLTK corpora, tokenizers, taggers, and chunkers required by the parser are available.

Purpose

Checks for required NLTK resources and downloads missing packages. This prepares tokenization, lemmatization, tagging, and named-entity recognition routines for use by parser methods.

Returns:

Name Type Description
None None

The operation completes without producing a return value.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def initialize_resources( self ) -> None:
	"""Ensure the NLTK corpora, tokenizers, taggers, and chunkers required by the parser are available.

	Purpose:
	    Checks for required NLTK resources and downloads missing packages. This prepares tokenization,
	    lemmatization, tagging, and named-entity recognition routines for use by parser methods.

	Returns:
	    None: The operation completes without producing a return value.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		required_resources: List[ Tuple[ str, str ] ] = [
				('tokenizers/punkt', 'punkt'),
				('tokenizers/punkt_tab', 'punkt_tab'),
				('corpora/wordnet', 'wordnet'),
				('corpora/omw-1.4', 'omw-1.4'),
				('taggers/averaged_perceptron_tagger', 'averaged_perceptron_tagger'),
				('taggers/averaged_perceptron_tagger_eng', 'averaged_perceptron_tagger_eng'),
				('chunkers/maxent_ne_chunker', 'maxent_ne_chunker'),
				('chunkers/maxent_ne_chunker_tab', 'maxent_ne_chunker_tab'),
				('corpora/words', 'words'), ]

		for resource_path, resource_name in required_resources:
			try:
				nltk.data.find( resource_path )
			except LookupError:
				nltk.download( resource_name )
	except Exception as e:
		exception = Error( e )
		exception.module = 'processing'
		exception.cause = 'NltkParser'
		exception.method = 'NltkParser._ensure_nltk_resources( self ) -> None'
		raise exception

word_tokenizer

word_tokenizer(text: str) -> List[str] | None

Tokenize text into lowercased word tokens.

Purpose

Lowercases text and tokenizes it into word tokens with NLTK. The resulting list is also stored on the parser instance for reuse by later NLTK operations.

Parameters:

Name Type Description Default
text str

Text value to process.

required

Returns:

Type Description
List[str] | None

List[ str ] | None: List of processed text values when the operation succeeds.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def word_tokenizer( self, text: str ) -> List[ str ] | None:
	"""Tokenize text into lowercased word tokens.

	Purpose:
	    Lowercases text and tokenizes it into word tokens with NLTK. The resulting list is also stored
	    on the parser instance for reuse by later NLTK operations.

	Args:
	    text: Text value to process.

	Returns:
	    List[ str ] | None: List of processed text values when the operation succeeds.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'text', text )
		_text = text.lower( )
		self.word_tokens = word_tokenize( _text )
		words = [ token for token in self.word_tokens ]
		return words
	except Exception as e:
		exception = Error( e )
		exception.module = 'processing'
		exception.cause = 'NltkParser'
		exception.method = 'word_tokenizer( self, text: str ) -> List[ str ]'
		raise exception

sentence_tokenizer

sentence_tokenizer(text: str) -> List[str] | None

Tokenize text into lowercased sentence strings.

Purpose

Lowercases text and tokenizes it into sentence strings with NLTK. The resulting sentences are stored on the parser instance and returned to the caller.

Parameters:

Name Type Description Default
text str

Text value to process.

required

Returns:

Type Description
List[str] | None

List[ str ] | None: List of processed text values when the operation succeeds.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def sentence_tokenizer( self, text: str ) -> List[ str ] | None:
	"""Tokenize text into lowercased sentence strings.

	Purpose:
	    Lowercases text and tokenizes it into sentence strings with NLTK. The resulting sentences are
	    stored on the parser instance and returned to the caller.

	Args:
	    text: Text value to process.

	Returns:
	    List[ str ] | None: List of processed text values when the operation succeeds.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'text', text )
		_text = text.lower( )
		self.sentence_tokens = sent_tokenize( _text )
		return self.sentence_tokens
	except Exception as e:
		exception = Error( e )
		exception.module = 'processing'
		exception.cause = 'NltkParser'
		exception.method = 'tokenize_sentences( self, text: str ) -> str'
		raise exception

word_stemmer

word_stemmer(text: str) -> List[str] | None

Stem lowercased word tokens with the configured Porter stemmer.

Purpose

Lowercases text, tokenizes it, and applies Porter stemming to each non-empty token. This produces stemmed tokens for lexical normalization workflows.

Parameters:

Name Type Description Default
text str

Text value to process.

required

Returns:

Type Description
List[str] | None

List[ str ] | None: List of processed text values when the operation succeeds.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def word_stemmer( self, text: str ) -> List[ str ] | None:
	"""Stem lowercased word tokens with the configured Porter stemmer.

	Purpose:
	    Lowercases text, tokenizes it, and applies Porter stemming to each non-empty token. This
	    produces stemmed tokens for lexical normalization workflows.

	Args:
	    text: Text value to process.

	Returns:
	    List[ str ] | None: List of processed text values when the operation succeeds.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'text', text )
		_text = text.lower( )
		self.word_tokens = word_tokenize( _text )
		self.stemmed_tokens = [ self.stemmer.stem( t ) for t in self.word_tokens
		                        if isinstance( t, str ) and t.strip( ) ]

		return self.stemmed_tokens
	except Exception as e:
		exception = Error( e )
		exception.module = 'processing'
		exception.cause = 'NltkParser'
		exception.method = 'stemmer( self, text: str ) -> str'
		raise exception

word_lemmatizer

word_lemmatizer(text: str) -> List[str] | None

Lemmatize lowercased word tokens with the configured WordNet lemmatizer.

Purpose

Lowercases text, tokenizes it, and applies WordNet lemmatization to each non-empty token. This produces normalized lexical forms suitable for downstream analysis.

Parameters:

Name Type Description Default
text str

Text value to process.

required

Returns:

Type Description
List[str] | None

List[ str ] | None: List of processed text values when the operation succeeds.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def word_lemmatizer( self, text: str ) -> List[ str ] | None:
	"""Lemmatize lowercased word tokens with the configured WordNet lemmatizer.

	Purpose:
	    Lowercases text, tokenizes it, and applies WordNet lemmatization to each non-empty token. This
	    produces normalized lexical forms suitable for downstream analysis.

	Args:
	    text: Text value to process.

	Returns:
	    List[ str ] | None: List of processed text values when the operation succeeds.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'text', text )
		_text = text.lower( )
		self.word_tokens = word_tokenize( _text )
		self.lemmatized_tokens = [ self.lemmatizer.lemmatize( t ) for t in self.word_tokens
		                           if isinstance( t, str ) and t.strip( ) ]

		return self.lemmatized_tokens
	except Exception as e:
		exception = Error( e )
		exception.module = 'processing'
		exception.cause = 'NltkParser'
		exception.method = 'lemmatizer( self, text: str ) -> str'
		raise exception

pos_tagger

pos_tagger(text: str) -> List[Tuple[str, str]] | None

Assign part-of-speech tags to lowercased word tokens.

Purpose

Lowercases and tokenizes text, then assigns NLTK part-of-speech tags to each token. The tagged sequence is stored on the instance and returned for syntactic analysis.

Parameters:

Name Type Description Default
text str

Text value to process.

required

Returns:

Type Description
List[Tuple[str, str]] | None

List[ Tuple[ str, str ] ] | None: List of text and label tuples when the operation succeeds.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def pos_tagger( self, text: str ) -> List[ Tuple[ str, str ] ] | None:
	"""Assign part-of-speech tags to lowercased word tokens.

	Purpose:
	    Lowercases and tokenizes text, then assigns NLTK part-of-speech tags to each token. The tagged
	    sequence is stored on the instance and returned for syntactic analysis.

	Args:
	    text: Text value to process.

	Returns:
	    List[ Tuple[ str, str ] ] | None: List of text and label tuples when the operation succeeds.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'text', text )
		_text = text.lower( )
		self.word_tokens = word_tokenize( _text )
		self.tagged_tokens = nltk.pos_tag( self.word_tokens )
		return self.tagged_tokens
	except Exception as e:
		exception = Error( e )
		exception.module = 'processing'
		exception.cause = 'NltkParser'
		exception.method = 'pos_tagger( self, text: str ) -> str'
		raise exception

named_entity_recognition

named_entity_recognition(
    text: str,
) -> List[Tuple[str, str]] | None

Extract named-entity text and entity labels from tagged tokens.

Purpose

Lowercases text, tokenizes and tags it, then applies NLTK named-entity chunking. Entity text and labels are collected into tuples for downstream review or extraction workflows.

Parameters:

Name Type Description Default
text str

Text value to process.

required

Returns:

Type Description
List[Tuple[str, str]] | None

List[ Tuple[ str, str ] ] | None: List of text and label tuples when the operation succeeds.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def named_entity_recognition( self, text: str ) -> List[ Tuple[ str, str ] ] | None:
	"""Extract named-entity text and entity labels from tagged tokens.

	Purpose:
	    Lowercases text, tokenizes and tags it, then applies NLTK named-entity chunking. Entity text
	    and labels are collected into tuples for downstream review or extraction workflows.

	Args:
	    text: Text value to process.

	Returns:
	    List[ Tuple[ str, str ] ] | None: List of text and label tuples when the operation succeeds.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'text', text )
		_text = text.lower( )
		self.word_tokens = word_tokenize( _text )
		self.tagged_tokens = nltk.pos_tag( self.word_tokens )
		tree = nltk.ne_chunk( self.tagged_tokens )
		self.named_entities = [ ]
		for node in tree:
			if hasattr( node, 'label' ):
				label = node.label( )
				entity_text = ' '.join( token for token, _ in node.leaves( )
				                        if isinstance( token, str ) and token.strip( ) )

				if entity_text:
					self.named_entities.append( (entity_text, label) )

		return self.named_entities
	except Exception as e:
		exception = Error( e )
		exception.module = 'processing'
		exception.cause = 'NltkParser'
		exception.method = 'named_entity_recogniztion( self, text: str ) -> str'
		raise exception

chunk_words

chunk_words(text: str, size: int = 5) -> DataFrame | None

Group word tokens into fixed-size chunks and return them as tabular data.

Purpose

Tokenizes lowercase text into words, groups the tokens into fixed-size chunks, and returns a DataFrame of chunk strings. This provides a simple word-level chunking utility for downstream vector or dataset generation.

Parameters:

Name Type Description Default
text str

Text value to process.

required
size int

Maximum number of tokens or sentences grouped into each chunk.

5

Returns:

Type Description
DataFrame | None

DataFrame | None: Pandas DataFrame containing the processed output when the operation

DataFrame | None

succeeds.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def chunk_words( self, text: str, size: int=5 ) -> DataFrame | None:
	"""Group word tokens into fixed-size chunks and return them as tabular data.

	Purpose:
	    Tokenizes lowercase text into words, groups the tokens into fixed-size chunks, and returns a
	    DataFrame of chunk strings. This provides a simple word-level chunking utility for downstream
	    vector or dataset generation.

	Args:
	    text: Text value to process.
	    size: Maximum number of tokens or sentences grouped into each chunk.

	Returns:
	    DataFrame | None: Pandas DataFrame containing the processed output when the operation
	    succeeds.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'text', text )
		_text = text.lower( )
		_tokens = nltk.word_tokenize( _text )
		_sentences = [ _tokens[ i: i + size ] for i in range( 0, len( _tokens ), size ) ]
		_datamap = [ ]
		for index, chunk in enumerate( _sentences ):
			_item = ' '.join( chunk )
			_datamap.append( _item )

		_data = pd.DataFrame( _datamap )
		return _data
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'TextParser'
		exception.method = 'chunk_sentences( self, text: str, max: int=10 ) -> DataFrame'
		raise exception

chunk_sentences

chunk_sentences(
    text: str, size: int = 15
) -> DataFrame | None

Group sentence tokens into fixed-size chunks and return them as tabular data.

Purpose

Tokenizes lowercase text into sentences, groups the sentences into fixed-size chunks, and returns a DataFrame of chunk strings. This provides a sentence-level chunking utility for review or dataset preparation.

Parameters:

Name Type Description Default
text str

Text value to process.

required
size int

Maximum number of tokens or sentences grouped into each chunk.

15

Returns:

Type Description
DataFrame | None

DataFrame | None: Pandas DataFrame containing the processed output when the operation

DataFrame | None

succeeds.

Raises:

Type Description
Error

If the implementation wraps a provider, parsing, filesystem, or processing failure in the project error type.

Source code in processors.py
def chunk_sentences( self, text: str, size: int=15 ) -> DataFrame | None:
	"""Group sentence tokens into fixed-size chunks and return them as tabular data.

	Purpose:
	    Tokenizes lowercase text into sentences, groups the sentences into fixed-size chunks, and
	    returns a DataFrame of chunk strings. This provides a sentence-level chunking utility for
	    review or dataset preparation.

	Args:
	    text: Text value to process.
	    size: Maximum number of tokens or sentences grouped into each chunk.

	Returns:
	    DataFrame | None: Pandas DataFrame containing the processed output when the operation
	    succeeds.

	Raises:
	    Error: If the implementation wraps a provider, parsing, filesystem, or processing failure in the
	        project error type.
	"""
	try:
		throw_if( 'text', text )
		_text = text.lower( )
		_tokens = sent_tokenize( _text )
		_sentences = [ _tokens[ i: i + size ] for i in range( 0, len( _tokens ), size ) ]
		_datamap = [ ]
		for i, c in enumerate( _sentences ):
			_item = ' '.join( c )
			_datamap.append( _item )

		_data = pd.DataFrame( _datamap )
		return _data
	except Exception as e:
		exception = Error( e )
		exception.module = 'preprocessors'
		exception.cause = 'NltkParser'
		exception.method = 'chunk_sentences( self, text: str, max: int=512 ) -> DataFrame'
		raise exception

throw_if

throw_if(name: str, value: object) -> None

Validate a required processor argument.

Purpose

Validates that a required argument is present and non-empty before text processing begins. The guard rejects None, blank strings, and empty container values with an argument-specific ValueError.

Parameters:

Name Type Description Default
name str

Argument name included in the validation error message.

required
value object

Candidate value checked for None, blank text, or an empty container.

required

Returns:

Name Type Description
None None

Validation succeeds silently; invalid values raise ValueError.

Raises:

Type Description
ValueError

If a required value is missing, blank, or outside the supported range.

Source code in processors.py
def throw_if( name: str, value: object ) -> None:
	"""Validate a required processor argument.

	Purpose:
	    Validates that a required argument is present and non-empty before text processing begins. The
	    guard rejects ``None``, blank strings, and empty container values with an argument-specific
	    ``ValueError``.

	Args:
	    name: Argument name included in the validation error message.
	    value: Candidate value checked for ``None``, blank text, or an empty container.

	Returns:
	    None: Validation succeeds silently; invalid values raise ``ValueError``.

	Raises:
	    ValueError: If a required value is missing, blank, or outside the supported range.
	"""
	if value is None:
		raise ValueError( f'Argument "{name}" cannot be empty!' )
	if isinstance( value, str ) and (not value.strip( )):
		raise ValueError( f'Argument "{name}" cannot be empty!' )
	if isinstance( value, (list, tuple, dict, set) ) and len( value ) == 0:
		raise ValueError( f'Argument "{name}" cannot be empty!' )