import nltk nltk.chat.chatbots() # EXERCISES Chapter 1 # E1 # E2 # E3 3 * sent1 # E4 len(text2) len([w.lower() for w in set(text2) if w.isalpha()]) # E5 # E6 text2.dispersion_plot(["Elinor", "Marianne", "Edward", "Willoughby"]) # E7 text5.collocations() # E8 # E9 a)) myString = "I can write whatever I feel like here" print myString # E9 b) otherString = ", I can" myString + otherString myString + " " + otherString " ".join([myString, otherString]) # Pythonista Alternative # E10 mySent = ["This", "is", "my", "sentence"] sentence = " ".join(mySent)
# EXERCISES Chapter 1 # E1 # E2 # E3 3*sent1 # E4 len(text2) len([w.lower() for w in set(text2) if w.isalpha()]) # E5 # E6 text2.dispersion_plot(["Elinor","Marianne","Edward","Willoughby"]) # E7 text5.collocations() # E8 # E9 a)) myString = "I can write whatever I feel like here" print myString # E9 b) otherString = ", I can" myString + otherString myString + " " + otherString " ".join([myString,otherString]) # Pythonista Alternative # E10 mySent = ["This","is","my","sentence"] sentence = " ".join(mySent)
''' Chapter 01 - https://www.nltk.org/book/ch01.html Section 08 - Exercises Question 06 - Produce a dispersion plot of the four main protagonists in Sense and Sensibility: Elinor, Marianne, Edward, and Willoughby. What can you observe about the different roles played by the males and females in this novel? Can you identify the couples? ''' from nltk.book import text2 four_main_protagonists = ["Elinor", "Marianne", "Edward", "Willoughby"] text2.dispersion_plot(four_main_protagonists) #count_occorrences = list(map(lambda x: (x, text2.count(x)), four_main_protagonists)) #print(count_occorrences) print("Elinor and Marianne are most cited!") print("Possible Couples:\n-> Elinor and Marianne\n-> Edward and Willoughby")
from nltk.book import text2 text2.dispersion_plot(['Elinor', 'Marianne', 'Edward', 'Willoughby']) print(len(text2))