Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sentiment
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Adrian Reza Ariffin
sentiment
Commits
f6b348da
Commit
f6b348da
authored
8 years ago
by
Adrian Reza Ariffin
Browse files
Options
Downloads
Patches
Plain Diff
Final program finished
parent
48ae8dcd
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
TEST.py
+59
-3
59 additions, 3 deletions
TEST.py
negative.txt
+7
-0
7 additions, 0 deletions
negative.txt
positive.txt
+5
-0
5 additions, 0 deletions
positive.txt
sentiment.py
+21
-16
21 additions, 16 deletions
sentiment.py
with
92 additions
and
19 deletions
TEST.py
+
59
−
3
View file @
f6b348da
...
...
@@ -26,9 +26,65 @@ class TestPreloading(TestCase):
except
IOError
:
print
(
"
File Not Found
"
)
review
=
sentiment
.
preloading
(
raw_file
)
average
=
0
number
=
0
average
,
number
=
sentiment
.
option1
(
review
,
'
arty
'
)
self
.
assertEquals
(
number
,
4
)
def
test_number_20
(
self
):
try
:
with
open
(
"
sentiment.txt
"
)
as
file
:
loading
=
file
.
read
()
raw_file
=
loading
.
split
(
'
\n
'
)
except
IOError
:
print
(
"
File Not Found
"
)
review
=
sentiment
.
preloading
(
raw_file
)
average
=
0
number
=
0
average
,
number
=
sentiment
.
option1
(
review
,
'
scramble
'
)
self
.
assertEquals
(
average
,
None
)
def
test_number_22
(
self
):
try
:
with
open
(
"
sentiment.txt
"
)
as
file
:
loading
=
file
.
read
()
raw_file
=
loading
.
split
(
'
\n
'
)
except
IOError
:
print
(
"
File Not Found
"
)
review
=
sentiment
.
preloading
(
raw_file
)
average
=
0
number
=
0
average
,
number
=
sentiment
.
option1
(
raw_file
,
'
arty
'
)
print
(
number
)
self
.
assertEquals
(
number
,
'
None
'
)
positive_word
=
"
The most positive word is
\"
None
\"
with a score of None
\n
The most negative word is
\"
None
\"
with a score of None
"
filename
=
'
positive.txt
'
print
(
positive_word
)
print
(
"
here
"
)
self
.
assertEquals
((
sentiment
.
file_score
(
review
,
filename
)),(
positive_word
))
def
test_number_24
(
self
):
# examples.txt has a word called scramble that does not exist in the dictionary and should not be in any
# of the files
try
:
with
open
(
"
sentiment.txt
"
)
as
file
:
loading
=
file
.
read
()
raw_file
=
loading
.
split
(
'
\n
'
)
except
IOError
:
print
(
"
File Not Found
"
)
review
=
sentiment
.
preloading
(
raw_file
)
filename
=
'
examples.txt
'
positive
,
negative
=
sentiment
.
word_sorting
(
review
,
filename
)
positive2
=
[
'
has
'
,
'
a
'
,
'
very
'
,
'
and
'
,
'
refreshing
'
]
negative2
=
[
'
This
'
,
'
movie
'
,
'
bad
'
,
'
plot
'
,
'
terrible
'
,
'
ending
'
,
'
horrible
'
]
self
.
assertEquals
((
positive
,
negative
),(
positive2
,
negative2
))
This diff is collapsed.
Click to expand it.
negative.txt
0 → 100644
+
7
−
0
View file @
f6b348da
This
movie
bad
plot
terrible
ending
horrible
\ No newline at end of file
This diff is collapsed.
Click to expand it.
positive.txt
0 → 100644
+
5
−
0
View file @
f6b348da
has
a
very
and
refreshing
\ No newline at end of file
This diff is collapsed.
Click to expand it.
sentiment.py
+
21
−
16
View file @
f6b348da
...
...
@@ -23,11 +23,14 @@ def main():
average
,
number
=
option1
(
review
,
key
)
print
(
"
\n
Score of
\"
"
,
key
,
"
\"
appears
"
,
number
,
"
times with an average sentiment of
"
,
average
,
"
\n
"
)
elif
choice
is
2
:
average_score
(
review
)
file_name
=
input
(
"
Enter file name :
\n
"
)
average_score
(
review
,
file_name
)
elif
choice
is
3
:
file_score
(
review
)
file_name
=
input
(
"
Enter file name :
\n
"
)
file_score
(
review
,
file_name
)
elif
choice
is
4
:
word_sorting
(
review
)
file_name
=
input
(
"
Enter file name :
\n
"
)
word_sorting
(
review
,
file_name
)
elif
choice
is
5
:
print
(
"
Goodbye!
"
)
break
...
...
@@ -95,8 +98,7 @@ def score_of_word(review,key):
else
:
return
None
def
average_score
(
review
):
file_name
=
input
(
"
Enter file name :
\n
"
)
def
average_score
(
review
,
file_name
):
try
:
with
open
(
file_name
)
as
file
:
loading
=
file
.
read
()
...
...
@@ -122,8 +124,8 @@ def average_score(review):
print
(
"
The overall sentiment of
"
,
file_name
,
"
is positive.
\n
"
)
def
file_score
(
review
):
file_name
=
input
(
"
Enter file name :
\n
"
)
def
file_score
(
review
,
file_name
):
try
:
with
open
(
file_name
)
as
file
:
loading
=
file
.
read
()
...
...
@@ -143,10 +145,15 @@ def file_score(review):
key
=
result
[
number
]
average
=
score_of_word
(
review
,
key
)
number
+=
1
if
(
average
<
min
):
if
average
is
None
:
max_word
=
None
min_word
=
None
min
=
None
max
=
None
elif
(
average
<
min
):
min
=
average
min_word
=
key
if
(
average
>
max
):
el
if
(
average
>
max
):
max
=
average
max_word
=
key
...
...
@@ -154,8 +161,7 @@ def file_score(review):
print
(
"
The most negative word is
\"
"
,
min_word
,
"
\"
with a score of
"
,
min
)
def
word_sorting
(
review
):
file_name
=
input
(
"
Enter file name :
\n
"
)
def
word_sorting
(
review
,
file_name
):
try
:
with
open
(
file_name
)
as
file
:
loading
=
file
.
read
()
...
...
@@ -181,8 +187,7 @@ def word_sorting(review):
number
+=
1
print
(
positive
)
print
(
negative
)
with
open
(
'
positive.txt
'
,
'
w
'
)
as
file
:
positives
=
'
\n
'
.
join
(
positive
)
...
...
@@ -193,7 +198,7 @@ def word_sorting(review):
file
.
write
(
negatives
)
return
positive
,
negative
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment