<jupyter_start><jupyter_text>Putting it all together - Basic Text Processing and Analysis<jupyter_code>from nltk.corpus import gutenberg
import matplotlib.pyplot as plt

%matplotlib inline

bible = gutenberg.open('bible-kjv.txt')
bible = bible.readlines()

bible[:5]
len(bible)
bible = list(filter(None, [item.strip('\n') for item in bible]))
bible[:5]
len(bible)
line_lengths = [len(sentence) for sentence in bible]
h = plt.hist(line_lengths)
tokens = [item.split() for item in bible]
print(tokens[:5])
total_tokens_per_line = [len(sentence.split()) for sentence in bible]
h = plt.hist(total_tokens_per_line, color='orange')
words = [word for sentence in tokens for word in sentence]
print(words[:20])
words = list(filter(None, [re.sub(r'[^A-Za-z]', '', word) for word in words]))
print(words[:20])
from collections import Counter

words = [word.lower() for word in words]
c = Counter(words)
c.most_common(10)
import nltk 

stopwords = nltk.corpus.stopwords.words('english')
words = [word.lower() for word in words if word not in stopwords]
c = Counter(words)
c.most_common(10)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13808664259927797, 'fraction_numerical': 0.009927797833935019, 'mean_word_length': 6.201298701298701, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '567605', 'license': 'Apache-2.0', 'n_tokens_mistral': 413, 'n_tokens_neox': 400, 'n_words': 108, 'path': 'ODSC18/Code/Basic Text Data Analysis and Visualization.ipynb', 'repo_name': '27ankitsharma/Dipanjan-Art_of_data_visualization', 'size': '1108'}