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.
- {persent-0.2.2 → persent-0.2.3}/PKG-INFO +1 -1
- {persent-0.2.2 → persent-0.2.3}/PerSent/CommentAnalyzer.py +17 -9
- {persent-0.2.2 → persent-0.2.3}/PerSent/__init__.py +1 -1
- {persent-0.2.2 → persent-0.2.3}/PerSent.egg-info/PKG-INFO +1 -1
- {persent-0.2.2 → persent-0.2.3}/setup.py +1 -1
- {persent-0.2.2 → persent-0.2.3}/PerSent.egg-info/SOURCES.txt +0 -0
- {persent-0.2.2 → persent-0.2.3}/PerSent.egg-info/dependency_links.txt +0 -0
- {persent-0.2.2 → persent-0.2.3}/PerSent.egg-info/requires.txt +0 -0
- {persent-0.2.2 → persent-0.2.3}/PerSent.egg-info/top_level.txt +0 -0
- {persent-0.2.2 → persent-0.2.3}/README.md +0 -0
- {persent-0.2.2 → persent-0.2.3}/setup.cfg +0 -0
|
@@ -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=
|
|
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.
|
|
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
|
-
#
|
|
129
|
-
if text_column
|
|
130
|
-
#
|
|
131
|
-
if
|
|
132
|
-
text_column = df.columns
|
|
133
|
-
|
|
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[
|
|
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')
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|