gaurv007 commited on
Commit
b16b7fa
·
verified ·
1 Parent(s): 11d6a4f

v4.2: Update compliance.py

Browse files
Files changed (1) hide show
  1. compliance.py +7 -4
compliance.py CHANGED
@@ -23,6 +23,9 @@ _NEGATION_PATTERNS = [
23
  r"notwithstanding.*(?:shall\s+not|does\s+not|is\s+not)",
24
  ]
25
 
 
 
 
26
  # Regulatory requirement definitions
27
  REGULATIONS = {
28
  "GDPR": {
@@ -214,13 +217,13 @@ def _check_negation(text_lower, keyword, window=200):
214
  wider_context = text_lower[start:end]
215
 
216
  # Check sentence first (higher confidence)
217
- for neg_pat in _NEGATION_PATTERNS:
218
- if re.search(neg_pat, sentence, re.IGNORECASE):
219
  return True
220
 
221
  # Then check wider window (lower confidence, still relevant)
222
- for neg_pat in _NEGATION_PATTERNS[:4]: # Only strong negation patterns for wider window
223
- if re.search(neg_pat, wider_context, re.IGNORECASE):
224
  return True
225
 
226
  return False
 
23
  r"notwithstanding.*(?:shall\s+not|does\s+not|is\s+not)",
24
  ]
25
 
26
+ # FIX v4.2: Pre-compile negation patterns at module level
27
+ _NEGATION_PATTERNS_COMPILED = [re.compile(p, re.IGNORECASE) for p in _NEGATION_PATTERNS]
28
+
29
  # Regulatory requirement definitions
30
  REGULATIONS = {
31
  "GDPR": {
 
217
  wider_context = text_lower[start:end]
218
 
219
  # Check sentence first (higher confidence)
220
+ for neg_pat in _NEGATION_PATTERNS_COMPILED:
221
+ if neg_pat.search(sentence):
222
  return True
223
 
224
  # Then check wider window (lower confidence, still relevant)
225
+ for neg_pat in _NEGATION_PATTERNS_COMPILED[:4]: # Only strong negation patterns for wider window
226
+ if neg_pat.search(wider_context):
227
  return True
228
 
229
  return False