PerSent 0.2.2__tar.gz → 0.2.4__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.2.2
3
+ Version: 0.2.4
4
4
  Summary: Persian Sentiment Analysis Toolkit
5
5
  Home-page: https://github.com/RezaGooner/PerSent
6
6
  Author: RezaGooner
@@ -112,40 +112,88 @@ class CommentAnalyzer:
112
112
  self.classifier = joblib.load(os.path.join(self.model_dir, 'classifier.joblib'))
113
113
  self.vectorizer = Word2Vec.load(os.path.join(self.model_dir, 'word2vec.model'))
114
114
 
115
- def csvPredict(self, input_csv, output_path, text_column='body'):
115
+ def csvPredict(self, input_csv, output_path, summary_path=None, text_column=0):
116
116
  """
117
117
  Analyze sentiment for comments in a CSV file and save results
118
118
 
119
119
  Parameters:
120
120
  input_csv (str): Path to input CSV file
121
121
  output_path (str): Path to save output CSV file
122
- text_column (str, optional): Name of column containing comments. Defaults to 'body'.
122
+ text_column (str/int, optional): Name or index (0-based) of column containing comments.
123
+ Defaults to 0 (first column).
124
+ summary_path (str, optional): Path to save prediction summary report.
125
+ If None, no summary will be saved.
123
126
  """
124
127
  try:
125
128
  # Read input CSV
126
129
  df = pd.read_csv(input_csv)
127
130
 
128
- # Check if specified column exists
129
- if text_column not in df.columns:
130
- # If only one column exists, use it regardless of name
131
- if len(df.columns) == 1:
132
- text_column = df.columns[0]
133
- else:
131
+ # Determine the correct column
132
+ if isinstance(text_column, int):
133
+ # Handle negative indices
134
+ if text_column < 0:
135
+ text_column = len(df.columns) + text_column
136
+
137
+ if text_column >= len(df.columns) or text_column < 0:
138
+ raise ValueError(f"Column index {text_column} is out of range")
139
+
140
+ column_name = df.columns[text_column]
141
+ else:
142
+ if text_column not in df.columns:
134
143
  raise ValueError(f"Column '{text_column}' not found in CSV file")
144
+ column_name = text_column
135
145
 
136
146
  # Analyze each comment
137
147
  tqdm.pandas(desc="Analyzing comments")
138
- df['sentiment'] = df[text_column].progress_apply(self.predict)
148
+ df['sentiment'] = df[column_name].progress_apply(self.predict)
139
149
 
140
150
  # Save results
141
151
  df.to_csv(output_path, index=False, encoding='utf-8-sig')
142
152
  print(f"Results saved to {output_path}")
143
153
 
154
+ # Generate and save summary if requested
155
+ if summary_path:
156
+ summary = self._generate_summary(df)
157
+ summary.to_csv(summary_path, index=False, encoding='utf-8-sig')
158
+ print(f"Summary report saved to {summary_path}")
159
+
144
160
  return df
145
161
 
146
162
  except Exception as e:
147
163
  print(f"Error: {str(e)}")
148
164
  return None
149
165
 
166
+ def _generate_summary(self, df):
167
+ """Generate prediction summary statistics"""
168
+ # Count each sentiment
169
+ counts = df['sentiment'].value_counts().to_dict()
170
+
171
+ # Create summary dataframe
172
+ summary = pd.DataFrame({
173
+ 'Category': [
174
+ 'Recommended',
175
+ 'Not Recommended',
176
+ 'No Idea',
177
+ 'Total',
178
+ 'Model Accuracy'
179
+ ],
180
+ 'Count': [
181
+ counts.get('recommended', 0),
182
+ counts.get('not_recommended', 0),
183
+ counts.get('no_idea', 0),
184
+ len(df),
185
+ 'N/A' # Accuracy needs to be calculated during training
186
+ ],
187
+ 'Percentage': [
188
+ f"{100 * counts.get('recommended', 0) / len(df):.2f}%",
189
+ f"{100 * counts.get('not_recommended', 0) / len(df):.2f}%",
190
+ f"{100 * counts.get('no_idea', 0) / len(df):.2f}%",
191
+ '100%',
192
+ 'N/A'
193
+ ]
194
+ })
195
+
196
+ return summary
197
+
150
198
 
151
199
  # Github : RezaGooner
@@ -1,4 +1,4 @@
1
1
  from .CommentAnalyzer import CommentAnalyzer
2
2
 
3
- __version__ = "0.2.2"
3
+ __version__ = "0.2.4"
4
4
  __all__ = ['CommentAnalyzer']
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PerSent
3
- Version: 0.2.2
3
+ Version: 0.2.4
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.2.2",
8
+ version="0.2.4",
9
9
  author="RezaGooner",
10
10
  author_email="RezaAsadiProgrammer@Gmail.com",
11
11
  description="Persian Sentiment Analysis Toolkit",
File without changes
File without changes