PerSent 1.0.0__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-1.0.0/PKG-INFO +44 -0
- persent-1.0.0/PerSent/__init__.py +50 -0
- persent-1.0.0/PerSent/core/models/base_model.py +31 -0
- persent-1.0.0/PerSent.egg-info/PKG-INFO +44 -0
- persent-1.0.0/PerSent.egg-info/SOURCES.txt +10 -0
- persent-1.0.0/PerSent.egg-info/dependency_links.txt +1 -0
- persent-1.0.0/PerSent.egg-info/requires.txt +6 -0
- persent-1.0.0/PerSent.egg-info/top_level.txt +1 -0
- persent-1.0.0/README.md +11 -0
- persent-1.0.0/setup.cfg +4 -0
- persent-1.0.0/setup.py +51 -0
- persent-1.0.0/tests/test_core.py +20 -0
persent-1.0.0/PKG-INFO
ADDED
|
@@ -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,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,10 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.py
|
|
3
|
+
PerSent/__init__.py
|
|
4
|
+
PerSent.egg-info/PKG-INFO
|
|
5
|
+
PerSent.egg-info/SOURCES.txt
|
|
6
|
+
PerSent.egg-info/dependency_links.txt
|
|
7
|
+
PerSent.egg-info/requires.txt
|
|
8
|
+
PerSent.egg-info/top_level.txt
|
|
9
|
+
PerSent/core/models/base_model.py
|
|
10
|
+
tests/test_core.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
PerSent
|
persent-1.0.0/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# PerSent - Persian Sentiment Analysis Toolkit
|
|
2
|
+
|
|
3
|
+
کتابخانه جامع تحلیل احساسات متن فارسی برای حوزههای مختلف
|
|
4
|
+
|
|
5
|
+
## قابلیتهای کلیدی
|
|
6
|
+
|
|
7
|
+
- پردازش هوشمند متنهای فارسی
|
|
8
|
+
- پشتیبانی از حوزههای مختلف (عمومی، خبری، شبکهاجتماعی)
|
|
9
|
+
- ترکیب روشهای مبتنی بر دیکشنری و یادگیری ماشین
|
|
10
|
+
- محاسبه شدت احساسات
|
|
11
|
+
- تشخیص خودکار حوزه متن
|
persent-1.0.0/setup.cfg
ADDED
persent-1.0.0/setup.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
def get_version():
|
|
5
|
+
here = os.path.abspath(os.path.dirname(__file__))
|
|
6
|
+
with open(os.path.join(here, "PerSent", "__init__.py"), encoding="utf-8") as f:
|
|
7
|
+
for line in f.readlines():
|
|
8
|
+
if line.startswith("__version__"):
|
|
9
|
+
return line.split("=")[1].strip().strip('"\'')
|
|
10
|
+
return "0.1.0"
|
|
11
|
+
|
|
12
|
+
setup(
|
|
13
|
+
name="PerSent",
|
|
14
|
+
version=get_version(),
|
|
15
|
+
packages=find_packages(),
|
|
16
|
+
package_data={
|
|
17
|
+
"PerSent": [
|
|
18
|
+
"core/models/*",
|
|
19
|
+
"utils/lexicons/*.json"
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
install_requires=[
|
|
23
|
+
"hazm>=0.9.0",
|
|
24
|
+
"gensim>=4.3.0",
|
|
25
|
+
"scikit-learn>=1.3.0",
|
|
26
|
+
"pandas>=2.0.0",
|
|
27
|
+
"joblib>=1.3.0",
|
|
28
|
+
"jdatetime>=4.1.0"
|
|
29
|
+
],
|
|
30
|
+
python_requires=">=3.8",
|
|
31
|
+
author="RezaGooner",
|
|
32
|
+
author_email="RezaAsadiProgrammer@Gmail.com",
|
|
33
|
+
description="Comprehensive Persian Sentiment Analysis Toolkit",
|
|
34
|
+
long_description=open("README.md", encoding="utf-8").read(),
|
|
35
|
+
long_description_content_type="text/markdown",
|
|
36
|
+
url="https://github.com/RezaGooner/PerSent",
|
|
37
|
+
classifiers=[
|
|
38
|
+
"Development Status :: 4 - Beta",
|
|
39
|
+
"Intended Audience :: Developers",
|
|
40
|
+
"Natural Language :: Persian",
|
|
41
|
+
"Topic :: Text Processing :: Linguistic",
|
|
42
|
+
"Programming Language :: Python :: 3.8",
|
|
43
|
+
"License :: OSI Approved :: MIT License",
|
|
44
|
+
],
|
|
45
|
+
keywords=[
|
|
46
|
+
"persian-nlp",
|
|
47
|
+
"sentiment-analysis",
|
|
48
|
+
"text-analytics",
|
|
49
|
+
"farsi-text-processing"
|
|
50
|
+
],
|
|
51
|
+
)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from PerSent.core.analyzer import PersianSentimentAnalyzer
|
|
3
|
+
from PerSent.domains import NewsAnalyzer
|
|
4
|
+
|
|
5
|
+
class TestCoreFunctionality(unittest.TestCase):
|
|
6
|
+
def setUp(self):
|
|
7
|
+
self.general_analyzer = PersianSentimentAnalyzer()
|
|
8
|
+
self.news_analyzer = NewsAnalyzer()
|
|
9
|
+
|
|
10
|
+
def test_general_analysis(self):
|
|
11
|
+
result = self.general_analyzer.analyze("این محصول خوب است")
|
|
12
|
+
self.assertIn(result, ['positive', 'negative', 'neutral'])
|
|
13
|
+
|
|
14
|
+
def test_news_analysis(self):
|
|
15
|
+
news_text = "رشد اقتصادی در سال جاری مثبت بود"
|
|
16
|
+
result = self.news_analyzer.analyze(news_text)
|
|
17
|
+
self.assertEqual(result, 'positive')
|
|
18
|
+
|
|
19
|
+
if __name__ == '__main__':
|
|
20
|
+
unittest.main()
|