-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
2387 lines (2078 loc) · 90.3 KB
/
app.py
File metadata and controls
2387 lines (2078 loc) · 90.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
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
import io
import json
import os
import re
import random
import tempfile
import uuid
import shutil
import concurrent.futures
import time
import sqlite3
import copy
import secrets
from pathlib import Path
from typing import Dict, List, Any, Optional, IO
from flask import Flask, jsonify, render_template, request, abort, redirect, url_for, session
from pypdf import PdfReader
from werkzeug.exceptions import HTTPException
from werkzeug.middleware.proxy_fix import ProxyFix
# --- Logging Configuration ---
import logging
import sys
# Suppress default Flask/Werkzeug access logs (e.g. "GET / ... 200")
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)
# Configure app logger to output to Console (StreamHandler)
# This ensures logs are visible in the platform dashboard and avoids filesystem issues
logging.basicConfig(
level=logging.WARNING,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.StreamHandler(sys.stdout)
]
)
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO) # Capture INFO for activity tracking (New User, Uploads, etc.)
BASE_DIR = Path(__file__).parent.resolve()
TESTS_DIR = BASE_DIR / "tests"
INSTANCE_DIR = BASE_DIR / "instance"
SESSION_DATA_DIR = INSTANCE_DIR / "sessions"
try:
TESTS_DIR.mkdir(parents=True, exist_ok=True)
except Exception:
logger.warning("Could not create TESTS_DIR. Uploads might fail if not using /tmp.")
try:
SESSION_DATA_DIR.mkdir(parents=True, exist_ok=True)
except Exception:
logger.warning("Read-only filesystem detected. Using /tmp for sessions.")
SESSION_DATA_DIR = Path(tempfile.gettempdir()) / "deca_app_sessions"
SESSION_DATA_DIR.mkdir(parents=True, exist_ok=True)
MAX_QUESTIONS_PER_RUN = int(os.getenv("MAX_QUESTIONS_PER_RUN", "100"))
MAX_TIME_LIMIT_MINUTES = int(os.getenv("MAX_TIME_LIMIT_MINUTES", "1440"))
DEFAULT_RANDOM_ORDER = os.getenv("DEFAULT_RANDOM_ORDER", "false").lower() in {"1", "true", "yes", "on"}
MAX_UPLOAD_BYTES = int(os.getenv("MAX_UPLOAD_BYTES", "12582912"))
MAX_PDF_PAGES = int(os.getenv("MAX_PDF_PAGES", "150"))
PDF_PAGE_TIMEOUT_SECONDS = int(os.getenv("PDF_PAGE_TIMEOUT_SECONDS", "8"))
TRUSTED_PROXY_HOPS = max(int(os.getenv("TRUSTED_PROXY_HOPS", "0")), 0)
SECRET_KEY = os.getenv("SECRET_KEY")
ENVIRONMENT = os.getenv("ENVIRONMENT", "").strip().lower()
IS_PRODUCTION = ENVIRONMENT == "production"
if not SECRET_KEY:
if IS_PRODUCTION:
raise RuntimeError("SECRET_KEY must be set in production.")
SECRET_KEY = secrets.token_hex(32)
logger.warning("SECRET_KEY not set. Generated ephemeral development key.")
SESSION_CLEANUP_AGE_SECONDS = 86400
# Ensure DB is in a writable location
DB_PATH = SESSION_DATA_DIR / "sessions.db"
def _init_db():
try:
with sqlite3.connect(DB_PATH) as conn:
conn.execute("CREATE TABLE IF NOT EXISTS sessions (id TEXT PRIMARY KEY, data TEXT, updated_at REAL)")
conn.execute("CREATE TABLE IF NOT EXISTS active_users (ip TEXT PRIMARY KEY, ua TEXT, last_seen REAL)")
conn.commit()
logger.info(f"Database initialized at {DB_PATH}")
except Exception as e:
logger.critical(f"FATAL: Database initialization failed: {e}")
logger.critical(f"Database path: {DB_PATH}")
logger.critical("Application cannot continue without database.")
import sys
sys.exit(1)
_init_db()
app = Flask(__name__, static_folder="static", template_folder="templates")
app.secret_key = SECRET_KEY
app.config.update(
MAX_CONTENT_LENGTH=MAX_UPLOAD_BYTES,
SESSION_TYPE="filesystem",
SESSION_COOKIE_HTTPONLY=True,
SESSION_COOKIE_SAMESITE=os.getenv("SESSION_COOKIE_SAMESITE", "Lax"),
SESSION_COOKIE_SECURE=IS_PRODUCTION,
PERMANENT_SESSION_LIFETIME=int(os.getenv("PERMANENT_SESSION_LIFETIME_SECONDS", "259200")),
)
if TRUSTED_PROXY_HOPS > 0:
app.wsgi_app = ProxyFix(app.wsgi_app, x_for=TRUSTED_PROXY_HOPS, x_proto=TRUSTED_PROXY_HOPS, x_host=TRUSTED_PROXY_HOPS)
# -----------------------------
import threading
def _background_cleanup():
"""Run cleanup periodically in background"""
import time
while True:
time.sleep(3600)
try:
_cleanup_old_sessions()
except Exception as e:
logger.error(f"Background cleanup error: {e}")
cleanup_thread = threading.Thread(target=_background_cleanup, daemon=True)
cleanup_thread.start()
# Words that commonly appear smashed onto the end of a previous word in PDF extraction.
# Used by _normalize_whitespace to surgically split run-ons without breaking valid words.
_RUNON_SPLIT_WORDS = {
'The', 'This', 'That', 'These', 'Those', 'Then', 'There', 'Their', 'They', 'Them',
'When', 'Where', 'Which', 'While', 'What', 'Who', 'Why', 'How',
'However', 'Therefore', 'Because', 'Although', 'Since', 'Before', 'After',
'For', 'From', 'With', 'About', 'Into', 'Over', 'Under', 'Between',
'And', 'But', 'Not', 'Also', 'Each', 'Every', 'Most', 'Some', 'All',
'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten',
'SOURCE', 'Rationale', 'Answer', 'Note',
'An', 'As', 'At', 'Be', 'By', 'Do', 'Go', 'He', 'If', 'In', 'Is', 'It',
'Me', 'My', 'No', 'Of', 'On', 'Or', 'So', 'To', 'Up', 'Us', 'We',
'Are', 'Can', 'Did', 'Has', 'Had', 'His', 'Her', 'Its', 'May', 'Our', 'Own',
'Any', 'New', 'Old', 'Per', 'Use', 'Was', 'Way', 'Set',
'Should', 'Would', 'Could', 'Must', 'Will', 'Shall', 'Does', 'Have',
}
# Build a regex alternation sorted longest-first so greedier words match first
_RUNON_ALTS = '|'.join(sorted(_RUNON_SPLIT_WORDS, key=len, reverse=True))
_RUNON_RE = re.compile(r'([a-z])(' + _RUNON_ALTS + r')(?=[^a-z]|$)')
def _normalize_whitespace(text: str) -> str:
if not isinstance(text, str):
return ""
# Split only at TRUE run-on word boundaries (e.g. "companyThe" -> "company The")
# instead of blindly splitting every lowercase-uppercase transition.
text = _RUNON_RE.sub(r'\1 \2', text)
# Fix specific common broken words
text = text.replace("SOURC E", "SOURCE")
text = re.sub(r"\b(SOURC)\s+(E)\b", "SOURCE", text)
return re.sub(r"\s+", " ", text).strip()
def _strip_leading_number(text: str) -> str:
return re.sub(r"^\s*(?:\d{1,3}[).:\-]|[A-E][).:\-])\s*", "", text).strip()
def _get_client_ip():
"""Get client IP while only trusting forwarding headers via ProxyFix."""
if not request: return "0.0.0.0"
return request.remote_addr or "0.0.0.0"
def _safe_log_value(value: Any) -> str:
text = str(value if value is not None else "")
return re.sub(r"[\r\n\t]+", " ", text)[:512]
def _get_csrf_token() -> str:
token = session.get("csrf_token")
if not token:
token = secrets.token_urlsafe(32)
session["csrf_token"] = token
return token
def _require_csrf():
token = request.headers.get("X-CSRF-Token", "")
expected = session.get("csrf_token")
if not expected or not token or token != expected:
abort(403, "CSRF validation failed")
origin = request.headers.get("Origin")
if origin:
trusted_origin = f"{request.scheme}://{request.host}"
if origin != trusted_origin:
abort(403, "Invalid request origin")
@app.before_request
def track_active_user():
if request.method in {"POST", "PUT", "PATCH", "DELETE"} and request.path.startswith("/api/"):
_require_csrf()
try:
# Use valid IP extraction
ip = _get_client_ip()
if ip:
ua = request.headers.get("User-Agent", "Unknown")
now = time.time()
with sqlite3.connect(DB_PATH) as conn:
# Check if new user
cursor = conn.execute("SELECT last_seen FROM active_users WHERE ip = ?", (ip,))
row = cursor.fetchone()
if not row:
logger.info(f"NEW USER ARRIVED: {_safe_log_value(ip)} | UA: {_safe_log_value(ua)}")
conn.execute("INSERT OR REPLACE INTO active_users (ip, ua, last_seen) VALUES (?, ?, ?)",
(ip, ua, now))
conn.commit()
except Exception:
pass # Don't fail request if tracking fails
@app.errorhandler(HTTPException)
def _json_http_error(exc: HTTPException):
if request.path.startswith("/api/"):
response = exc.get_response()
payload = {"error": exc.name, "description": exc.description}
response.data = json.dumps(payload)
response.content_type = "application/json"
response.status_code = exc.code or 500
return response
return exc
@app.errorhandler(Exception)
def _json_generic_error(exc: Exception):
if isinstance(exc, HTTPException):
return _json_http_error(exc)
if request.path.startswith("/api/"):
app.logger.exception("Unhandled error during API request")
return jsonify({"error": "Internal Server Error", "description": "An unexpected error occurred."}), 500
raise exc
def _looks_like_header_line(text: str) -> bool:
# Don't treat option lines as headers
if re.match(r"^\s*[A-E]\s*[).:\-]", text):
return False
patterns = [
r"(?i)\bcluster\b",
r"(?i)\bcareer\s+cluster\b",
r"(?i)\btest\s*(number|#)\b",
r"(?i)\bdeca\b",
r"(?i)\bexam\b",
r"(?i)^page\s+\d+",
r"^\d+\s*(of|/)\s*\d+$",
# Only match actual copyright notices (with © or year), not answer content
r"(?i)copyright\s*©",
r"(?i)copyright\s*\d{4}",
r"^[A-Z]{3,4}\s+-\s+[A-Z]",
]
if any(re.search(p, text) for p in patterns):
return True
# Stricter check for all-caps lines to avoid false positives on short question text
tokens = text.split()
if len(tokens) >= 3 and all(tok.isupper() or re.fullmatch(r"[A-Z0-9\-]+", tok) for tok in tokens):
# Exclude common question words even if capitalized
if "WHICH" in text.upper() or "WHAT" in text.upper():
return False
return True
return False
def _worker_process_page(source_path: str, page_num: int, temp_file_path: str = None) -> List[str]:
try:
# Re-open the file in the worker
# If temp_file is provided, use that
path_to_use = temp_file_path if temp_file_path else source_path
reader = PdfReader(path_to_use)
if page_num >= len(reader.pages):
return []
page = reader.pages[page_num]
lines = []
splitter = re.compile(r"\s{2,}(?=(?:\d{1,3}|[A-E])\s*[.:\-])")
raw_text = page.extract_text() or ""
for raw_line in raw_text.splitlines():
if splitter.search(raw_line):
parts = splitter.split(raw_line)
else:
parts = [raw_line]
for line in parts:
line = line.strip()
if not line:
continue
line = re.sub(r"\s{2,}", " ", line)
footer_regex = re.compile(r"(?:^|\s+)\b([A-Z]{3,5}\s*[-–—]\s*[A-Z])")
footer_match = footer_regex.search(line)
if footer_match:
line = line[:footer_match.start()].strip()
line = re.sub(r"\s+(and|Cluster)$", "", line).strip()
line = re.sub(r"\s+(Business Management|Hospitality|Finance|Marketing|Entrepreneurship|Administration)\s*$", "", line).strip()
if "specialist levels." in line:
line = line.replace("specialist levels.", "").strip()
# Handle copyright lines that may have answer key concatenated (e.g., "Ohio1.A")
ohio_match = re.search(r"(Center®?,?\s*Columbus,?\s*Ohio)\s*(\d{1,3}\s*[.:,-]?\s*[A-E].*)?$", line, re.IGNORECASE)
if ohio_match:
# Keep the answer part if present
answer_part = ohio_match.group(2)
line = line[:ohio_match.start()].strip()
if answer_part:
lines.append(answer_part.strip())
if "career -sustaining" in line:
line = line.split("career -sustaining")[0].strip()
if line.endswith("Business Management and"):
line = line[:-23].strip()
if "sustaining, specialist, supervi" in line:
line = line.split("sustaining, specialist, supervi")[0].strip()
# Enhanced strict footer stripping
line = re.sub(r"(?:^|\s+)Hospitality and Tourism.*$", "", line, flags=re.IGNORECASE).strip()
line = re.sub(r"(?:^|\s+)Business Management.*$", "", line, flags=re.IGNORECASE).strip()
line = re.sub(r"(?:^|\s+)\d{4}-\d{4}.*$", "", line).strip()
# Only strip actual copyright notices (with © symbol or year pattern), not answer content
line = re.sub(r"(?:^|\s+)Copyright\s*©.*$", "", line, flags=re.IGNORECASE).strip()
line = re.sub(r"(?:^|\s+)Copyright\s*\d{4}.*$", "", line, flags=re.IGNORECASE).strip()
line = re.sub(r"(?:^|\s+)CAUTION: Posting these materials.*$", "", line, flags=re.IGNORECASE).strip()
line = re.sub(r"(?:^|\s+)Test questions were developed by.*$", "", line, flags=re.IGNORECASE).strip()
line = re.sub(r"(?:^|\s+)Performance indicators for these.*$", "", line, flags=re.IGNORECASE).strip()
line = re.sub(r"(?:^|\s+)are at the prerequisite.*$", "", line, flags=re.IGNORECASE).strip()
line = re.sub(r"(?:^|\s+)Competitive Events.*$", "", line, flags=re.IGNORECASE).strip()
line = re.sub(r"(?:^|\s+)Test-Item Bank.*$", "", line, flags=re.IGNORECASE).strip()
# Check for header/footer but be careful not to trigger on question text
if _looks_like_header_line(line):
cleaned = re.sub(r"(?i)^.*?copyright.*?ohio\s*", "", line)
if cleaned and cleaned != line:
line = cleaned
if _looks_like_header_line(line):
continue
else:
continue
lines.append(line)
return lines
except Exception as e:
# Use print in worker as logging config might not be propagated
# or rely on stderr
print(f"Worker Parsing Error on page {page_num}: {e}", file=sys.stderr)
return []
def _extract_clean_lines(source: Path | IO[bytes]) -> List[str]:
# Handle ByteIO by dumping to temp file
temp_path = None
is_bytes = isinstance(source, (io.BytesIO, bytes)) or (hasattr(source, 'read') and not isinstance(source, (str, Path)))
try:
if is_bytes:
# Create a named temp file that persists so workers can read it
# Close it so workers can open it
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp:
if hasattr(source, 'read'):
source.seek(0)
shutil.copyfileobj(source, tmp)
else:
tmp.write(source)
temp_path = tmp.name
# Open reader just to get page count
reader = PdfReader(temp_path)
source_path_arg = None # Don't pass source_path if using temp
path_for_worker = temp_path
else:
source = Path(source)
reader = PdfReader(source)
source_path_arg = str(source)
path_for_worker = None # Worker uses source_path_arg
num_pages = len(reader.pages)
if num_pages > MAX_PDF_PAGES:
raise ValueError(f"PDF has {num_pages} pages; maximum allowed is {MAX_PDF_PAGES}.")
lines = []
# Determine strict header threshold first?
# No, we need lines first.
# But we need page count for threshold, which we have.
# Parallel Execution
# 4 workers is usually sweet spot for PDF extraction
max_workers = min(8, num_pages) if num_pages > 0 else 1
with concurrent.futures.ProcessPoolExecutor(max_workers=max_workers) as executor:
# Map page numbers to workers
# Pass source_path_arg as first arg (if real file), or None
# Pass temp_path as third arg
futures = []
for i in range(num_pages):
# Args: (source_path, page_num, temp_file_path)
futures.append(executor.submit(_worker_process_page, source_path_arg, i, path_for_worker))
for future in futures:
try:
page_lines = future.result(timeout=PDF_PAGE_TIMEOUT_SECONDS)
lines.extend(page_lines)
except Exception as e:
logger.error(f"Page processing error: {e}")
finally:
if temp_path and os.path.exists(temp_path):
try:
os.unlink(temp_path)
except:
pass
# Remove duplicates that appear on almost every page (headers/footers)
# (Original logic follows)
counts = {}
for l in lines:
counts[l] = counts.get(l, 0) + 1
# Calculate a dynamic threshold based on page count
# If a line appears on > 40% of pages, it's likely a header
# page_count variable needs to be reused.
page_count = num_pages
threshold = max(2, int(page_count * 0.4))
final_lines = []
for l in lines:
# If line is very common, skip it
if counts[l] > threshold:
continue
# If line looks like a header (and we missed it earlier), skip it
if _looks_like_header_line(l):
continue
final_lines.append(l)
return final_lines
COMMON_FIXES_RAW = [
# === CRITICAL: Single letter + common word = fix ===
# These patterns fix cases like "h as" -> "has" where the first letter got separated
(r'\bh\s+as\b', 'has'),
(r'\bw\s+as\b', 'was'),
(r'\bh\s+is\b', 'his'),
(r'\bh\s+er\b', 'her'),
(r'\bh\s+im\b', 'him'),
(r'\bh\s+ad\b', 'had'),
(r'\bh\s+ave\b', 'have'),
(r'\bh\s+ow\b', 'how'),
(r'\bw\s+ho\b', 'who'),
(r'\bw\s+hy\b', 'why'),
(r'\bw\s+ay\b', 'way'),
(r'\bw\s+ill\b', 'will'),
(r'\bw\s+ere\b', 'were'),
(r'\bw\s+ould\b', 'would'),
(r'\bw\s+ant\b', 'want'),
(r'\bw\s+hen\b', 'when'),
(r'\bw\s+hat\b', 'what'),
(r'\bw\s+here\b', 'where'),
(r'\bt\s+he\b', 'the'),
(r'\bt\s+his\b', 'this'),
(r'\bt\s+hat\b', 'that'),
(r'\bt\s+hen\b', 'then'),
(r'\bt\s+hey\b', 'they'),
(r'\bt\s+hem\b', 'them'),
(r'\bt\s+here\b', 'there'),
(r'\bt\s+hose\b', 'those'),
(r'\bt\s+heir\b', 'their'),
# === ADDITIONAL PATTERN FIXES (from analysis) ===
(r'\brece\s+ives?\b', 'receives'),
(r'\bbenef\s+its?\b', 'benefits'),
(r'\bbenef\s+it\b', 'benefit'),
(r'\bcom\s+pany\b', 'company'),
(r'\bpro\s+duct\b', 'product'),
(r'\bser\s+vice\b', 'service'),
(r'\bcus\s+tomer\b', 'customer'),
(r'\bman\s+age\b', 'manage'),
(r'\bpro\s+vide\b', 'provide'),
# === CAPITAL LETTER SPLITS (most common from analysis) ===
# Words ending in -it that get split with capital I
(r'\bbenef\s*[Ii]t\b', 'benefit'),
(r'\bbenef\s*[Ii]ts\b', 'benefits'),
(r'\bcred\s*[Ii]t\b', 'credit'),
(r'\bcred\s*[Ii]ts\b', 'credits'),
(r'\btrans\s*[Ii]t\b', 'transit'),
(r'\bsubm\s*[Ii]t\b', 'submit'),
(r'\bsubm\s*[Ii]ts\b', 'submits'),
(r'\bprof\s*[Ii]t\b', 'profit'),
(r'\bprof\s*[Ii]ts\b', 'profits'),
(r'\blim\s*[Ii]t\b', 'limit'),
(r'\blim\s*[Ii]ts\b', 'limits'),
(r'\baud\s*[Ii]t\b', 'audit'),
(r'\baud\s*[Ii]ts\b', 'audits'),
(r'\bdepos\s*[Ii]t\b', 'deposit'),
(r'\bdepos\s*[Ii]ts\b', 'deposits'),
(r'\bexh\s*[Ii]b\s*[Ii]t\b', 'exhibit'),
(r'\bperm\s*[Ii]t\b', 'permit'),
(r'\bperm\s*[Ii]ts\b', 'permits'),
(r'\bun\s*[Ii]t\b', 'unit'),
(r'\bun\s*[Ii]ts\b', 'units'),
(r'\bexpl\s*[Ii]c\s*[Ii]t\b', 'explicit'),
# Words ending in -as that get split with capital A
(r'\bpurch\s*[Aa]s\b', 'purchase'),
(r'\bpurch\s*[Aa]ses\b', 'purchases'),
(r'\bextr\s*[Aa]s\b', 'extras'),
(r'\bextr\s*[Aa]\b', 'extra'),
(r'\bide\s*[Aa]s\b', 'ideas'),
(r'\bare\s*[Aa]s\b', 'areas'),
(r'\brele\s*[Aa]s\b', 'release'),
(r'\brele\s*[Aa]ses\b', 'releases'),
# Other common capital letter splits
(r'\b[Rr]etrieved\s+[Aa]ugust\b', 'Retrieved August'),
(r'\betrieved\s+[Aa]ugust\b', 'Retrieved August'),
(r'\bengage\s+[Ll]earning\b', 'Engage Learning'),
(r'\bonsumer\s+[Pp]roduct\b', 'Consumer Product'),
(r'\bwith\s*[Ii]n\b', 'within'),
(r'\bwith\s*[Oo]ut\b', 'without'),
# -ity splits with capital letters
(r'\bquant\s*[Ii]ty\b', 'quantity'),
(r'\bqual\s*[Ii]ty\b', 'quality'),
(r'\babil\s*[Ii]ty\b', 'ability'),
(r'\bliabil\s*[Ii]ty\b', 'liability'),
(r'\bpersonal\s*[Ii]ty\b', 'personality'),
(r'\bcapabil\s*[Ii]ty\b', 'capability'),
(r'\bactiv\s*[Ii]ty\b', 'activity'),
(r'\bactiv\s*[Ii]ties\b', 'activities'),
(r'\bopportun\s*[Ii]ty\b', 'opportunity'),
(r'\butil\s*[Ii]ty\b', 'utility'),
# -er/-or splits
(r'\bcustom\s*[Ee]r\b', 'customer'),
(r'\bcustom\s*[Ee]rs\b', 'customers'),
(r'\bmanag\s*[Ee]r\b', 'manager'),
(r'\bmanag\s*[Ee]rs\b', 'managers'),
(r'\bemploy\s*[Ee]r\b', 'employer'),
(r'\bemploy\s*[Ee]rs\b', 'employers'),
(r'\binvest\s*[Oo]r\b', 'investor'),
(r'\binvest\s*[Oo]rs\b', 'investors'),
# === CRITICAL EDGE CASES: Short word splits ===
# These happen when common words get split at unusual points
(r'\ba\s+nd\b', 'and'),
(r'\ba\s+ndthe\b', 'and the'),
(r'\ba\s+s\b', 'as'), # Only when followed by space
(r'\bo\s+f\b', 'of'),
(r'\bo\s+n\b', 'on'),
(r'\bo\s+r\b', 'or'),
(r'\bi\s+n\b', 'in'),
(r'\bi\s+s\b', 'is'),
(r'\bi\s+t\b', 'it'),
(r'\bt\s+o\b', 'to'),
(r'\bt\s+he\b', 'the'),
(r'\bw\s+e\b', 'we'),
(r'\bb\s+e\b', 'be'),
(r'\bb\s+y\b', 'by'),
(r'\ba\s+t\b', 'at'),
(r'\bu\s+p\b', 'up'),
(r'\bn\s+o\b', 'no'),
(r'\bs\s+o\b', 'so'),
(r'\bm\s+y\b', 'my'),
(r'\bh\s+e\b', 'he'),
(r'\bf\s+or\b', 'for'),
(r'\bf\s+rom\b', 'from'),
(r'\bw\s+ith\b', 'with'),
(r'\bth\s+at\b', 'that'),
(r'\bth\s+is\b', 'this'),
(r'\bth\s+ey\b', 'they'),
(r'\bth\s+em\b', 'them'),
(r'\bth\s+en\b', 'then'),
(r'\bwh\s+en\b', 'when'),
(r'\bwh\s+at\b', 'what'),
(r'\bwh\s+o\b', 'who'),
(r'\bwh\s+ich\b', 'which'),
(r'\bha\s+ve\b', 'have'),
(r'\bha\s+s\b', 'has'),
(r'\bha\s+d\b', 'had'),
(r'\bca\s+n\b', 'can'),
(r'\bwi\s+ll\b', 'will'),
(r'\bwo\s+uld\b', 'would'),
(r'\bwi\s+th\b', 'with'),
(r'\bev\s+al\s*uating\b', 'evaluating'),
(r'\beval\s+uating\b', 'evaluating'),
(r'\bsitu\s+ation\b', 'situation'),
# === BUSINESS/FINANCE CORE TERMS ===
(r'\bbusi?\s*ness\b', 'business'),
(r'\bbus\s+iness\b', 'business'),
(r'\bfi\s*nance\b', 'finance'),
(r'\bfi\s*nan\s*cial\b', 'financial'),
(r'\bin\s*for\s*ma\s*tion\b', 'information'),
(r'\binfor\s*mation\b', 'information'),
(r'\bman\s*age\s*ment\b', 'management'),
(r'\bmanage\s*ment\b', 'management'),
(r'\bcus\s*tom\s*er\b', 'customer'),
(r'\bcustom\s*er\b', 'customer'),
(r'\bcom\s*pa\s*ny\b', 'company'),
(r'\bcompan\s*y\b', 'company'),
(r'\bpro\s*duct\b', 'product'),
(r'\bproduc\s*t\b', 'product'),
(r'\bser\s*vice\b', 'service'),
(r'\bservic\s*e\b', 'service'),
(r'\bmar\s*ket\s*ing\b', 'marketing'),
(r'\bmarket\s*ing\b', 'marketing'),
(r'\bem\s*ploy\s*ee\b', 'employee'),
(r'\bemploy\s*ee\b', 'employee'),
(r'\bor\s*gan\s*iza\s*tion\b', 'organization'),
(r'\borgan\s*ization\b', 'organization'),
(r'\borganiza\s*tion\b', 'organization'),
(r'\bcom\s*mu\s*ni\s*ca\s*tion\b', 'communication'),
(r'\bcommunica\s*tion\b', 'communication'),
(r'\bde\s*ci\s*sion\b', 'decision'),
(r'\bdeci\s*sion\b', 'decision'),
(r'\bop\s*er\s*a\s*tion\b', 'operation'),
(r'\bopera\s*tion\b', 'operation'),
# === COMMON VERBS ===
(r'\bSOURC\s*E\b', 'SOURCE'),
(r'\bsourc\s*e\b', 'source'),
(r'\bre\s*triev\s*ed\b', 'retrieved'),
(r'\bRetriev\s*ed\b', 'Retrieved'),
(r'\bdeter\s*mine\b', 'determine'),
(r'\bunder\s*stand\b', 'understand'),
(r'\bunder\s*standing\b', 'understanding'),
(r'\bpro\s*vide\b', 'provide'),
(r'\bprovid\s*ing\b', 'providing'),
(r'\bim\s*prove\b', 'improve'),
(r'\bimprov\s*ing\b', 'improving'),
(r'\bcon\s*sider\b', 'consider'),
(r'\bcon\s*tact\b', 'contact'),
(r'\bcon\s*trol\b', 'control'),
(r'\bcon\s*tract\b', 'contract'),
(r'\bcon\s*sumer\b', 'consumer'),
(r'\bcon\s*tinue\b', 'continue'),
(r'\bex\s*ample\b', 'example'),
(r'\bex\s*plain\b', 'explain'),
(r'\bex\s*pect\b', 'expect'),
(r'\bex\s*perience\b', 'experience'),
(r'\bre\s*quire\b', 'require'),
(r'\bre\s*sponse\b', 'response'),
(r'\bre\s*sult\b', 'result'),
(r'\bre\s*port\b', 'report'),
(r'\bre\s*ceive\b', 'receive'),
(r'\bre\s*view\b', 'review'),
(r'\bre\s*search\b', 'research'),
(r'\bper\s*form\b', 'perform'),
(r'\bper\s*son\b', 'person'),
(r'\bper\s*sonal\b', 'personal'),
# === COMMON NOUNS ===
(r'\bprofes\s*sional\b', 'professional'),
(r'\brel\s*ation\s*ship\b', 'relationship'),
(r'\brelation\s*ship\b', 'relationship'),
(r'\bdevel\s*op\s*ment\b', 'development'),
(r'\bdevelop\s*ment\b', 'development'),
(r'\benviron\s*ment\b', 'environment'),
(r'\btech\s*nol\s*ogy\b', 'technology'),
(r'\btechnol\s*ogy\b', 'technology'),
(r'\badver\s*tis\s*ing\b', 'advertising'),
(r'\badvertis\s*ing\b', 'advertising'),
(r'\bexplan\s*ation\b', 'explanation'),
(r'\binstru\s*ment\b', 'instrument'),
(r'\bques\s*tion\b', 'question'),
(r'\bregu\s*la\s*tion\b', 'regulation'),
(r'\bregula\s*tion\b', 'regulation'),
(r'\bdocu\s*ment\b', 'document'),
(r'\bstate\s*ment\b', 'statement'),
(r'\binvest\s*ment\b', 'investment'),
(r'\bequip\s*ment\b', 'equipment'),
(r'\brequire\s*ment\b', 'requirement'),
(r'\bachieve\s*ment\b', 'achievement'),
(r'\badvan\s*tage\b', 'advantage'),
(r'\bknowl\s*edge\b', 'knowledge'),
(r'\bstra\s*tegy\b', 'strategy'),
(r'\bstrateg\s*y\b', 'strategy'),
(r'\bactiv\s*ity\b', 'activity'),
(r'\bopportun\s*ity\b', 'opportunity'),
(r'\brespons\s*ibility\b', 'responsibility'),
(r'\bresponsi\s*bility\b', 'responsibility'),
(r'\babil\s*ity\b', 'ability'),
(r'\bqual\s*ity\b', 'quality'),
(r'\bquant\s*ity\b', 'quantity'),
(r'\butil\s*ity\b', 'utility'),
(r'\bsecur\s*ity\b', 'security'),
(r'\bauthor\s*ity\b', 'authority'),
(r'\bprior\s*ity\b', 'priority'),
(r'\bcomplex\s*ity\b', 'complexity'),
# === MORE BUSINESS TERMS ===
(r'\bemploy\s*er\b', 'employer'),
(r'\bemploy\s*ment\b', 'employment'),
(r'\bsales\s*person\b', 'salesperson'),
(r'\bread\s*ing\b', 'reading'),
(r'\bwrit\s*ing\b', 'writing'),
(r'\bspeak\s*ing\b', 'speaking'),
(r'\blisten\s*ing\b', 'listening'),
(r'\blearn\s*ing\b', 'learning'),
(r'\btrain\s*ing\b', 'training'),
(r'\bplan\s*ning\b', 'planning'),
(r'\bbudget\s*ing\b', 'budgeting'),
(r'\baccount\s*ing\b', 'accounting'),
(r'\bbank\s*ing\b', 'banking'),
(r'\bpric\s*ing\b', 'pricing'),
(r'\bbrand\s*ing\b', 'branding'),
(r'\bsell\s*ing\b', 'selling'),
(r'\bbuy\s*ing\b', 'buying'),
(r'\bship\s*ping\b', 'shipping'),
(r'\bpack\s*aging\b', 'packaging'),
(r'\bpromot\s*ion\b', 'promotion'),
(r'\bpromo\s*tion\b', 'promotion'),
(r'\bdistri\s*bution\b', 'distribution'),
(r'\bproduct\s*ion\b', 'production'),
(r'\bcompet\s*ition\b', 'competition'),
(r'\bcompeti\s*tion\b', 'competition'),
(r'\bposi\s*tion\b', 'position'),
(r'\bcondi\s*tion\b', 'condition'),
(r'\btransi\s*tion\b', 'transition'),
(r'\bsolu\s*tion\b', 'solution'),
(r'\beval\s*uation\b', 'evaluation'),
(r'\bsitu\s*ation\b', 'situation'),
(r'\bpresen\s*tation\b', 'presentation'),
(r'\bappli\s*cation\b', 'application'),
(r'\binforma\s*tion\b', 'information'),
(r'\bimportant\b', 'important'),
(r'\bimport\s*ant\b', 'important'),
(r'\bdifferent\b', 'different'),
(r'\bdiffer\s*ent\b', 'different'),
(r'\beffect\s*ive\b', 'effective'),
(r'\bproduct\s*ive\b', 'productive'),
(r'\bposit\s*ive\b', 'positive'),
(r'\bnegat\s*ive\b', 'negative'),
(r'\bcreate\s*ive\b', 'creative'),
(r'\bcompet\s*itive\b', 'competitive'),
# === ADDITIONAL COMMON WORDS ===
(r'\bfollow\s*ing\b', 'following'),
(r'\binclu\s*ding\b', 'including'),
(r'\bbecome\s*ing\b', 'becoming'),
(r'\bbehav\s*ior\b', 'behavior'),
(r'\binter\s*est\b', 'interest'),
(r'\binter\s*net\b', 'internet'),
(r'\binter\s*view\b', 'interview'),
(r'\binter\s*nal\b', 'internal'),
(r'\binter\s*action\b', 'interaction'),
(r'\bextern\s*al\b', 'external'),
(r'\borigin\s*al\b', 'original'),
(r'\bperson\s*al\b', 'personal'),
(r'\bproces\s*s\b', 'process'),
(r'\bprogr\s*am\b', 'program'),
(r'\bprob\s*lem\b', 'problem'),
(r'\bpur\s*pose\b', 'purpose'),
(r'\bpur\s*chase\b', 'purchase'),
(r'\bstand\s*ard\b', 'standard'),
(r'\bpart\s*ner\b', 'partner'),
(r'\bpart\s*nership\b', 'partnership'),
(r'\bleader\s*ship\b', 'leadership'),
(r'\bmember\s*ship\b', 'membership'),
(r'\bowner\s*ship\b', 'ownership'),
(r'\bspons\s*orship\b', 'sponsorship'),
(r'\bintern\s*ship\b', 'internship'),
(r'\bscholar\s*ship\b', 'scholarship'),
(r'\bcitizen\s*ship\b', 'citizenship'),
(r'\bfriend\s*ship\b', 'friendship'),
(r'\bwork\s*place\b', 'workplace'),
(r'\bmarket\s*place\b', 'marketplace'),
# === FIX COMMON SHORT SPLITS ===
(r'\bwi\s*th\b', 'with'),
(r'\bwit\s*h\b', 'with'),
(r'\bth\s*at\b', 'that'),
(r'\btha\s*t\b', 'that'),
(r'\bth\s*is\b', 'this'),
(r'\bthi\s*s\b', 'this'),
(r'\bth\s*ey\b', 'they'),
(r'\bthe\s*y\b', 'they'),
(r'\bth\s*em\b', 'them'),
(r'\bthe\s*m\b', 'them'),
(r'\bth\s*eir\b', 'their'),
(r'\bthei\s*r\b', 'their'),
(r'\bth\s*ere\b', 'there'),
(r'\bther\s*e\b', 'there'),
(r'\bth\s*ese\b', 'these'),
(r'\bthes\s*e\b', 'these'),
(r'\bwh\s*ich\b', 'which'),
(r'\bwhic\s*h\b', 'which'),
(r'\bwh\s*en\b', 'when'),
(r'\bwhe\s*n\b', 'when'),
(r'\bwh\s*ere\b', 'where'),
(r'\bwher\s*e\b', 'where'),
(r'\bwh\s*at\b', 'what'),
(r'\bwha\s*t\b', 'what'),
(r'\bab\s*out\b', 'about'),
(r'\babou\s*t\b', 'about'),
(r'\bfr\s*om\b', 'from'),
(r'\bfro\s*m\b', 'from'),
(r'\bhave\b', 'have'),
(r'\bha\s*ve\b', 'have'),
(r'\bsh\s*ould\b', 'should'),
(r'\bshou\s*ld\b', 'should'),
(r'\bwo\s*uld\b', 'would'),
(r'\bwoul\s*d\b', 'would'),
(r'\bco\s*uld\b', 'could'),
(r'\bcoul\s*d\b', 'could'),
(r'\bbe\s*cause\b', 'because'),
(r'\bbecau\s*se\b', 'because'),
(r'\bbefor\s*e\b', 'before'),
(r'\baft\s*er\b', 'after'),
(r'\bafte\s*r\b', 'after'),
(r'\both\s*er\b', 'other'),
(r'\bothe\s*r\b', 'other'),
(r'\beff\s*ect\b', 'effect'),
(r'\beffec\s*t\b', 'effect'),
]
ADDITIONAL_FIXES_RAW = [
# === FIX: Common word splits that the general merge logic misses ===
(r'\ban\s+d\b', 'and'), # "an d" → "and" (common split missed by prefix merge)
(r'\bExclu\s*sive\b', 'Exclusive'),
(r'\bexclu\s*sive\b', 'exclusive'),
(r'\binclu\s*sive\b', 'inclusive'),
(r'\binc\s*ome\b', 'income'),
(r'\boutc\s*ome\b', 'outcome'),
(r'\bresou\s*rces\b', 'resources'),
(r'\bresou\s*rce\b', 'resource'),
(r'\bth\s*rough\b', 'through'),
(r'\bth\s*an\b', 'than'),
(r'\bYo\s*ucan\b', 'You can'),
(r'\bus\s*er\b', 'user'),
(r'\bunabl\s*e\b', 'unable'),
(r'\brobo\s*ts\b', 'robots'),
(r'\brisk\s*s\b', 'risks'),
(r'\bAlthoug\s*h\b', 'Although'),
(r'\bThoug\s*h\b', 'Though'),
(r'\bThroug\s*h\b', 'Through'),
(r'\bEnoug\s*h\b', 'Enough'),
(r'\balthoug\s*h\b', 'although'),
(r'\bthoug\s*h\b', 'though'),
(r'\bthroug\s*h\b', 'through'),
(r'\benoug\s*h\b', 'enough'),
(r'\bpar\s*t\b', 'part'),
(r'\bpar\s*ts\b', 'parts'),
(r'\bcos\s*t\b', 'cost'),
(r'\bcos\s*ts\b', 'costs'),
(r'\bno\s*t\b', 'not'),
(r'\bmus\s*t\b', 'must'),
(r'\bbes\s*t\b', 'best'),
(r'\btes\s*t\b', 'test'),
(r'\blis\s*t\b', 'list'),
(r'\bjus\s*t\b', 'just'),
(r'\blas\s*t\b', 'last'),
(r'\bfirs\s*t\b', 'first'),
(r'\bmos\s*t\b', 'most'),
(r'\bpos\s*t\b', 'post'),
(r'\brus\s*t\b', 'rust'),
(r'\btrus\s*t\b', 'trust'),
(r'\binteres\s*t\b', 'interest'),
(r'\bconsis\s*t\b', 'consist'),
(r'\bexis\s*t\b', 'exist'),
(r'\bproduc\s*t\b', 'product'),
(r'\bimpac\s*t\b', 'impact'),
(r'\bcontac\s*t\b', 'contact'),
(r'\bexac\s*t\b', 'exact'),
(r'\bdirec\s*t\b', 'direct'),
(r'\bshor\s*t\b', 'short'),
(r'\brepor\s*t\b', 'report'),
(r'\bmar\s*ket\b', 'market'),
(r'\bbene\s*fit\b', 'benefit'),
(r'\bben\s*efit\b', 'benefit'),
(r'\bprofes\s*sion\b', 'profession'),
(r'\bimpor\s*t\b', 'import'),
(r'\bexpor\s*t\b', 'export'),
(r'\bcomfor\s*t\b', 'comfort'),
(r'\bsuppor\s*t\b', 'support'),
(r'\btranspor\s*t\b', 'transport'),
(r'\beffec\s*t\b', 'effect'),
(r'\bselec\s*t\b', 'select'),
(r'\bprojec\s*t\b', 'project'),
(r'\bsubjec\s*t\b', 'subject'),
(r'\bobjec\s*t\b', 'object'),
(r'\bprotec\s*t\b', 'protect'),
(r'\bdetec\s*t\b', 'detect'),
(r'\bexpec\s*t\b', 'expect'),
(r'\brespec\s*t\b', 'respect'),
(r'\binsec\s*t\b', 'insect'),
(r'\binfec\s*t\b', 'infect'),
(r'\bcollec\s*t\b', 'collect'),
(r'\bconnec\s*t\b', 'connect'),
(r'\bproduc\s*ts\b', 'products'),
(r'\bcontrac\s*t\b', 'contract'),
(r'\bcontrac\s*ts\b', 'contracts'),
(r'\bus\s*e\b', 'use'),
(r'\bthos\s*e\b', 'those'),
(r'\bthes\s*e\b', 'these'),
(r'\bclos\s*e\b', 'close'),
(r'\bpurpos\s*e\b', 'purpose'),
(r'\bpurchas\s*e\b', 'purchase'),
(r'\bincreas\s*e\b', 'increase'),
(r'\bdecreas\s*e\b', 'decrease'),
(r'\breleas\s*e\b', 'release'),
(r'\bchoos\s*e\b', 'choose'),
(r'\brespons\s*e\b', 'response'),
(r'\bexpens\s*e\b', 'expense'),
(r'\bdefens\s*e\b', 'defense'),
(r'\blicens\s*e\b', 'license'),
(r'\bpromis\s*e\b', 'promise'),
(r'\bexercis\s*e\b', 'exercise'),
(r'\bpractic\s*e\b', 'practice'),
(r'\bservic\s*e\b', 'service'),
# Words found in spacing analysis that were still broken
(r'\bciv\s*il\b', 'civil'),
(r'\bmaj\s*ority\b', 'majority'),
(r'\bret\s*ailers\b', 'retailers'),
(r'\brath\s*er\b', 'rather'),
(r'\bcons\s*umers\b', 'consumers'),
(r'\bcontroll\s*ing\b', 'controlling'),
(r'\bslott\s*ing\b', 'slotting'),
(r'\bsimplifyi\s*ng\b', 'simplifying'),
(r'\beffecti\s*vely\b', 'effectively'),
(r'\blisteni\s*ng\b', 'listening'),
(r'\bmaki\s*ng\b', 'making'),
(r'\btaki\s*ng\b', 'taking'),
(r'\bhavi\s*ng\b', 'having'),
(r'\bgivi\s*ng\b', 'giving'),
(r'\busi\s*ng\b', 'using'),
(r'\bmeani\s*ng\b', 'meaning'),
(r'\bbec\s*ause\b', 'because'),
(r'\bmes\s*sage\b', 'message'),
(r'\baff\s*ect\b', 'affect'),
(r'\bspe\s*cific\b', 'specific'),
(r'\bdiffi\s*cult\b', 'difficult'),
(r'\bsemi\s*nar\b', 'seminar'),
(r'\binformati\s*on\b', 'information'),
(r'\brel\s*y\b', 'rely'),
(r'\bYo\s*ucan\b', 'You can'),
(r'\bwit\s*htheir\b', 'with their'),
(r'\bwit\s*hout\b', 'without'),
(r'\bwhi\s*ch\b', 'which'),
(r'\bmone\s*y\b', 'money'),
(r'\bsho\s*uld\b', 'should'),
(r'\bcou\s*ld\b', 'could'),
(r'\bwou\s*ld\b', 'would'),
(r'\ba\s+re\s+based\b', 'are based'),
(r'\bsteppings\s*tones\b', 'steppingstones'),
(r'\btriggerne\s*w\b', 'trigger new'),
(r'\bveryoutlandish\b', 'very outlandish'),
(r'\blisteni\s*ngand\b', 'listening and'),
(r'\bwhi\s*chmay\b', 'which may'),
(r'\bsimplifyi\s*ngexisting\b', 'simplifying existing'),
(r'\brath\s*erthan\b', 'rather than'),
(r'\bciv\s*illitigation\b', 'civil litigation'),
# More -ing splits
(r'\bkee\s*ping\b', 'keeping'),
(r'\bsel\s*ling\b', 'selling'),
(r'\btel\s*ling\b', 'telling'),
(r'\bgett\s*ing\b', 'getting'),
(r'\bsett\s*ing\b', 'setting'),
(r'\blett\s*ing\b', 'letting'),
(r'\bputt\s*ing\b', 'putting'),
(r'\bcutt\s*ing\b', 'cutting'),
(r'\bhitt\s*ing\b', 'hitting'),
(r'\bsitt\s*ing\b', 'sitting'),
# More common splits
(r'\binfor\s*mation\b', 'information'),
(r'\beffici\s*ent\b', 'efficient'),
(r'\beffici\s*ency\b', 'efficiency'),
(r'\bsuffi\s*cient\b', 'sufficient'),
(r'\bdefici\s*ent\b', 'deficient'),
# === NEW: -ity word splits (from analysis) ===
(r'\bprofitabilit\s*y\b', 'profitability'),
(r'\babilit\s*y\b', 'ability'),
(r'\bqualit\s*y\b', 'quality'),
(r'\bliabilit\s*y\b', 'liability'),
(r'\bfacilit\s*y\b', 'facility'),
(r'\bflexibilit\s*y\b', 'flexibility'),
(r'\bresponsibilit\s*y\b', 'responsibility'),
(r'\bquantit\s*y\b', 'quantity'),
(r'\bactivit\s*y\b', 'activity'),
(r'\brealit\s*y\b', 'reality'),
(r'\bvariet\s*y\b', 'variety'),