|
import nltk |
|
from nltk.sentiment import SentimentIntensityAnalyzer |
|
|
|
|
|
nltk.download('vader_lexicon') |
|
|
|
with open("lks.txt", 'r') as file: |
|
fl = file.read() |
|
|
|
contactId = fl.split("|")[0] |
|
transcript=fl.split("|")[1] |
|
transcript=transcript.replace("'",'') |
|
|
|
sia = SentimentIntensityAnalyzer() |
|
print(transcript) |
|
|
|
sentiment_score = sia.polarity_scores(transcript) |
|
|
|
tones = { |
|
'analytical': 0, |
|
'anger': 0, |
|
'confident': 0, |
|
'fear': 0, |
|
'joy': 0, |
|
'sadness': 0, |
|
'tentative': 0 |
|
} |
|
|
|
if sentiment_score['compound'] >= 0.05: |
|
tones['joy'] += 1 |
|
elif sentiment_score['compound'] <= -0.05: |
|
tones['anger'] += 1 |
|
elif sentiment_score['neg'] >= 0.5: |
|
tones['sadness'] += 1 |
|
elif sentiment_score['pos'] <= 0.2: |
|
tones['fear'] += 1 |
|
elif sentiment_score['neu'] >= 0.5: |
|
tones['tentative'] += 1 |
|
else: |
|
tones['analytical'] += 1 |
|
tones['confident'] += 1 |
|
|
|
print("Tone Counts:", tones) |
|
|
|
|
|
|
|
|
|
|