HW2: SIDEQUEST -- Summarization (via example)

Via this tutorial } 10-13-19

In [34]:
paragraph = "So, keep working. Keep striving. Never give up. Fall down seven times, get up eight. Ease is a greater threat to progress than hardship. Ease is a greater threat to progress than hardship. So, keep moving, keep growing, keep learning. See you at work."
In [35]:
paragraph
Out[35]:
'So, keep working. Keep striving. Never give up. Fall down seven times, get up eight. Ease is a greater threat to progress than hardship. Ease is a greater threat to progress than hardship. So, keep moving, keep growing, keep learning. See you at work.'
In [36]:
sentences = paragraph.split('.')
sentences
Out[36]:
['So, keep working',
 ' Keep striving',
 ' Never give up',
 ' Fall down seven times, get up eight',
 ' Ease is a greater threat to progress than hardship',
 ' Ease is a greater threat to progress than hardship',
 ' So, keep moving, keep growing, keep learning',
 ' See you at work',
 '']
In [68]:
# remove stopwords
clean_sentences = [sentence.strip().split() for sentence in sentences]
clean_sentences
Out[68]:
[['So,', 'keep', 'working'],
 ['Keep', 'striving'],
 ['Never', 'give', 'up'],
 ['Fall', 'down', 'seven', 'times,', 'get', 'up', 'eight'],
 ['Ease',
  'is',
  'a',
  'greater',
  'threat',
  'to',
  'progress',
  'than',
  'hardship'],
 ['Ease',
  'is',
  'a',
  'greater',
  'threat',
  'to',
  'progress',
  'than',
  'hardship'],
 ['So,', 'keep', 'moving,', 'keep', 'growing,', 'keep', 'learning'],
 ['See', 'you', 'at', 'work'],
 []]
In [69]:
clean_words = [word.lower() for sent in clean_sentences for word in sent]
# clean_words = [word.lower() for word in sent for sent in clean_sentences]

clean_words
Out[69]:
['so,',
 'keep',
 'working',
 'keep',
 'striving',
 'never',
 'give',
 'up',
 'fall',
 'down',
 'seven',
 'times,',
 'get',
 'up',
 'eight',
 'ease',
 'is',
 'a',
 'greater',
 'threat',
 'to',
 'progress',
 'than',
 'hardship',
 'ease',
 'is',
 'a',
 'greater',
 'threat',
 'to',
 'progress',
 'than',
 'hardship',
 'so,',
 'keep',
 'moving,',
 'keep',
 'growing,',
 'keep',
 'learning',
 'see',
 'you',
 'at',
 'work']
In [93]:
for sentence in sentences:
    sentence = sentence.strip().split()
    for word in sentence:
        new_word = ''
        for letter in word:
            if letter.isalpha():
#                 print(letter)
                new_word += letter.lower()
        print(new_word)
#         if word.isalpha():
#             print(word.lower())
so
keep
working
keep
striving
never
give
up
fall
down
seven
times
get
up
eight
ease
is
a
greater
threat
to
progress
than
hardship
ease
is
a
greater
threat
to
progress
than
hardship
so
keep
moving
keep
growing
keep
learning
see
you
at
work
In [88]:
for sentence in clean_sentences:
#     no_punctuation = [''.join(letters) for word in sentence for letters in word if letters.isalpha()]
    no_punctuation = [letters for word in sentence for letters in word if letters.isalpha()]
    print(no_punctuation)
    clean_words = [word.lower() for word in sentence]
    print(clean_words)
['S', 'o', 'k', 'e', 'e', 'p', 'w', 'o', 'r', 'k', 'i', 'n', 'g']
['so,', 'keep', 'working']
['K', 'e', 'e', 'p', 's', 't', 'r', 'i', 'v', 'i', 'n', 'g']
['keep', 'striving']
['N', 'e', 'v', 'e', 'r', 'g', 'i', 'v', 'e', 'u', 'p']
['never', 'give', 'up']
['F', 'a', 'l', 'l', 'd', 'o', 'w', 'n', 's', 'e', 'v', 'e', 'n', 't', 'i', 'm', 'e', 's', 'g', 'e', 't', 'u', 'p', 'e', 'i', 'g', 'h', 't']
['fall', 'down', 'seven', 'times,', 'get', 'up', 'eight']
['E', 'a', 's', 'e', 'i', 's', 'a', 'g', 'r', 'e', 'a', 't', 'e', 'r', 't', 'h', 'r', 'e', 'a', 't', 't', 'o', 'p', 'r', 'o', 'g', 'r', 'e', 's', 's', 't', 'h', 'a', 'n', 'h', 'a', 'r', 'd', 's', 'h', 'i', 'p']
['ease', 'is', 'a', 'greater', 'threat', 'to', 'progress', 'than', 'hardship']
['E', 'a', 's', 'e', 'i', 's', 'a', 'g', 'r', 'e', 'a', 't', 'e', 'r', 't', 'h', 'r', 'e', 'a', 't', 't', 'o', 'p', 'r', 'o', 'g', 'r', 'e', 's', 's', 't', 'h', 'a', 'n', 'h', 'a', 'r', 'd', 's', 'h', 'i', 'p']
['ease', 'is', 'a', 'greater', 'threat', 'to', 'progress', 'than', 'hardship']
['S', 'o', 'k', 'e', 'e', 'p', 'm', 'o', 'v', 'i', 'n', 'g', 'k', 'e', 'e', 'p', 'g', 'r', 'o', 'w', 'i', 'n', 'g', 'k', 'e', 'e', 'p', 'l', 'e', 'a', 'r', 'n', 'i', 'n', 'g']
['so,', 'keep', 'moving,', 'keep', 'growing,', 'keep', 'learning']
['S', 'e', 'e', 'y', 'o', 'u', 'a', 't', 'w', 'o', 'r', 'k']
['see', 'you', 'at', 'work']
[]
[]
In [ ]:
 
In [ ]: