Guest User

Untitled

a guest
Jan 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. dieperbolic_sentences = []
  2. hyperbolic_sentences = get_sentences
  3. length = hyperbolic_sentences.length
  4.  
  5. # Initialise our sentences to false.
  6. prev_s = false
  7. this_s = false
  8. next_s = false
  9.  
  10. for i in 0...length do
  11.  
  12. prev_s = this_s
  13. this_s = (next_s) ? next_s : hyperbolic_sentence[i]
  14. next_s = (i == (length - 1)) ? false : hyperbolic_sentences[i+1]
  15.  
  16. # This was just a paragraph break or it's an empty string. Push it on and then skip to the next sentence.
  17. if this_s == false || this_s == ''
  18. dieperbolic_sentences push this_s
  19. next
  20. end
  21.  
  22. # No sentence needs to begin with 'Yes'.
  23. this_s.sub!(/^Yes, /, '')
  24.  
  25. # But's a conjunctive. What you mean is 'However'.
  26. this_s.sub!(/^But /, 'However, ')
  27.  
  28. # Let's leave the rhetorical questions to the politicians.
  29. if this_s.match!(/\?$/)
  30. if next_s && next_s.length < 12 # Change this magic value
  31. this_s = ''
  32. next_s = ''
  33. end
  34.  
  35. # Solve that I disease problem.
  36. this_s.sub!(/^I /)
  37.  
  38. # Again with conjunctions beginning sentences.
  39. if next_s && next_s.match(/^And /)
  40. this_s = this_s + ' ' + next_s[0, 1].downcase + next_s[1..-1]
  41. next_s = ''
  42. end
  43.  
  44. dieperbolic_sentences.push this_s
  45. end
  46.  
  47. cleaned_content = '<p>'
  48.  
  49. dieperbolic_sentences.each do |sentence|
  50. if sentence || sentence != ''
  51. cleaned_content += '' + sentence
  52. elsif sentence
  53. cleaned_content += '</p>'
  54. end
  55. end
Add Comment
Please, Sign In to add comment