leilaghomashchi commited on
Commit
cb5a83f
·
verified ·
1 Parent(s): 989a66d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py CHANGED
@@ -82,6 +82,57 @@ class AnonymizationBenchmark:
82
 
83
  return max(total_entities, 1) # حداقل 1 برای جلوگیری از تقسیم بر صفر
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  def calculate_accuracy(self, original_text: str, anonymized_text: str) -> float:
86
  """محاسبه درستی کلی ناشناس‌سازی"""
87
  entities = self.extract_entities_from_text(anonymized_text)
 
82
 
83
  return max(total_entities, 1) # حداقل 1 برای جلوگیری از تقسیم بر صفر
84
 
85
+ def check_indexing_correctness(self, entities: Dict[str, List[str]]) -> float:
86
+ """بررسی درستی اندیس‌گذاری"""
87
+ total_checks = 0
88
+ passed_checks = 0
89
+
90
+ for entity_type, indices in entities.items():
91
+ if not indices:
92
+ continue
93
+
94
+ total_checks += 1
95
+ unique_indices = sorted([int(x) for x in set(indices)])
96
+
97
+ # بررسی شروع از 1
98
+ if unique_indices[0] == 1:
99
+ passed_checks += 0.5
100
+
101
+ # بررسی پیوستگی
102
+ expected = list(range(1, len(unique_indices) + 1))
103
+ if unique_indices == expected:
104
+ passed_checks += 0.5
105
+
106
+ return passed_checks / total_checks if total_checks > 0 else 0.0
107
+
108
+ def calculate_structure_preservation(self, original_text: str, anonymized_text: str) -> float:
109
+ """محاسبه امتیاز حفظ ساختار"""
110
+ # کلمات مهم که باید حفظ شوند
111
+ important_words = [
112
+ 'میلیارد', 'میلیون', 'تومان', 'ریال', 'درصد', 'سود', 'زیان',
113
+ 'مدیرعامل', 'شرکت', 'بانک', 'درآمد', 'سال', 'ماه'
114
+ ]
115
+
116
+ score = 0.0
117
+ total_checks = len(important_words)
118
+
119
+ for word in important_words:
120
+ if word in original_text and word in anonymized_text:
121
+ score += 1.0
122
+ elif word not in original_text:
123
+ total_checks -= 1
124
+
125
+ # بررسی حفظ تعداد کلمات (تقریبی)
126
+ original_words = len(original_text.split())
127
+ anonymized_words = len(anonymized_text.split())
128
+
129
+ if original_words > 0:
130
+ word_ratio = min(anonymized_words / original_words, 1.0)
131
+ score += word_ratio * 2
132
+ total_checks += 2
133
+
134
+ return score / total_checks if total_checks > 0 else 0.0
135
+
136
  def calculate_accuracy(self, original_text: str, anonymized_text: str) -> float:
137
  """محاسبه درستی کلی ناشناس‌سازی"""
138
  entities = self.extract_entities_from_text(anonymized_text)