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
45063937
Commit
45063937
authored
8 years ago
by
Sam Neupane
Browse files
Options
Downloads
Patches
Plain Diff
hw
parent
7e3eca38
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Test.py
+10
-0
10 additions, 0 deletions
Test.py
sentiment.py
+37
-63
37 additions, 63 deletions
sentiment.py
test_method_11.py
+6
-0
6 additions, 0 deletions
test_method_11.py
with
53 additions
and
63 deletions
Test.py
0 → 100644
+
10
−
0
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
+
37
−
63
View file @
45063937
...
@@ -4,28 +4,19 @@ from builtins import input
...
@@ -4,28 +4,19 @@ from builtins import input
def
main
():
def
main
():
average
=
list
()
reviews
=
list
()
reviews
=
list
()
try
:
try
:
with
open
(
'
sentiment.txt
'
)
as
s
:
with
open
(
'
sentiment.txt
'
)
as
s
:
reviews
=
list
(
s
)
reviews
=
list
(
s
)
print
(
len
(
reviews
))
#
print(len(reviews))
except
OSError
:
except
OSError
:
print
(
'
Does not exist
'
)
print
(
'
Does not exist
'
)
sentiments
=
{}
sentiments
=
{}
for
review
in
reviews
:
word
=
method_11
(
reviews
,
sentiments
)
words
=
review
.
split
()
#print(len(sentiments['arty']))
for
word
in
words
:
if
word
!=
review
[
0
]:
if
word
in
sentiments
.
keys
():
sentiments
[
word
].
append
(
int
(
review
[
0
]))
else
:
sentiments
[
word
]
=
list
()
sentiments
[
word
].
append
(
int
(
review
[
0
]))
print
(
sentiments
[
'
arty
'
])
print
(
len
(
sentiments
[
'
arty
'
]))
# x = input("Enter a word")
# x = input("Enter a word")
# if x in sentiments:
# if x in sentiments:
#
#
...
@@ -69,6 +60,7 @@ def main():
...
@@ -69,6 +60,7 @@ def main():
y
=
x
,
num
=
0
,
av
=
'
None
'
y
=
x
,
num
=
0
,
av
=
'
None
'
)
)
print
(
output
)
print
(
output
)
average
=
list
()
if
y
==
2
or
y
==
3
:
if
y
==
2
or
y
==
3
:
file
=
input
(
'
Enter a file
'
)
file
=
input
(
'
Enter a file
'
)
try
:
try
:
...
@@ -95,68 +87,50 @@ def main():
...
@@ -95,68 +87,50 @@ def main():
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
))
except
IOError
:
print
(
'
File could not be found
'
)
if
y
==
3
:
if
y
==
3
:
rating
=
sum
(
sentiments
[
x
])
/
len
(
sentiments
[
x
])
#rating = sum(sentiments[x])/len(sentiments[x])
split_file
=
file
.
split
()
#
highest_score
=
max
(
average
)
highest_score
=
max
(
average
)
lowest_score
=
min
(
average
)
lowest_score
=
min
(
average
)
p
=
average
.
append
(
sum_word
)
for
check_word
in
split_file
:
for
file_word
,
rate
in
rating
.
items
():
if
check_word
in
sentiments
:
if
rate
==
highest_score
:
method_11
(
check_word
)
j
=
file_word
sum_word
=
sum
(
method_11
(
check_word
))
/
len
(
method_11
(
check_word
))
if
rate
==
lowest_score
:
y
==
file_word
print
(
'
The most positive word is {phrase} with a score of {j}
'
.
format
(
phrase
=
j
,
j
=
highest_score
))
print
(
'
The most negative word is {phrase} with a score of {min}
'
.
format
(
phrase
=
y
,
min
=
lowest_score
))
for
file_word
,
rate
in
sum_word
.
items
():
if
rate
==
highest_score
:
j
=
file_word
if
rate
==
lowest_score
:
j
==
file_word
print
(
'
The most positive word is {phrase} with a score of {j}
'
.
format
(
phrase
=
j
,
j
=
highest_score
))
print
(
'
The most negative word is {phrase} with a score of {min}
'
.
format
(
phrase
=
j
,
min
=
lowest_score
))
except
IOError
:
print
(
'
File could not be found
'
)
def
method_11
(
reviews
,
sentiments
):
for
review
in
reviews
:
words
=
review
.
split
()
for
word
in
words
:
if
word
!=
review
[
0
]:
if
word
in
sentiments
:
sentiments
[
word
].
append
(
int
(
review
[
0
]))
else
:
sentiments
[
word
]
=
list
()
sentiments
[
word
].
append
(
int
(
review
[
0
]))
# print(sentiments['arty'])
return
word
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
...
...
This diff is collapsed.
Click to expand it.
test_method_11.py
0 → 100644
+
6
−
0
View file @
45063937
from
unittest
import
TestCase
class
TestMethod_11
(
TestCase
):
def
test_method_11
(
self
,
reviews
,
sentiments
):
self
.
assertEqual
([
'
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