-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsentimentAnalysis.py
More file actions
57 lines (43 loc) · 1.8 KB
/
sentimentAnalysis.py
File metadata and controls
57 lines (43 loc) · 1.8 KB
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
import cohere
import requests
from dumby import token
co = cohere.Client(token)
from cohere.classify import Example
def sentimental(websiteUrl, websiteService):
review_data = requests.get(url="http://127.0.0.1:3000/?siteurl=" + websiteUrl)
data = (review_data.text).split('","')
negative = []
positive = []
neutral = []
examples=[
Example("The order came 5 days early", "positive"),
Example("The item exceeded my expectations", "positive"),
Example("I ordered more for my friends", "positive"),
Example("I would buy this again", "positive"),
Example("I would recommend this to others", "positive"),
Example("Nothing beats this.", "positive"),
Example("Superb quality", "positive"),
Example("The order was incorrect", "negative"),
Example("I want to return my item", "negative"),
Example("The item\'s material feels low quality", "negative"),
Example("The product was okay", "neutral"),
Example("I received five items in total", "neutral"),
Example("I bought it from the website", "neutral"),
Example("I used the product this morning", "neutral"),
Example("The product arrived yesterday", "neutral")
]
for i in range(0,len(data)):
review = data[i]
review = [review]
response = co.classify(model='large', inputs=review, examples=examples,)
if response.classifications[0].prediction == 'negative':
negative.append(review)
elif response.classifications[0].prediction == 'positive':
positive.append(review)
else:
neutral.append(review)
print(negative, positive, neutral)
print(len(negative), len(positive), len(neutral))
values = [len(negative), len(positive), len(neutral)]
return_values = []
return values