PerSent 0.2.2__tar.gz → 0.2.3__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.3
4
4
  Summary: Persian Sentiment Analysis Toolkit
5
5
  Home-page: https://github.com/RezaGooner/PerSent
6
6
  Author: RezaGooner
@@ -112,30 +112,38 @@ 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, 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).
123
124
  """
124
125
  try:
125
126
  # Read input CSV
126
127
  df = pd.read_csv(input_csv)
127
128
 
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:
129
+ # Determine the correct column
130
+ if isinstance(text_column, int):
131
+ # Handle negative indices
132
+ if text_column < 0:
133
+ text_column = len(df.columns) + text_column
134
+
135
+ if text_column >= len(df.columns) or text_column < 0:
136
+ raise ValueError(f"Column index {text_column} is out of range")
137
+
138
+ column_name = df.columns[text_column]
139
+ else:
140
+ if text_column not in df.columns:
134
141
  raise ValueError(f"Column '{text_column}' not found in CSV file")
142
+ column_name = text_column
135
143
 
136
144
  # Analyze each comment
137
145
  tqdm.pandas(desc="Analyzing comments")
138
- df['sentiment'] = df[text_column].progress_apply(self.predict)
146
+ df['sentiment'] = df[column_name].progress_apply(self.predict)
139
147
 
140
148
  # Save results
141
149
  df.to_csv(output_path, index=False, encoding='utf-8-sig')
@@ -1,4 +1,4 @@
1
1
  from .CommentAnalyzer import CommentAnalyzer
2
2
 
3
- __version__ = "0.2.2"
3
+ __version__ = "0.2.3"
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.3
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.3",
9
9
  author="RezaGooner",
10
10
  author_email="RezaAsadiProgrammer@Gmail.com",
11
11
  description="Persian Sentiment Analysis Toolkit",
File without changes
File without changes