EGYADMIN commited on
Commit
0d546e2
·
verified ·
1 Parent(s): c26339c

Update modules/document_comparison/document_comparator.py

Browse files
modules/document_comparison/document_comparator.py CHANGED
@@ -38,8 +38,24 @@ class DocumentComparator:
38
  self.comparison_dir = os.path.join(os.path.dirname(__file__), '..', '..', 'data', 'document_comparison')
39
  create_directory_if_not_exists(self.comparison_dir)
40
 
 
 
 
41
  # إعداد مقيم ROUGE لمقارنة النصوص
42
  self.rouge_scorer = rouge_scorer.RougeScorer(['rouge1', 'rouge2', 'rougeL'], use_stemmer=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
  def _preprocess_text(self, text):
45
  """معالجة النص قبل التحليل"""
 
38
  self.comparison_dir = os.path.join(os.path.dirname(__file__), '..', '..', 'data', 'document_comparison')
39
  create_directory_if_not_exists(self.comparison_dir)
40
 
41
+ # تهيئة NLTK وتنزيل حزمة punkt إذا لم تكن موجودة
42
+ self._initialize_nltk()
43
+
44
  # إعداد مقيم ROUGE لمقارنة النصوص
45
  self.rouge_scorer = rouge_scorer.RougeScorer(['rouge1', 'rouge2', 'rougeL'], use_stemmer=False)
46
+
47
+ def _initialize_nltk(self):
48
+ """تهيئة مكتبة NLTK وتنزيل الحزم المطلوبة"""
49
+ try:
50
+ # محاولة استخدام sent_tokenize للتحقق من وجود حزمة punkt
51
+ from nltk.tokenize import sent_tokenize
52
+ sent_tokenize("This is a test sentence.")
53
+ except LookupError:
54
+ # تنزيل حزمة punkt تلقائيًا إذا لم تكن موجودة
55
+ import nltk
56
+ nltk.download('punkt', quiet=True)
57
+ # طباعة رسالة تأكيد التنزيل
58
+ st.info("تم تنزيل حزمة NLTK punkt بنجاح للاستخدام في مقارنة المستندات.")
59
 
60
  def _preprocess_text(self, text):
61
  """معالجة النص قبل التحليل"""