<jupyter_start><jupyter_text>1. Building a Corpus of Tweets  The following code downloads tweets from twitter API and saves tweets as json files.<jupyter_code># import package 

import os
from nltk.twitter import Twitter
# set enviornment variable to the directory that contains twitter APT credientials 

os.environ['TWITTER'] = '/Users/qiuzhuang/twitter-files'
# download tweets that contain key words from twitter database, notice:
# 1) a single function that loops through all the key words does NOT work for this task
# becuase the connection to twitter API will be aborted after about 30000-70000 downloads.
# 2) due to the same reason, the number of tweets downloaded for each key words varies from
# 35359 tweets to 71601 tweets
 
tw=Twitter()
tw.tweets(keywords='definitely', stream=False, to_screen= False, limit=100000)
tw=Twitter()
tw.tweets(keywords='might', stream=False, to_screen= False, limit=100000)
tw=Twitter()
tw.tweets(keywords='must', stream=False, to_screen= False, limit=100000)
tw=Twitter()
tw.tweets(keywords='would', stream=False, to_screen= False, limit=100000)
tw=Twitter()
tw.tweets(keywords='possibly', stream=False, to_screen= False, limit=100000)
tw=Twitter()
tw.tweets(keywords='probably', stream=False, to_screen= False, limit=100000)
tw=Twitter()
tw.tweets(keywords='certainly', stream=False, to_screen= False, limit=100000)
tw=Twitter()
tw.tweets(keywords='may', stream=False, to_screen= False, limit=100000)
# manually rename the json files as 'keyword.json', such as 'may.json', 'certainly.json', etc.<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11012094207511139, 'fraction_numerical': 0.04519414385741566, 'mean_word_length': 6.86, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '90047', 'license': 'MIT', 'n_tokens_mistral': 574, 'n_tokens_neox': 477, 'n_words': 163, 'path': 'notebooks/1_corpus_building.ipynb', 'repo_name': 'PON2020/PSC290_final_project', 'size': '1571'}