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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sam Neupane
sentiment
Commits
767f8142
Commit
767f8142
authored
8 years ago
by
Sam Neupane
Browse files
Options
Downloads
Patches
Plain Diff
hw
parent
45063937
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Test.py
+0
-10
0 additions, 10 deletions
Test.py
sentiment.py
+34
-45
34 additions, 45 deletions
sentiment.py
test_method_11.py
+6
-2
6 additions, 2 deletions
test_method_11.py
with
40 additions
and
57 deletions
Test.py
deleted
100644 → 0
+
0
−
10
View file @
45063937
import
unittest
class
MyTestCase
(
unittest
.
TestCase
):
def
test_sentim
(
self
):
self
.
assertEqual
(
method_11
)
if
__name__
==
'
__main__
'
:
unittest
.
main
()
This diff is collapsed.
Click to expand it.
sentiment.py
+
34
−
45
View file @
767f8142
...
@@ -2,12 +2,9 @@ from __future__ import print_function, division
...
@@ -2,12 +2,9 @@ from __future__ import print_function, division
from
builtins
import
input
from
builtins
import
input
def
main
():
def
main
():
reviews
=
list
()
reviews
=
list
()
try
:
try
:
with
open
(
'
sentiment.txt
'
)
as
s
:
with
open
(
'
sentiment.txt
'
)
as
s
:
reviews
=
list
(
s
)
reviews
=
list
(
s
)
...
@@ -70,7 +67,6 @@ def main():
...
@@ -70,7 +67,6 @@ def main():
if
word_in_file
in
sentiments
.
keys
():
if
word_in_file
in
sentiments
.
keys
():
average
.
append
(
sum
(
sentiments
[
word
])
/
len
(
sentiments
[
word
]))
average
.
append
(
sum
(
sentiments
[
word
])
/
len
(
sentiments
[
word
]))
if
y
==
2
:
if
y
==
2
:
average
.
append
(
sum
(
sentiments
[
word_in_file
])
/
len
(
sentiments
[
word_in_file
]))
average
.
append
(
sum
(
sentiments
[
word_in_file
])
/
len
(
sentiments
[
word_in_file
]))
if
not
average
:
if
not
average
:
...
@@ -81,15 +77,13 @@ def main():
...
@@ -81,15 +77,13 @@ def main():
if
average_words
>=
2.01
:
if
average_words
>=
2.01
:
print
(
'
The average score of words in {y} is {av}
'
.
format
(
y
=
file
,
av
=
average_words
))
print
(
'
The average score of words in {y} is {av}
'
.
format
(
y
=
file
,
av
=
average_words
))
print
(
'
The overall sentiment of {y} is positive
'
.
format
(
y
=
file
))
print
(
'
The overall sentiment of {y} is positive
'
.
format
(
y
=
file
))
if
average_words
<=
1.99
:
el
if
average_words
<=
1.99
:
print
(
'
The average score of words in {y} is {av}
'
.
format
(
y
=
file
,
av
=
average_words
))
print
(
'
The average score of words in {y} is {av}
'
.
format
(
y
=
file
,
av
=
average_words
))
print
(
'
The overall sentiment of {y} is negative
'
.
format
(
y
=
file
))
print
(
'
The overall sentiment of {y} is negative
'
.
format
(
y
=
file
))
else
:
else
:
print
(
'
The average score of words in {y} is {av}
'
.
format
(
y
=
file
,
av
=
average_words
))
print
(
'
The average score of words in {y} is {av}
'
.
format
(
y
=
file
,
av
=
average_words
))
print
(
'
The overall sentiment of {y} is neutral
'
.
format
(
y
=
file
))
print
(
'
The overall sentiment of {y} is neutral
'
.
format
(
y
=
file
))
if
y
==
3
:
if
y
==
3
:
# rating = sum(sentiments[x])/len(sentiments[x])
# rating = sum(sentiments[x])/len(sentiments[x])
split_file
=
file
.
split
()
split_file
=
file
.
split
()
...
@@ -103,11 +97,6 @@ def main():
...
@@ -103,11 +97,6 @@ def main():
method_11
(
check_word
)
method_11
(
check_word
)
sum_word
=
sum
(
method_11
(
check_word
))
/
len
(
method_11
(
check_word
))
sum_word
=
sum
(
method_11
(
check_word
))
/
len
(
method_11
(
check_word
))
for
file_word
,
rate
in
sum_word
.
items
():
for
file_word
,
rate
in
sum_word
.
items
():
if
rate
==
highest_score
:
if
rate
==
highest_score
:
j
=
file_word
j
=
file_word
...
...
This diff is collapsed.
Click to expand it.
test_method_11.py
+
6
−
2
View file @
767f8142
from
unittest
import
TestCase
from
unittest
import
TestCase
from
sentiment
import
method_11
class
TestMethod_11
(
TestCase
):
class
TestMethod_11
(
TestCase
):
def
test_method_11
(
self
,
reviews
,
sentiments
):
def
test_method_11
(
self
):
self
.
assertEqual
([
'
arty
'
],
)
reviews
=
[
'
John
'
,
"
jack
"
]
sentiments
=
[
2
,
2
]
self
.
assertEqual
(
method_11
(
reviews
,
sentiments
)[
3
,
0
,
1
,
1
],
[
'
arty
'
])
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