-
Notifications
You must be signed in to change notification settings - Fork 0
/
natLang.py
30 lines (27 loc) · 854 Bytes
/
natLang.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
28
29
30
from google.cloud import language
from google.cloud.language import enums
from google.cloud.language import types
import sys
def language_analysis(text):
client = language.LanguageServiceClient()
document = types.Document(content=text, type=enums.Document.Type.PLAIN_TEXT)
sent_analysis = client.analyze_sentiment(document=document).document_sentiment
#print(dir(sent_analysis))
#sentiment = sent_analysis.sentiment
#print(sentiment)
return sent_analysis
example_text = "Suicide is an unfortunate thing"
ex = ""
print(sys)
example_text1 = example_text.split(" ")
sent = 0
average = 0
for i in example_text1:
sent = language_analysis(i)
if sent.score < 0.5:
ex += i + " "
print(ex)
senti = language_analysis(ex.lower())
sentiment = language_analysis(example_text)
print(sentiment.score)
print(senti.score)