my-sentiment 0.1.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.
@@ -0,0 +1,37 @@
1
+ Metadata-Version: 2.4
2
+ Name: my-sentiment
3
+ Version: 0.1.0
4
+ Summary: A modular Python sentiment analysis library
5
+ Author: Mohammed Sinan K
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/markdown
8
+ Dynamic: author
9
+ Dynamic: description
10
+ Dynamic: description-content-type
11
+ Dynamic: requires-python
12
+ Dynamic: summary
13
+
14
+ # My Sentiment
15
+
16
+ A modular Python sentiment analysis library that analyzes text using
17
+ lexicon-based sentiment scoring, negation, modifiers, emphasis,
18
+ emojis, emoticons, and contextual expressions.
19
+
20
+ ## Features
21
+
22
+ - Lexicon-based sentiment analysis
23
+ - Tokenization
24
+ - Negation handling
25
+ - Intensifiers and modifiers
26
+ - Capitalization emphasis
27
+ - Punctuation emphasis
28
+ - Emoji sentiment
29
+ - Emoticon sentiment
30
+ - Context-aware sentiment
31
+ - Modular architecture
32
+ - Automated testing with pytest
33
+
34
+ ## Installation
35
+
36
+ `bash
37
+ pip install my-sentiment
@@ -0,0 +1,24 @@
1
+ # My Sentiment
2
+
3
+ A modular Python sentiment analysis library that analyzes text using
4
+ lexicon-based sentiment scoring, negation, modifiers, emphasis,
5
+ emojis, emoticons, and contextual expressions.
6
+
7
+ ## Features
8
+
9
+ - Lexicon-based sentiment analysis
10
+ - Tokenization
11
+ - Negation handling
12
+ - Intensifiers and modifiers
13
+ - Capitalization emphasis
14
+ - Punctuation emphasis
15
+ - Emoji sentiment
16
+ - Emoticon sentiment
17
+ - Context-aware sentiment
18
+ - Modular architecture
19
+ - Automated testing with pytest
20
+
21
+ ## Installation
22
+
23
+ `bash
24
+ pip install my-sentiment
@@ -0,0 +1,2 @@
1
+ from .sentiment import sentiment
2
+ __version__ = "0.1.0"
@@ -0,0 +1,88 @@
1
+ CONTEXT_RULES = {
2
+ "sick": {
3
+ "positive": [
4
+ "was sick",
5
+ "is sick",
6
+ "looks sick",
7
+ "that's sick",
8
+ "that was sick",
9
+ ],
10
+ "negative": [
11
+ "feel sick",
12
+ "feeling sick",
13
+ "am sick",
14
+ "felt sick",
15
+ ],
16
+ },
17
+
18
+ "insane": {
19
+ "positive": [
20
+ "was insane",
21
+ "is insane",
22
+ "looks insane",
23
+ "that's insane",
24
+ "that was insane",
25
+ ],
26
+ "negative": [
27
+ "feel insane",
28
+ "feeling insane",
29
+ "am insane",
30
+ "felt insane",
31
+ ],
32
+ },
33
+
34
+ "crazy": {
35
+ "positive": [
36
+ "was crazy",
37
+ "is crazy",
38
+ "looks crazy",
39
+ "that's crazy",
40
+ "that was crazy",
41
+ ],
42
+ "negative": [
43
+ "feel crazy",
44
+ "feeling crazy",
45
+ "am crazy",
46
+ "felt crazy",
47
+ ],
48
+ },
49
+
50
+ "wicked": {
51
+ "positive": [
52
+ "was wicked",
53
+ "is wicked",
54
+ "looks wicked",
55
+ "that's wicked",
56
+ "that was wicked",
57
+ ],
58
+ "negative": [
59
+ "feel wicked",
60
+ "feeling wicked",
61
+ "am wicked",
62
+ "felt wicked",
63
+ ],
64
+ },
65
+ }
66
+
67
+
68
+ def detect_context(text):
69
+ """
70
+ Detect contextual sentiment patterns in the text.
71
+
72
+ Returns:
73
+ list: A list of (word, sentiment) tuples.
74
+ """
75
+ text = text.lower()
76
+ found = []
77
+
78
+ for word, rules in CONTEXT_RULES.items():
79
+
80
+ for pattern in rules["positive"]:
81
+ if pattern in text:
82
+ found.append((word, "positive"))
83
+
84
+ for pattern in rules["negative"]:
85
+ if pattern in text:
86
+ found.append((word, "negative"))
87
+
88
+ return found
@@ -0,0 +1,36 @@
1
+ EMOJI_LEXICON = {
2
+ # Positive emojis
3
+ "❤️": 2.5,
4
+ "❤": 2.5,
5
+ "😊": 2.0,
6
+ "😄": 2.5,
7
+ "😁": 2.5,
8
+ "😍": 3.0,
9
+ "🥰": 3.0,
10
+ "😂": 2.0,
11
+ "🤣": 2.0,
12
+ "👍": 2.0,
13
+ "🎉": 2.5,
14
+ "✨": 1.5,
15
+
16
+ # Negative emojis
17
+ "😡": -2.5,
18
+ "😠": -2.0,
19
+ "😭": -2.5,
20
+ "😢": -2.0,
21
+ "😞": -2.0,
22
+ "😔": -1.5,
23
+ "🤬": -3.0,
24
+ "👎": -2.0,
25
+ "💔": -2.5,
26
+ "😱": -2.0,
27
+ }
28
+
29
+
30
+ def get_emoji_score(text):
31
+ score = 0.0
32
+
33
+ for emoji, value in EMOJI_LEXICON.items():
34
+ score += text.count(emoji) * value
35
+
36
+ return score
@@ -0,0 +1,33 @@
1
+ EMOTICONS = {
2
+ ":)": 2.0,
3
+ ":-)": 2.0,
4
+ ":D": 3.0,
5
+ ":-D": 3.0,
6
+ ":P": 1.5,
7
+ ":-P": 1.5,
8
+ ";)": 1.5,
9
+ ";-)": 1.5,
10
+
11
+ ":(": -2.0,
12
+ ":-(": -2.0,
13
+ ":'(": -3.0,
14
+ }
15
+
16
+ def find_emoticons(text):
17
+ """
18
+ Find standalone emoticons present in the text.
19
+
20
+ Returns:
21
+ list: A list of (emoticon, score) tuples.
22
+ """
23
+ found = []
24
+
25
+ words = text.split()
26
+
27
+ for word in words:
28
+ cleaned = word.strip(".,!?")
29
+
30
+ if cleaned in EMOTICONS:
31
+ found.append((cleaned, EMOTICONS[cleaned]))
32
+
33
+ return found
@@ -0,0 +1,22 @@
1
+ import re
2
+
3
+
4
+ def get_emphasis(text):
5
+ emphasis = 1.0
6
+
7
+ # Check for ALL CAPS words
8
+ words = text.split()
9
+
10
+ for word in words:
11
+ clean_word = re.sub(r"[^\w]", "", word)
12
+
13
+ if clean_word.isupper() and len(clean_word) > 1:
14
+ emphasis *= 1.5
15
+
16
+ # Check for exclamation marks
17
+ exclamation_count = text.count("!")
18
+
19
+ if exclamation_count > 0:
20
+ emphasis *= 1 + (0.1 * min(exclamation_count, 3))
21
+
22
+ return emphasis
@@ -0,0 +1,25 @@
1
+ LEXICON = {
2
+ # Positive
3
+ "good": 1.5,
4
+ "great": 2.5,
5
+ "amazing": 3.0,
6
+ "excellent": 3.0,
7
+ "awesome": 2.8,
8
+ "love": 3.0,
9
+ "like": 1.5,
10
+ "happy": 2.5,
11
+ "wonderful": 3.0,
12
+ "perfect": 3.0,
13
+
14
+ # Negative
15
+ "bad": -1.5,
16
+ "terrible": -3.0,
17
+ "awful": -2.5,
18
+ "horrible": -3.0,
19
+ "hate": -3.0,
20
+ "dislike": -1.5,
21
+ "sad": -2.0,
22
+ "angry": -2.5,
23
+ "worst": -3.0,
24
+ "poor": -1.5,
25
+ }
@@ -0,0 +1,9 @@
1
+ INTENSIFIERS = {
2
+ "very": 1.5,
3
+ "really": 1.4,
4
+ "extremely": 1.8,
5
+ "so": 1.3,
6
+ "too": 1.3,
7
+ "absolutely": 1.7,
8
+ "incredibly": 1.7,
9
+ }
@@ -0,0 +1,17 @@
1
+ NEGATIONS = {
2
+ "not",
3
+ "no",
4
+ "never",
5
+ "don't",
6
+ "doesn't",
7
+ "didn't",
8
+ "isn't",
9
+ "wasn't",
10
+ "aren't",
11
+ "weren't",
12
+ "can't",
13
+ "couldn't",
14
+ "won't",
15
+ "wouldn't",
16
+ "shouldn't",
17
+ }
@@ -0,0 +1,73 @@
1
+ from .lexicon import LEXICON
2
+ from .tokenizer import tokenize
3
+ from .negation import NEGATIONS
4
+ from .modifiers import INTENSIFIERS
5
+ from .emphasis import get_emphasis
6
+ from .emoji import get_emoji_score
7
+ from .emoticon import find_emoticons
8
+ from .context import detect_context
9
+
10
+
11
+ def sentiment(text):
12
+ score = 0.0
13
+ words = tokenize(text)
14
+
15
+ negation = False
16
+ multiplier = 1.0
17
+ emphasis = get_emphasis(text)
18
+
19
+ # Detect contextual sentiment
20
+ context_results = detect_context(text)
21
+
22
+ for word in words:
23
+
24
+ # Check for negation
25
+ if word in NEGATIONS:
26
+ negation = True
27
+ continue
28
+
29
+ # Check for intensifier
30
+ if word in INTENSIFIERS:
31
+ multiplier = INTENSIFIERS[word]
32
+ continue
33
+
34
+ # Check for sentiment word
35
+ if word in LEXICON:
36
+ word_score = LEXICON[word]
37
+
38
+ # Apply intensifier
39
+ word_score *= multiplier
40
+
41
+ # Apply emphasis
42
+ word_score *= emphasis
43
+
44
+ # Apply negation
45
+ if negation:
46
+ word_score = -word_score
47
+ negation = False
48
+
49
+ score += word_score
50
+
51
+ # Reset multiplier
52
+ multiplier = 1.0
53
+
54
+ # Apply contextual sentiment
55
+ for _, context_sentiment in context_results:
56
+ if context_sentiment == "positive":
57
+ score += 3.0
58
+ elif context_sentiment == "negative":
59
+ score -= 3.0
60
+
61
+ # Add emoji sentiment
62
+ score += get_emoji_score(text)
63
+
64
+ # Add emoticon sentiment
65
+ for _, emoticon_score in find_emoticons(text):
66
+ score += emoticon_score
67
+
68
+ if score > 0:
69
+ return "Positive"
70
+ elif score < 0:
71
+ return "Negative"
72
+ else:
73
+ return "Neutral"
@@ -0,0 +1,7 @@
1
+ import re
2
+
3
+
4
+ def tokenize(text):
5
+ text = text.lower()
6
+ words = re.findall(r"\b[\w']+\b", text)
7
+ return words
@@ -0,0 +1,37 @@
1
+ Metadata-Version: 2.4
2
+ Name: my-sentiment
3
+ Version: 0.1.0
4
+ Summary: A modular Python sentiment analysis library
5
+ Author: Mohammed Sinan K
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/markdown
8
+ Dynamic: author
9
+ Dynamic: description
10
+ Dynamic: description-content-type
11
+ Dynamic: requires-python
12
+ Dynamic: summary
13
+
14
+ # My Sentiment
15
+
16
+ A modular Python sentiment analysis library that analyzes text using
17
+ lexicon-based sentiment scoring, negation, modifiers, emphasis,
18
+ emojis, emoticons, and contextual expressions.
19
+
20
+ ## Features
21
+
22
+ - Lexicon-based sentiment analysis
23
+ - Tokenization
24
+ - Negation handling
25
+ - Intensifiers and modifiers
26
+ - Capitalization emphasis
27
+ - Punctuation emphasis
28
+ - Emoji sentiment
29
+ - Emoticon sentiment
30
+ - Context-aware sentiment
31
+ - Modular architecture
32
+ - Automated testing with pytest
33
+
34
+ ## Installation
35
+
36
+ `bash
37
+ pip install my-sentiment
@@ -0,0 +1,18 @@
1
+ README.md
2
+ pyproject.toml
3
+ setup.py
4
+ my_sentiment/__init__.py
5
+ my_sentiment/context.py
6
+ my_sentiment/emoji.py
7
+ my_sentiment/emoticon.py
8
+ my_sentiment/emphasis.py
9
+ my_sentiment/lexicon.py
10
+ my_sentiment/modifiers.py
11
+ my_sentiment/negation.py
12
+ my_sentiment/sentiment.py
13
+ my_sentiment/tokenizer.py
14
+ my_sentiment.egg-info/PKG-INFO
15
+ my_sentiment.egg-info/SOURCES.txt
16
+ my_sentiment.egg-info/dependency_links.txt
17
+ my_sentiment.egg-info/top_level.txt
18
+ tests/test_sentiment.py
@@ -0,0 +1 @@
1
+ my_sentiment
@@ -0,0 +1,3 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,17 @@
1
+ from setuptools import setup, find_packages
2
+
3
+
4
+ with open("README.md", "r", encoding="utf-8") as fh:
5
+ long_description = fh.read()
6
+
7
+
8
+ setup(
9
+ name="my-sentiment",
10
+ version="0.1.0",
11
+ description="A modular Python sentiment analysis library",
12
+ long_description=long_description,
13
+ long_description_content_type="text/markdown",
14
+ author="Mohammed Sinan K",
15
+ packages=find_packages(),
16
+ python_requires=">=3.8",
17
+ )
@@ -0,0 +1,160 @@
1
+ import pytest
2
+
3
+ from my_sentiment.sentiment import sentiment
4
+ from my_sentiment.tokenizer import tokenize
5
+ from my_sentiment.context import detect_context
6
+
7
+
8
+ @pytest.mark.parametrize(
9
+ "text, expected",
10
+ [
11
+ # Basic sentiment
12
+ ("I love this", "Positive"),
13
+ ("I hate this", "Negative"),
14
+ ("This is okay", "Neutral"),
15
+
16
+ # Multiple sentiment words
17
+ ("I love this, it is amazing and great", "Positive"),
18
+ ("I hate this, it is terrible and awful", "Negative"),
19
+
20
+ # Empty and single words
21
+ ("", "Neutral"),
22
+ ("love", "Positive"),
23
+ ("hate", "Negative"),
24
+
25
+ # Negation
26
+ ("I do not love this", "Negative"),
27
+ ("I do not hate this", "Positive"),
28
+ ("This is not good", "Negative"),
29
+ ("This is not bad", "Positive"),
30
+
31
+ # Intensifiers / modifiers
32
+ ("I really love this", "Positive"),
33
+ ("I very much love this", "Positive"),
34
+ ("I barely love this", "Positive"),
35
+ ("I slightly hate this", "Negative"),
36
+
37
+ # Capitalization
38
+ ("I LOVE this", "Positive"),
39
+ ("I HATE this", "Negative"),
40
+
41
+ # Punctuation / emphasis
42
+ ("I love this!", "Positive"),
43
+ ("I hate this!", "Negative"),
44
+ ("I love this!!!", "Positive"),
45
+ ("I hate this!!!", "Negative"),
46
+
47
+ # Emojis
48
+ ("I love this 😊", "Positive"),
49
+ ("I hate this 😢", "Negative"),
50
+ ("😊", "Positive"),
51
+ ("😢", "Negative"),
52
+ ],
53
+ )
54
+ def test_sentiment(text, expected):
55
+ assert sentiment(text) == expected
56
+
57
+
58
+ def test_tokenizer():
59
+ assert tokenize("This is amazing!") == ["this", "is", "amazing"]
60
+ assert tokenize("I LOVE this!!!") == ["i", "love", "this"]
61
+
62
+
63
+ # -------------------------
64
+ # Emoticon tests
65
+ # -------------------------
66
+
67
+ def test_positive_emoticon():
68
+ assert sentiment("I love this :)") == "Positive"
69
+
70
+
71
+ def test_negative_emoticon():
72
+ assert sentiment("I hate this :(") == "Negative"
73
+
74
+
75
+ def test_strong_positive_emoticon():
76
+ assert sentiment("This is great :D") == "Positive"
77
+
78
+
79
+ def test_strong_negative_emoticon():
80
+ assert sentiment("This is terrible :'(") == "Negative"
81
+
82
+
83
+ def test_repeated_positive_emoticons():
84
+ assert sentiment(":) :) :)") == "Positive"
85
+
86
+
87
+ def test_emoticon_with_punctuation():
88
+ assert sentiment("I love this :)!") == "Positive"
89
+
90
+
91
+ def test_emoticon_attached_to_word():
92
+ assert sentiment("hello:)") == "Neutral"
93
+
94
+
95
+ def test_playful_emoticon():
96
+ assert sentiment("This is funny :P") == "Positive"
97
+
98
+
99
+ def test_playful_emoticon_with_dash():
100
+ assert sentiment("This is funny :-P") == "Positive"
101
+
102
+
103
+ # -------------------------
104
+ # Context detection tests
105
+ # -------------------------
106
+
107
+ def test_positive_context():
108
+ assert detect_context("The movie was sick") == [("sick", "positive")]
109
+
110
+
111
+ def test_negative_context():
112
+ assert detect_context("I feel sick") == [("sick", "negative")]
113
+
114
+
115
+ def test_negative_am_sick_context():
116
+ assert detect_context("I am sick") == [("sick", "negative")]
117
+
118
+
119
+ def test_no_context():
120
+ assert detect_context("I love this movie") == []
121
+
122
+
123
+ # -------------------------
124
+ # Context sentiment tests
125
+ # -------------------------
126
+
127
+ def test_context_positive_sick():
128
+ assert sentiment("The movie was sick") == "Positive"
129
+
130
+
131
+ def test_context_negative_sick():
132
+ assert sentiment("I feel sick") == "Negative"
133
+
134
+
135
+ # -------------------------
136
+ # New context tests
137
+ # -------------------------
138
+
139
+ def test_positive_insane_context():
140
+ assert sentiment("The movie was insane!") == "Positive"
141
+
142
+
143
+ def test_negative_insane_context():
144
+ assert sentiment("I feel insane") == "Negative"
145
+
146
+
147
+ def test_positive_crazy_context():
148
+ assert sentiment("That game was crazy!") == "Positive"
149
+
150
+
151
+ def test_negative_crazy_context():
152
+ assert sentiment("I feel crazy") == "Negative"
153
+
154
+
155
+ def test_positive_wicked_context():
156
+ assert sentiment("That movie was wicked!") == "Positive"
157
+
158
+
159
+ def test_negative_wicked_context():
160
+ assert sentiment("I feel wicked") == "Negative"