Mega Code Archive

 
Categories / Ruby / String
 

Testing Sentence Separation

require 'test/unit' class String   def sentences     gsub(/\n|\r/, ' ').split(/\.\s*/)   end end def test_sentences   assert_equal(["a", "b", "c d", "e f g"], "a. b. c d. e f g.".sentences)   test_text = %q{Hello. This is a test of sentence separation. This is the end of the test.}   assert_equal("This is the end of the test", test_text.sentences[2]) end