PerSent 1.0.0__py3-none-any.whl
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/__init__.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
PerSent - کتابخانه جامع تحلیل احساسات متن فارسی
|
|
4
|
+
|
|
5
|
+
نسخه: 1.0.0
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .core.analyzer import PersianSentimentAnalyzer
|
|
9
|
+
from .domains.news import NewsAnalyzer
|
|
10
|
+
from .domains.social import SocialMediaAnalyzer
|
|
11
|
+
from .domains.comments import CommentAnalyzer
|
|
12
|
+
from .utils.dictionary import load_custom_dictionary
|
|
13
|
+
|
|
14
|
+
# تعریف نسخه
|
|
15
|
+
__version__ = "1.0.0"
|
|
16
|
+
__all__ = [
|
|
17
|
+
'PersianSentimentAnalyzer',
|
|
18
|
+
'NewsAnalyzer',
|
|
19
|
+
'SocialMediaAnalyzer',
|
|
20
|
+
'CommentAnalyzer',
|
|
21
|
+
'load_custom_dictionary'
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
# تنظیمات اولیه
|
|
25
|
+
class Config:
|
|
26
|
+
DEFAULT_MODEL_PATH = "models/v1/"
|
|
27
|
+
ENABLE_LOGGING = True
|
|
28
|
+
MAX_TEXT_LENGTH = 5000
|
|
29
|
+
|
|
30
|
+
@classmethod
|
|
31
|
+
def set_model_path(cls, path):
|
|
32
|
+
cls.DEFAULT_MODEL_PATH = path
|
|
33
|
+
|
|
34
|
+
# بارگذاری خودکار مدلهای پایه
|
|
35
|
+
try:
|
|
36
|
+
from .core.models import BaseModel
|
|
37
|
+
base_model = BaseModel()
|
|
38
|
+
except ImportError as e:
|
|
39
|
+
import warnings
|
|
40
|
+
warnings.warn(f"Failed to load base models: {str(e)}")
|
|
41
|
+
|
|
42
|
+
# فعال کردن لوگر پیشفرض
|
|
43
|
+
if Config.ENABLE_LOGGING:
|
|
44
|
+
import logging
|
|
45
|
+
logging.basicConfig(
|
|
46
|
+
level=logging.INFO,
|
|
47
|
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
48
|
+
)
|
|
49
|
+
logger = logging.getLogger('PerSent')
|
|
50
|
+
logger.info(f"PerSent v{__version__} initialized")
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import joblib
|
|
2
|
+
import numpy as np
|
|
3
|
+
from gensim.models import Word2Vec
|
|
4
|
+
from typing import List
|
|
5
|
+
|
|
6
|
+
class BaseModel:
|
|
7
|
+
def __init__(self, model_path: str = None):
|
|
8
|
+
self.vectorizer = None
|
|
9
|
+
self.classifier = None
|
|
10
|
+
if model_path:
|
|
11
|
+
self.load(model_path)
|
|
12
|
+
|
|
13
|
+
def predict(self, tokens: List[str]) -> str:
|
|
14
|
+
"""پیشبینی احساس از توکنها"""
|
|
15
|
+
vector = self._vectorize(tokens)
|
|
16
|
+
pred = self.classifier.predict([vector])[0]
|
|
17
|
+
return self._decode_prediction(pred)
|
|
18
|
+
|
|
19
|
+
def _vectorize(self, tokens: List[str]) -> np.ndarray:
|
|
20
|
+
"""تبدیل توکنها به بردار"""
|
|
21
|
+
vectors = [self.vectorizer.wv[t] for t in tokens if t in self.vectorizer.wv]
|
|
22
|
+
return np.mean(vectors, axis=0) if vectors else np.zeros(100)
|
|
23
|
+
|
|
24
|
+
def _decode_prediction(self, code: int) -> str:
|
|
25
|
+
"""تبدیل کد پیشبینی به متن"""
|
|
26
|
+
return {0: 'negative', 1: 'positive', 2: 'neutral'}.get(code, 'neutral')
|
|
27
|
+
|
|
28
|
+
def load(self, model_dir: str):
|
|
29
|
+
"""بارگذاری مدل از مسیر"""
|
|
30
|
+
self.vectorizer = Word2Vec.load(f"{model_dir}/word2vec.model")
|
|
31
|
+
self.classifier = joblib.load(f"{model_dir}/classifier.joblib")
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: PerSent
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Comprehensive Persian Sentiment Analysis Toolkit
|
|
5
|
+
Home-page: https://github.com/RezaGooner/PerSent
|
|
6
|
+
Author: RezaGooner
|
|
7
|
+
Author-email: RezaAsadiProgrammer@Gmail.com
|
|
8
|
+
Keywords: persian-nlp,sentiment-analysis,text-analytics,farsi-text-processing
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Natural Language :: Persian
|
|
12
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Requires-Python: >=3.8
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
Requires-Dist: hazm>=0.9.0
|
|
18
|
+
Requires-Dist: gensim>=4.3.0
|
|
19
|
+
Requires-Dist: scikit-learn>=1.3.0
|
|
20
|
+
Requires-Dist: pandas>=2.0.0
|
|
21
|
+
Requires-Dist: joblib>=1.3.0
|
|
22
|
+
Requires-Dist: jdatetime>=4.1.0
|
|
23
|
+
Dynamic: author
|
|
24
|
+
Dynamic: author-email
|
|
25
|
+
Dynamic: classifier
|
|
26
|
+
Dynamic: description
|
|
27
|
+
Dynamic: description-content-type
|
|
28
|
+
Dynamic: home-page
|
|
29
|
+
Dynamic: keywords
|
|
30
|
+
Dynamic: requires-dist
|
|
31
|
+
Dynamic: requires-python
|
|
32
|
+
Dynamic: summary
|
|
33
|
+
|
|
34
|
+
# PerSent - Persian Sentiment Analysis Toolkit
|
|
35
|
+
|
|
36
|
+
کتابخانه جامع تحلیل احساسات متن فارسی برای حوزههای مختلف
|
|
37
|
+
|
|
38
|
+
## قابلیتهای کلیدی
|
|
39
|
+
|
|
40
|
+
- پردازش هوشمند متنهای فارسی
|
|
41
|
+
- پشتیبانی از حوزههای مختلف (عمومی، خبری، شبکهاجتماعی)
|
|
42
|
+
- ترکیب روشهای مبتنی بر دیکشنری و یادگیری ماشین
|
|
43
|
+
- محاسبه شدت احساسات
|
|
44
|
+
- تشخیص خودکار حوزه متن
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
PerSent/__init__.py,sha256=M0A8Zd0PXPLLpjJqxH1IVi-gPh668LRECK8ldVVaCjM,1383
|
|
2
|
+
PerSent/core/models/base_model.py,sha256=GIrXk4ShhlngebfktZ-i-YsvcKCiHSs9NK4qQLmFz4w,1256
|
|
3
|
+
persent-1.0.0.dist-info/METADATA,sha256=Mmr5Hcby4sNOXKSTy92EUfBrtr76UEQZpIU8IShJBbU,1604
|
|
4
|
+
persent-1.0.0.dist-info/WHEEL,sha256=DK49LOLCYiurdXXOXwGJm6U4DkHkg4lcxjhqwRa0CP4,91
|
|
5
|
+
persent-1.0.0.dist-info/top_level.txt,sha256=D-YZBGOvL3FdEaLI9OwoTXniE26IUqE_dX3w8XEiDms,8
|
|
6
|
+
persent-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
PerSent
|