-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogic.py
27 lines (22 loc) · 823 Bytes
/
logic.py
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
# text analytics libraries
from textblob import TextBlob
import nltk
import transformers
import json
# Returns sentiment of text input as object
def getSentiment(getSentimenttext):
return TextBlob(getSentimenttext).sentiment
def getSentimentScore(getSentimenttext):
return TextBlob(getSentimenttext).sentiment[0]
def getEntities(getEntitiestext):
return TextBlob(getEntitiestext).tags
def getNouns(getNounstext):
return TextBlob(getNounstext).noun_phrases
def getCompound(getCompoundtext):
compounded = {}
compounded['Sentiment'] = str(getSentiment(getCompoundtext))
compounded['SentimentScore'] = str(getSentimentScore(getCompoundtext))
compounded['Entities'] = str(getEntities(getCompoundtext))
compounded['Nouns'] = str(getNouns(getCompoundtext))
compounded = json.dumps(compounded)
return compounded