Skip to content

Instantly share code, notes, and snippets.

@jnewman12
Created April 28, 2013 04:14
Show Gist options
  • Save jnewman12/5475845 to your computer and use it in GitHub Desktop.
Save jnewman12/5475845 to your computer and use it in GitHub Desktop.
This is used for summarizing text. For the time being, just insert your own text into the text variable. I will see if I can add more to it
text = %q{
#insert your text here
}
sentences = text.gsub(/\s+/, ' ').strip.split(/\.|\?|!/)
sentences_sorted = sentences.sort_by {|sentence| sentence.length}
one_third = sentences_sorted.length / 3
ideal_sentences = sentences_sorted.slice(one_third, one_third + 1)
ideal_sentences = ideal_sentences.select { |sentence| sentence =~ /is|are/ }
puts ideal_sentences.join(". ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment