kishanj97 commited on
Commit
5359fa5
·
verified ·
1 Parent(s): 1c7c662

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +48 -0
README.md ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import nltk
2
+ from nltk.sentiment import SentimentIntensityAnalyzer
3
+
4
+ # Download NLTK resources (only need to run once)
5
+ nltk.download('vader_lexicon')
6
+
7
+ # Sample text for sentiment analysis
8
+ with open("lks.txt", 'r') as file:
9
+ fl = file.read()
10
+
11
+ contactId = fl.split("|")[0]
12
+ transcript=fl.split("|")[1]
13
+ transcript=transcript.replace("'",'')
14
+ # Initialize the sentiment analyzer
15
+ sia = SentimentIntensityAnalyzer()
16
+ print(transcript)
17
+
18
+ # Analyze sentiment
19
+ sentiment_score = sia.polarity_scores(transcript)
20
+
21
+ # Initialize dictionary to store tone counts
22
+ tones = {
23
+ 'analytical': 0,
24
+ 'anger': 0,
25
+ 'confident': 0,
26
+ 'fear': 0,
27
+ 'joy': 0,
28
+ 'sadness': 0,
29
+ 'tentative': 0
30
+ }
31
+
32
+ # Apply thresholds and count tones
33
+ if sentiment_score['compound'] >= 0.05: # Threshold for positive sentiment
34
+ tones['joy'] += 1
35
+ elif sentiment_score['compound'] <= -0.05: # Threshold for negative sentiment
36
+ tones['anger'] += 1
37
+ elif sentiment_score['neg'] >= 0.5: # Threshold for high negativity
38
+ tones['sadness'] += 1
39
+ elif sentiment_score['pos'] <= 0.2: # Threshold for low positivity
40
+ tones['fear'] += 1
41
+ elif sentiment_score['neu'] >= 0.5: # Threshold for high neutrality
42
+ tones['tentative'] += 1
43
+ else: # Otherwise, consider it analytical or confident
44
+ tones['analytical'] += 1
45
+ tones['confident'] += 1
46
+
47
+ # Print tone counts
48
+ print("Tone Counts:", tones)