<jupyter_start><jupyter_text>Working with Texts in PythonAdapted from a lesson by <NAME>With only the tools we learned in the last tutorial we can do a good amount of text analysis. No special libraries or functions, just counting.  Lesson Goals* Get comfortable reading a text into Python and manipulating it* Apply Wednesday's lesson and do simple counts on a text* Start building more comfort with the Python programming language Outline* On your own, use the tools we have already learned to answer a few questions about two novels* In small groups, compare your solutions and discuss any differences* Discuss in the larger group Exploratory Natural Language Processing TasksNow that we have some of Python's basics in our toolkit, we can immediately perform the kinds of tasks that are the bread and butter of text analysis: counting. When we first meet a text in the wild, we often wish to find out a little about it before digging in deeply, so we start with simple questions like "How many words are in this text?" or "What is the average word length?" Run the cell below to read in the text of "Pride and Prejudice" and assign it to the variable "austen_string", and read in the text of <NAME>'s "A Garland for Girls," a children's book, and assign it to the variable "aclott_string". With these variables, print the answer to the following questions:1. How many words are in each novel?2. How many words in each novel appear in title case?3. What is the approximate average word length in each novel? (don't worry about punctuation for now)4. How many words longer than 7 characters are in each novel? (don't worry about punctuation for now)5. What proportion of the total words are the long words in each novel?<jupyter_code>#read in the texts
austen_string = open('../Data/Austen_PrideAndPrejudice.txt', encoding='utf-8').read()
alcott_string = open('../Data/Alcott_GarlandForGirls.txt', encoding='utf-8').read()

#print the first 100 characters of each text to make sure everything is in order
print(austen_string[:100])
print(alcott_string[:100])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.05645933014354067, 'fraction_numerical': 0.008133971291866028, 'mean_word_length': 5.078488372093023, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '460967', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 541, 'n_tokens_neox': 520, 'n_words': 317, 'path': '01-IntroToPython/.ipynb_checkpoints/01-WorkingWithTexts-checkpoint.ipynb', 'repo_name': 'lknelson/text-analysis-2017', 'size': '2107'}