PerSent 0.1.4__tar.gz → 0.1.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of PerSent might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PerSent
3
- Version: 0.1.4
3
+ Version: 0.1.6
4
4
  Summary: Persian Sentiment Analysis Toolkit
5
5
  Home-page: https://github.com/RezaGooner/PerSent
6
6
  Author: RezaGooner
@@ -1,4 +1,4 @@
1
1
  from .analyzer import PersianSentimentAnalyzer
2
2
 
3
- __version__ = "0.1.4"
3
+ __version__ = "0.1.6"
4
4
  __all__ = ['PersianSentimentAnalyzer']
@@ -39,6 +39,17 @@ class AdvancedPersianSentimentAnalyzer:
39
39
  'sg': 1 # استفاده از skip-gram
40
40
  }
41
41
 
42
+ # نگاشت برچسب‌های احساسات
43
+ self.emotion_labels = {
44
+ 'ترس': 'Fear',
45
+ 'تعجب': 'Surprise',
46
+ 'خشم': 'Anger',
47
+ 'تحقیر': 'Contempt',
48
+ 'شادی': 'Joy',
49
+ 'غم': 'Sadness',
50
+ 'انزجار': 'Disgust'
51
+ }
52
+
42
53
  os.makedirs(self.model_dir, exist_ok=True)
43
54
 
44
55
  def _preprocess_text(self, text, for_emotion=False):
@@ -81,19 +92,36 @@ class AdvancedPersianSentimentAnalyzer:
81
92
  return np.zeros(self.w2v_params['vector_size'])
82
93
 
83
94
  def _emotion_analysis(self, text):
84
- """تحلیل احساسات پیشرفته با مدیریت خطا"""
95
+ """تحلیل احساسات پیشرفته با مدل BERT"""
85
96
  try:
97
+ # پیش‌پردازش متن برای تحلیل احساسات
86
98
  processed_text = self._preprocess_text(text, for_emotion=True)
99
+
100
+ # تحلیل احساسات
87
101
  results = self.emotion_analyzer(processed_text)[0]
88
102
 
89
- return {
90
- item['label']: round(float(item['score']), 4)
91
- for item in results
92
- if item['label'] in ['ترس', 'تعجب', 'خشم', 'تحقیر', 'شادی', 'غم', 'انزجار']
93
- }
103
+ # پردازش نتایج
104
+ emotions = {}
105
+ for item in results:
106
+ fa_label = item['label']
107
+ if fa_label in self.emotion_labels:
108
+ en_label = self.emotion_labels[fa_label]
109
+ score = round(float(item['score']), 4)
110
+ emotions[en_label] = score
111
+
112
+ # اگر همه مقادیر صفر بودند، قوی‌ترین احساس را برگردان
113
+ if all(v == 0 for v in emotions.values()) and results:
114
+ top_emotion = max(results, key=lambda x: x['score'])
115
+ fa_label = top_emotion['label']
116
+ if fa_label in self.emotion_labels:
117
+ en_label = self.emotion_labels[fa_label]
118
+ emotions[en_label] = round(float(top_emotion['score']), 4)
119
+
120
+ return emotions
121
+
94
122
  except Exception as e:
95
- print(f"Error in emotion analysis: {str(e)}")
96
- return {label: 0.0 for label in ['ترس', 'تعجب', 'خشم', 'تحقیر', 'شادی', 'غم', 'انزجار']}
123
+ print(f"خطا در تحلیل احساسات: {str(e)}")
124
+ return {label: 0.0 for label in self.emotion_labels.values()}
97
125
 
98
126
  def train(self, train_csv, test_size=0.2):
99
127
  """آموزش پیشرفته مدل تحلیل توصیه"""
@@ -151,7 +179,7 @@ class AdvancedPersianSentimentAnalyzer:
151
179
  'model_params': self.w2v_params
152
180
  }
153
181
 
154
- def predict(self, text, mode=0, threshold=0.3):
182
+ def predict(self, text, mode=0, threshold=0.1):
155
183
  """
156
184
  پیش‌بینی پیشرفته با قابلیت تنظیم آستانه
157
185
 
@@ -220,3 +248,4 @@ class AdvancedPersianSentimentAnalyzer:
220
248
  self.vectorizer = Word2Vec.load(
221
249
  os.path.join(self.model_dir, f'word2vec_v{version}.model')
222
250
  )
251
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PerSent
3
- Version: 0.1.4
3
+ Version: 0.1.6
4
4
  Summary: Persian Sentiment Analysis Toolkit
5
5
  Home-page: https://github.com/RezaGooner/PerSent
6
6
  Author: RezaGooner
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
5
5
 
6
6
  setup(
7
7
  name="PerSent",
8
- version="0.1.4",
8
+ version="0.1.6",
9
9
  author="RezaGooner",
10
10
  author_email="RezaAsadiProgrammer@Gmail.com",
11
11
  description="Persian Sentiment Analysis Toolkit",
File without changes
File without changes
File without changes
File without changes