SsebaA commited on
Commit
20bf715
·
verified ·
1 Parent(s): 7f107f0

Update gdpr_filter.py

Browse files
Files changed (1) hide show
  1. gdpr_filter.py +13 -7
gdpr_filter.py CHANGED
@@ -1,7 +1,5 @@
1
-
2
  import re
3
  import logging
4
- from config import Config
5
 
6
  logger = logging.getLogger(__name__)
7
 
@@ -31,6 +29,13 @@ class GDPRFilter:
31
  r'(ol|in|stat|pril|zol|am|um|ase|mycin|axin|cillin)$',
32
  ]
33
 
 
 
 
 
 
 
 
34
  @staticmethod
35
  def has_medication_context(text: str) -> bool:
36
  for pattern in GDPRFilter.MEDICATION_CONTEXT_KEYWORDS:
@@ -70,13 +75,14 @@ class GDPRFilter:
70
  text = re.sub(r'(\[PERSONNR\])\s+\d{1,4}\b', r'\1', text)
71
 
72
  has_med_context = GDPRFilter.has_medication_context(text)
73
- exclusions = Config.GDPR_EXCLUSION_LIST
74
 
75
  def replace_name(match):
76
  word = match.group(0)
77
- if any(word.startswith(ex) for ex in exclusions):
78
- return word
79
- if GDPRFilter.is_likely_medication(word) and has_med_context:
 
 
80
  return word
81
  return '[NAMN]'
82
 
@@ -113,4 +119,4 @@ if __name__ == "__main__":
113
  print(f"\nINPUT: {text}")
114
  print(f"OUTPUT: {result}")
115
 
116
- print("\n" + "="*80)
 
 
1
  import re
2
  import logging
 
3
 
4
  logger = logging.getLogger(__name__)
5
 
 
29
  r'(ol|in|stat|pril|zol|am|um|ase|mycin|axin|cillin)$',
30
  ]
31
 
32
+ MEDICATION_EXCLUSIONS = [
33
+ 'Metoprolol', 'Atorvastatin', 'Losartan', 'Omeprazol',
34
+ 'Lisinopril', 'Simvastatin', 'Ramipril', 'Bisoprolol',
35
+ 'Warfarin', 'Insulin', 'Aspirin', 'Paracetamol', 'Ibuprofen',
36
+ 'Amoxicillin', 'Penicillin', 'Tetracyclin', 'Doxycyclin',
37
+ ]
38
+
39
  @staticmethod
40
  def has_medication_context(text: str) -> bool:
41
  for pattern in GDPRFilter.MEDICATION_CONTEXT_KEYWORDS:
 
75
  text = re.sub(r'(\[PERSONNR\])\s+\d{1,4}\b', r'\1', text)
76
 
77
  has_med_context = GDPRFilter.has_medication_context(text)
 
78
 
79
  def replace_name(match):
80
  word = match.group(0)
81
+ if GDPRFilter.is_likely_medication(word):
82
+ if has_med_context:
83
+ return word
84
+ return '[LÄKEMEDEL]'
85
+ if any(word.startswith(ex) for ex in GDPRFilter.MEDICATION_EXCLUSIONS):
86
  return word
87
  return '[NAMN]'
88
 
 
119
  print(f"\nINPUT: {text}")
120
  print(f"OUTPUT: {result}")
121
 
122
+ print("\n" + "="*80)