박은주

Add TXT output func

......@@ -23,20 +23,27 @@ def GetResult(annotations):
else:
neutral += 1
tot += 1
return tot, positive, neutral, negative
def analyze(movie_review_filename):
with open(BASE_DIR + 'sentiment.txt', 'w', encoding='utf-8-sig') as txt_file:
txt_file.write(str(tot))
txt_file.write(str(int(positive / tot * 100)))
txt_file.write(str(int(neutral / tot * 100)))
txt_file.write(str(int(negative / tot * 100)))
print("txt file saved")
# return tot, positive, neutral, negative
def analyze(filename):
client = language_v1.LanguageServiceClient()
try:
with open(movie_review_filename, "r", encoding='utf-8-sig') as review_file:
# try:
with open(filename, "r", encoding='utf-8-sig') as file:
# Instantiates a plain text document.
content = review_file.read()
content = file.read()
document = language_v1.Document(content=content, type_=language_v1.Document.Type.PLAIN_TEXT)
annotations = client.analyze_sentiment(request={'document': document})
return GetResult(annotations)
except:
return 0, 0, 0, 0
GetResult(annotations)
# except:
# return 0, 0, 0, 0
def StartSentimentAnalysis():
return analyze("data.txt")
\ No newline at end of file
analyze("data.txt")
\ No newline at end of file
......