Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from textblob import TextBlob
- def calculatesentiment(text):
- """
- Calculate polarity and subjectivity
- Input:
- text - text for which polarity and subjectivity needs to be calculated
- Output:
- (polarity, subjectivity)
- """
- blob = TextBlob(text)
- if blob.detect_language() != 'en':
- try:
- blob = blob.translate(to="en")
- except:
- print("Translation error:",blob.detect_language())
- print(blob)
- blob.correct()
- return (float(blob.sentiment.polarity),
- float(blob.sentiment.subjectivity))
Add Comment
Please, Sign In to add comment