Toggle navigation
Toggle navigation
This project
Loading...
Sign in
박은주
/
Todays_Issue
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
박은주
2021-06-08 23:04:40 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
878bc54f0a74ba9d99890d3f3bf3e3d172ef55dc
878bc54f
1 parent
75217c16
Clearance
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
11 deletions
SentimentAnalyzer.py
SentimentAnalyzer.py
View file @
878bc54
import
argparse
import
os
from
google.cloud
import
language_v1
def
print_result
(
annotations
):
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
os
.
environ
[
"GOOGLE_APPLICATION_CREDENTIALS"
]
=
BASE_DIR
+
"/artful-fortress-316201-f135fd520d56.json"
def
GetResult
(
annotations
):
score
=
annotations
.
document_sentiment
.
score
magnitude
=
annotations
.
document_sentiment
.
magnitude
...
...
@@ -18,14 +22,8 @@ def print_result(annotations):
negative
+=
1
else
:
neutral
+=
1
# print(
# "Sentence {} has a sentiment score of {}".format(index, sentence_sentiment)
# )
tot
+=
1
print
(
"Overall Sentiment: score of {} with magnitude of {}"
.
format
(
score
,
magnitude
)
)
return
tot
,
positive
,
negative
return
tot
,
positive
,
neutral
,
negative
def
analyze
(
movie_review_filename
):
client
=
language_v1
.
LanguageServiceClient
()
...
...
@@ -36,7 +34,7 @@ def analyze(movie_review_filename):
document
=
language_v1
.
Document
(
content
=
content
,
type_
=
language_v1
.
Document
.
Type
.
PLAIN_TEXT
)
annotations
=
client
.
analyze_sentiment
(
request
=
{
'document'
:
document
})
print_r
esult
(
annotations
)
return
GetR
esult
(
annotations
)
if
__name__
==
"__main__"
:
analyze
(
"data.txt"
)
\ No newline at end of file
def
StartSentimentAnalysis
():
return
analyze
(
"data.txt"
)
\ No newline at end of file
...
...
Please
register
or
login
to post a comment