File size: 1,567 Bytes
c8f1eb5
 
 
 
 
 
 
 
 
5359fa5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
003b4e0
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
---
language:
- en
tags:
- nltk
- swntiment
- tone
- nlp
---
import nltk
from nltk.sentiment import SentimentIntensityAnalyzer

# Download NLTK resources (only need to run once)
nltk.download('vader_lexicon')

# Sample text for sentiment analysis
with open("lks.txt", 'r') as file:
            fl = file.read()
        
contactId = fl.split("|")[0]
transcript=fl.split("|")[1]
transcript=transcript.replace("'",'')
# Initialize the sentiment analyzer
sia = SentimentIntensityAnalyzer()
print(transcript)

# Analyze sentiment
sentiment_score = sia.polarity_scores(transcript)

# Initialize dictionary to store tone counts
tones = {
    'analytical': 0,
    'anger': 0,
    'confident': 0,
    'fear': 0,
    'joy': 0,
    'sadness': 0,
    'tentative': 0
}

# Apply thresholds and count tones
if sentiment_score['compound'] >= 0.05:  # Threshold for positive sentiment
    tones['joy'] += 1
elif sentiment_score['compound'] <= -0.05:  # Threshold for negative sentiment
    tones['anger'] += 1
elif sentiment_score['neg'] >= 0.5:  # Threshold for high negativity
    tones['sadness'] += 1
elif sentiment_score['pos'] <= 0.2:  # Threshold for low positivity
    tones['fear'] += 1
elif sentiment_score['neu'] >= 0.5:  # Threshold for high neutrality
    tones['tentative'] += 1
else:  # Otherwise, consider it analytical or confident
    tones['analytical'] += 1
    tones['confident'] += 1

# Print tone counts
print("Tone Counts:", tones)


# sample output
#Tone Counts: {'analytical': 0, 'anger': 0, 'confident': 0, 'fear': 0, 'joy': 1, 'sadness': 0, 'tentative': 0}