Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nltk
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
nltk
Commits
d8d3e786
Commit
d8d3e786
authored
May 15, 2015
by
Ewan Klein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Partial fix for global variables in demo functions
parent
e0b0d97b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
4 deletions
+12
-4
nltk/twitter/twitter_demo.py
+12
-4
No files found.
nltk/twitter/twitter_demo.py
View file @
d8d3e786
...
@@ -54,16 +54,23 @@ def verbose(func):
...
@@ -54,16 +54,23 @@ def verbose(func):
def
setup
():
def
setup
():
global
TWEETS
,
DATE
,
USERIDS
global
TWEETS
,
DATE
,
USERIDS
,
IDS
,
FIELDS
from
nltk.corpus
import
tweets
from
nltk.corpus
import
tweets
TWEETS
=
tweets
.
docs
()[:
100
]
TWEETS
=
NamedTemporaryFile
(
mode
=
'w'
)
for
tweet
in
tweets
.
docs
()[:
100
]:
json
.
dump
(
tweet
,
TWEETS
)
DATE
=
(
2015
,
4
,
20
,
16
,
40
)
DATE
=
(
2015
,
4
,
20
,
16
,
40
)
USERIDS
=
[
'759251'
,
'612473'
,
'15108702'
,
'6017542'
,
'2673523800'
]
# UserIDs corresponding to\
USERIDS
=
[
'759251'
,
'612473'
,
'15108702'
,
'6017542'
,
'2673523800'
]
# UserIDs corresponding to\
# @CNN, @BBCNews, @ReutersLive, @BreakingNews, @AJELive
# @CNN, @BBCNews, @ReutersLive, @BreakingNews, @AJELive
IDS
=
NamedTemporaryFile
(
mode
=
'w'
,
delete
=
False
)
IDS
=
NamedTemporaryFile
(
mode
=
'w'
)
FIELDS
=
[
'id_str'
]
pass
def
teardown
():
def
teardown
():
IDS
.
close
()
IDS
.
close
()
TWEETS
.
close
()
@verbose
@verbose
...
@@ -185,6 +192,7 @@ def extract_tweetids_demo():
...
@@ -185,6 +192,7 @@ def extract_tweetids_demo():
tweetIDs to a new file (`outfile`)
tweetIDs to a new file (`outfile`)
"""
"""
infile
=
TWEETS
infile
=
TWEETS
TWEETS
.
seek
(
0
)
outfile
=
IDS
outfile
=
IDS
print
(
"Reading from {0}"
.
format
(
infile
))
print
(
"Reading from {0}"
.
format
(
infile
))
json2csv
(
infile
,
outfile
,
FIELDS
)
json2csv
(
infile
,
outfile
,
FIELDS
)
...
@@ -245,7 +253,7 @@ ALL = [twitterclass_demo, sampletoscreen_demo, tracktoscreen_demo,
...
@@ -245,7 +253,7 @@ ALL = [twitterclass_demo, sampletoscreen_demo, tracktoscreen_demo,
streamtofile_demo
,
limit_by_time_demo
,
streamtofile_demo
,
limit_by_time_demo
,
extract_tweetids_demo
,
expand_tweetids_demo
,
corpusreader_demo
]
extract_tweetids_demo
,
expand_tweetids_demo
,
corpusreader_demo
]
DEMOS
=
ALL
[
:
]
DEMOS
=
ALL
[
9
:
10
]
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
"""Run selected demo functions."""
"""Run selected demo functions."""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment