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-09 13:30:04 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
5c8faef459fbd9822ec843edb2965364953e9d1b
5c8faef4
1 parent
f1af6d40
Add TXT output func
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
12 deletions
SentimentAnalyzer.py
SentimentAnalyzer.py
View file @
5c8faef
...
...
@@ -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
:
# 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
})
#
try:
with
open
(
filename
,
"r"
,
encoding
=
'utf-8-sig'
)
as
file
:
# Instantiates a plain text document.
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
...
...
Please
register
or
login
to post a comment