Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
Lab2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
davyji2
Lab2
Commits
3086d56e
Commit
3086d56e
authored
3 years ago
by
davegii
Browse files
Options
Downloads
Patches
Plain Diff
finished analysis
parent
c1341314
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
__pycache__/analysis.cpython-38.pyc
+0
-0
0 additions, 0 deletions
__pycache__/analysis.cpython-38.pyc
analysis.py
+21
-21
21 additions, 21 deletions
analysis.py
twitter.py
+14
-4
14 additions, 4 deletions
twitter.py
with
35 additions
and
25 deletions
__pycache__/analysis.cpython-38.pyc
0 → 100644
+
0
−
0
View file @
3086d56e
File added
This diff is collapsed.
Click to expand it.
analysis.py
+
21
−
21
View file @
3086d56e
...
...
@@ -23,7 +23,7 @@ def overall_sentiment(text):
if
percent_sentiment
[
'
pos
'
]
<
0.1
:
if
percent_sentiment
[
'
pos
'
]
-
percent_sentiment
[
'
neg
'
]
<=
0
or
percent_sentiment
[
'
compound
'
]
<=
-
0.5
:
# The "=" makes it better
print
(
"
Sentence overall rated as
posi
tive
"
)
print
(
"
Sentence overall rated as
nega
tive
"
)
print
(
"
\n
"
)
#print("Negative")
return
"
Negative
"
...
...
@@ -36,27 +36,27 @@ def overall_sentiment(text):
pos_count
=
0
pos_correct
=
0
#
pos_count = 0
#
pos_correct = 0
file_positive
=
open
(
"
positive.txt
"
,
"
r
"
)
file_positive_lines
=
file_positive
.
readlines
()
for
line
in
file_positive_lines
:
sentiment
=
overall_sentiment
(
line
)
if
sentiment
==
"
Positive
"
:
pos_correct
+=
1
pos_count
+=
1
#
file_positive = open("positive.txt","r")
#
file_positive_lines = file_positive.readlines()
#
for line in file_positive_lines:
#
sentiment = overall_sentiment(line)
#
if sentiment == "Positive":
#
pos_correct += 1
#
pos_count += 1
neg_count
=
0
neg_correct
=
0
#
neg_count = 0
#
neg_correct = 0
file_negative
=
open
(
"
negative.txt
"
,
"
r
"
)
file_negative_lines
=
file_negative
.
readlines
()
for
line
in
file_negative_lines
:
sentiment
=
overall_sentiment
(
line
)
if
sentiment
==
"
Negative
"
:
neg_correct
+=
1
neg_count
+=
1
#
file_negative = open("negative.txt","r")
#
file_negative_lines = file_negative.readlines()
#
for line in file_negative_lines:
#
sentiment = overall_sentiment(line)
#
if sentiment == "Negative":
#
neg_correct += 1
#
neg_count += 1
print
(
"
Positive accuracy using vader= {}% via {} samples
"
.
format
(
pos_correct
/
pos_count
*
100.0
,
pos_count
))
print
(
"
Negative accuracy using vader= {}% via {} samples
"
.
format
(
neg_correct
/
neg_count
*
100.0
,
neg_count
))
#
print("Positive accuracy using vader= {}% via {} samples".format(pos_correct/pos_count*100.0, pos_count))
#
print("Negative accuracy using vader= {}% via {} samples".format(neg_correct/neg_count*100.0, neg_count))
This diff is collapsed.
Click to expand it.
twitter.py
+
14
−
4
View file @
3086d56e
...
...
@@ -7,9 +7,17 @@ import csv
import
re
import
string
import
preprocessor
as
p
import
analysis
import
emoji
# Remove Emojis
def
give_emoji_free_text
(
text
):
allchars
=
[
str
for
str
in
text
]
emoji_list
=
[
c
for
c
in
allchars
if
c
in
emoji
.
UNICODE_EMOJI
]
clean_text
=
'
'
.
join
([
str
for
str
in
text
.
split
()
if
not
any
(
i
in
str
for
i
in
emoji_list
)])
return
clean_text
auth
=
tweepy
.
OAuthHandler
(
consumer_key
,
consumer_secret
)
auth
.
set_access_token
(
access_key
,
access_secret
)
...
...
@@ -19,8 +27,10 @@ api = tweepy.API(auth,wait_on_rate_limit=True)
search_words
=
"
#wildfires
"
# enter your words
new_search
=
search_words
+
"
-filter:retweets
"
for
tweets
in
api
.
search_tweets
(
q
=
"
iphone
"
,
lang
=
"
en
"
,
count
=
100
,
since_id
=
0
):
print
(
tweets
.
text
.
encode
(
'
utf-8
'
))
for
tweets
in
api
.
search_tweets
(
q
=
new_search
,
lang
=
"
en
"
,
count
=
100
,
since_id
=
0
):
print
(
tweets
.
text
)
text
=
give_emoji_free_text
(
text
=
tweets
.
text
)
analysis
.
overall_sentiment
(
text
)
# #for tweet in tweepy.Cursor(api.search_tweets,q=new_search,count=100,
# lang="en",
# since_id=0).items():
...
...
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