PerSent 0.2.1__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.1 → persent-0.2.3}/PKG-INFO +1 -1
- {persent-0.2.1 → persent-0.2.3}/PerSent/CommentAnalyzer.py +46 -0
- {persent-0.2.1 → persent-0.2.3}/PerSent/__init__.py +1 -1
- {persent-0.2.1 → persent-0.2.3}/PerSent.egg-info/PKG-INFO +1 -1
- {persent-0.2.1 → persent-0.2.3}/setup.py +1 -1
- {persent-0.2.1 → persent-0.2.3}/PerSent.egg-info/SOURCES.txt +0 -0
- {persent-0.2.1 → persent-0.2.3}/PerSent.egg-info/dependency_links.txt +0 -0
- {persent-0.2.1 → persent-0.2.3}/PerSent.egg-info/requires.txt +0 -0
- {persent-0.2.1 → persent-0.2.3}/PerSent.egg-info/top_level.txt +0 -0
- {persent-0.2.1 → persent-0.2.3}/README.md +0 -0
- {persent-0.2.1 → persent-0.2.3}/setup.cfg +0 -0
|
@@ -111,3 +111,49 @@ class CommentAnalyzer:
|
|
|
111
111
|
"""reload from file"""
|
|
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
|
+
|
|
115
|
+
def csvPredict(self, input_csv, output_path, text_column=0):
|
|
116
|
+
"""
|
|
117
|
+
Analyze sentiment for comments in a CSV file and save results
|
|
118
|
+
|
|
119
|
+
Parameters:
|
|
120
|
+
input_csv (str): Path to input CSV file
|
|
121
|
+
output_path (str): Path to save output CSV file
|
|
122
|
+
text_column (str/int, optional): Name or index (0-based) of column containing comments.
|
|
123
|
+
Defaults to 0 (first column).
|
|
124
|
+
"""
|
|
125
|
+
try:
|
|
126
|
+
# Read input CSV
|
|
127
|
+
df = pd.read_csv(input_csv)
|
|
128
|
+
|
|
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:
|
|
141
|
+
raise ValueError(f"Column '{text_column}' not found in CSV file")
|
|
142
|
+
column_name = text_column
|
|
143
|
+
|
|
144
|
+
# Analyze each comment
|
|
145
|
+
tqdm.pandas(desc="Analyzing comments")
|
|
146
|
+
df['sentiment'] = df[column_name].progress_apply(self.predict)
|
|
147
|
+
|
|
148
|
+
# Save results
|
|
149
|
+
df.to_csv(output_path, index=False, encoding='utf-8-sig')
|
|
150
|
+
print(f"Results saved to {output_path}")
|
|
151
|
+
|
|
152
|
+
return df
|
|
153
|
+
|
|
154
|
+
except Exception as e:
|
|
155
|
+
print(f"Error: {str(e)}")
|
|
156
|
+
return None
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
# Github : RezaGooner
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|