PerSent 1.3.0__tar.gz → 1.3.2__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.
- persent-1.3.2/MANIFEST.in +2 -0
- {persent-1.3.0 → persent-1.3.2}/PKG-INFO +1 -1
- {persent-1.3.0 → persent-1.3.2}/PerSent/CommentAnalyzer.py +26 -10
- {persent-1.3.0 → persent-1.3.2}/PerSent/SentimentAnalyzer.py +6 -10
- {persent-1.3.0 → persent-1.3.2}/PerSent/__init__.py +2 -2
- {persent-1.3.0 → persent-1.3.2}/PerSent.egg-info/PKG-INFO +1 -1
- {persent-1.3.0 → persent-1.3.2}/PerSent.egg-info/SOURCES.txt +3 -3
- {persent-1.3.0 → persent-1.3.2}/setup.py +2 -2
- persent-1.3.0/MANIFEST.in +0 -1
- {persent-1.3.0/PerSent/model → persent-1.3.2/PerSent/models}/classifier.joblib +0 -0
- {persent-1.3.0/PerSent/model → persent-1.3.2/PerSent/models}/weighted_sentiment_model.joblib +0 -0
- {persent-1.3.0/PerSent/model → persent-1.3.2/PerSent/models}/word2vec.model +0 -0
- {persent-1.3.0 → persent-1.3.2}/PerSent.egg-info/dependency_links.txt +0 -0
- {persent-1.3.0 → persent-1.3.2}/PerSent.egg-info/requires.txt +0 -0
- {persent-1.3.0 → persent-1.3.2}/PerSent.egg-info/top_level.txt +0 -0
- {persent-1.3.0 → persent-1.3.2}/README.md +0 -0
- {persent-1.3.0 → persent-1.3.2}/setup.cfg +0 -0
|
@@ -9,6 +9,8 @@ from sklearn.linear_model import LogisticRegression
|
|
|
9
9
|
from sklearn.model_selection import train_test_split
|
|
10
10
|
import os
|
|
11
11
|
import joblib
|
|
12
|
+
import importlib.resources
|
|
13
|
+
|
|
12
14
|
|
|
13
15
|
class CommentAnalyzer:
|
|
14
16
|
def __init__(self, model_dir='PerSent/model'):
|
|
@@ -140,21 +142,35 @@ class CommentAnalyzer:
|
|
|
140
142
|
except Exception as e:
|
|
141
143
|
raise Exception(f"Error while saving model: {str(e)}")
|
|
142
144
|
|
|
145
|
+
|
|
143
146
|
def loadModel(self):
|
|
144
|
-
"""reload from
|
|
147
|
+
"""reload from package asset or model_dir"""
|
|
145
148
|
try:
|
|
146
|
-
|
|
147
|
-
|
|
149
|
+
classifier_filename = 'classifier.joblib'
|
|
150
|
+
vectorizer_filename = 'word2vec.model'
|
|
151
|
+
|
|
152
|
+
classifier_path = os.path.join(self.model_dir, classifier_filename)
|
|
153
|
+
vectorizer_path = os.path.join(self.model_dir, vectorizer_filename)
|
|
154
|
+
|
|
155
|
+
if os.path.exists(classifier_path) and os.path.exists(vectorizer_path):
|
|
156
|
+
self.classifier = joblib.load(classifier_path)
|
|
157
|
+
self.vectorizer = Word2Vec.load(vectorizer_path)
|
|
158
|
+
return
|
|
148
159
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
160
|
+
try:
|
|
161
|
+
with importlib.resources.path("PerSent.models", classifier_filename) as clf_p, \
|
|
162
|
+
importlib.resources.path("PerSent.models", vectorizer_filename) as vec_p:
|
|
163
|
+
self.classifier = joblib.load(clf_p)
|
|
164
|
+
self.vectorizer = Word2Vec.load(str(vec_p))
|
|
165
|
+
except FileNotFoundError as e:
|
|
166
|
+
raise FileNotFoundError("Model files not found in model_dir *and* package asset")
|
|
167
|
+
except Exception as e:
|
|
168
|
+
raise Exception(f"Failed to load model from package: {str(e)}")
|
|
169
|
+
|
|
156
170
|
except Exception as e:
|
|
157
171
|
raise Exception(f"Failed to load model: {str(e)}")
|
|
172
|
+
|
|
173
|
+
|
|
158
174
|
|
|
159
175
|
def analyzeCSV(self, input_csv, output_path, summary_path=None, text_column=0):
|
|
160
176
|
"""
|
|
@@ -11,6 +11,7 @@ from collections import defaultdict
|
|
|
11
11
|
from hazm import Stemmer, Lemmatizer, Normalizer, word_tokenize, stopwords_list
|
|
12
12
|
from tqdm import tqdm
|
|
13
13
|
import pandas as pd
|
|
14
|
+
import importlib.resources
|
|
14
15
|
|
|
15
16
|
class SentimentAnalyzer:
|
|
16
17
|
"""A Persian sentiment analyzer that supports word weighting"""
|
|
@@ -239,20 +240,15 @@ class SentimentAnalyzer:
|
|
|
239
240
|
"""
|
|
240
241
|
try:
|
|
241
242
|
model_path = os.path.join(self.model_dir, f'{model_name}.joblib')
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
243
|
+
if os.path.exists(model_path):
|
|
244
|
+
data = joblib.load(model_path)
|
|
245
|
+
else:
|
|
246
|
+
with importlib.resources.path("PerSent.models", f'{model_name}.joblib') as pkg_model_path:
|
|
247
|
+
data = joblib.load(pkg_model_path)
|
|
247
248
|
self.emotion_map = data['emotion_map']
|
|
248
249
|
self.keywords = defaultdict(list, data['keywords'])
|
|
249
250
|
self.word_weights = defaultdict(dict, data['word_weights'])
|
|
250
251
|
self.model_loaded = True
|
|
251
|
-
|
|
252
|
-
except FileNotFoundError as e:
|
|
253
|
-
raise FileNotFoundError(f"Model file not found: {str(e)}")
|
|
254
|
-
except (KeyError, AttributeError) as e:
|
|
255
|
-
raise ValueError(f"Invalid or corrupted model file: {str(e)}")
|
|
256
252
|
except Exception as e:
|
|
257
253
|
raise Exception(f"Failed to load model: {str(e)}")
|
|
258
254
|
|
|
@@ -3,8 +3,8 @@ from .SentimentAnalyzer import SentimentAnalyzer
|
|
|
3
3
|
from pathlib import Path
|
|
4
4
|
import os
|
|
5
5
|
|
|
6
|
-
MODEL_DIR = Path(__file__).parent / "
|
|
6
|
+
MODEL_DIR = Path(__file__).parent / "models"
|
|
7
7
|
os.makedirs(MODEL_DIR, exist_ok=True)
|
|
8
8
|
|
|
9
|
-
__version__ = "1.3.
|
|
9
|
+
__version__ = "1.3.2"
|
|
10
10
|
__all__ = ['CommentAnalyzer', 'SentimentAnalyzer', 'MODEL_DIR']
|
|
@@ -10,6 +10,6 @@ PerSent.egg-info/SOURCES.txt
|
|
|
10
10
|
PerSent.egg-info/dependency_links.txt
|
|
11
11
|
PerSent.egg-info/requires.txt
|
|
12
12
|
PerSent.egg-info/top_level.txt
|
|
13
|
-
PerSent/
|
|
14
|
-
PerSent/
|
|
15
|
-
PerSent/
|
|
13
|
+
PerSent/models/classifier.joblib
|
|
14
|
+
PerSent/models/weighted_sentiment_model.joblib
|
|
15
|
+
PerSent/models/word2vec.model
|
|
@@ -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="1.3.
|
|
8
|
+
version="1.3.2",
|
|
9
9
|
author="RezaGooner",
|
|
10
10
|
author_email="RezaAsadiProgrammer@Gmail.com",
|
|
11
11
|
description="Persian Sentiment Analysis Toolkit",
|
|
@@ -14,7 +14,7 @@ setup(
|
|
|
14
14
|
url="https://github.com/RezaGooner/PerSent",
|
|
15
15
|
packages=find_packages(),
|
|
16
16
|
package_data={
|
|
17
|
-
'PerSent': ['CommentAnalyzer.py','SentimentAnalyzer.py' , '
|
|
17
|
+
'PerSent': ['CommentAnalyzer.py','SentimentAnalyzer.py' , 'models/*'],
|
|
18
18
|
},
|
|
19
19
|
include_package_data=True,
|
|
20
20
|
install_requires=[
|
persent-1.3.0/MANIFEST.in
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
recursive-include PerSent/models *.*
|
|
File without changes
|
{persent-1.3.0/PerSent/model → persent-1.3.2/PerSent/models}/weighted_sentiment_model.joblib
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|