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:21:05 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f9a1a756414858937fec575072ee6fe58279dca6
f9a1a756
1 parent
00f0e7fc
Clearance
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
8 deletions
SentimentAnalyzer.py
SentimentAnalyzer.py
View file @
f9a1a75
...
...
@@ -27,14 +27,16 @@ def GetResult(annotations):
def
analyze
(
movie_review_filename
):
client
=
language_v1
.
LanguageServiceClient
()
with
open
(
movie_review_filename
,
"r"
,
encoding
=
'utf-8-sig'
)
as
review_file
:
# Instantiates a plain text document.
content
=
review_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
)
try
:
with
open
(
movie_review_filename
,
"r"
,
encoding
=
'utf-8-sig'
)
as
review_file
:
# Instantiates a plain text document.
content
=
review_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
def
StartSentimentAnalysis
():
return
analyze
(
"data.txt"
)
\ No newline at end of file
...
...
Please
register
or
login
to post a comment