On Aug 4, 2006, at 14:20, Mike Harris wrote: > Ruby Quiz wrote: > >> *snip* >> >> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- >> =-=-=-=-=-=-= >> >> by elliot temple >> >> sometimes i type in all or mostly lowercase. a friend of mine says >> it's hard to >> read essays with no capital letters. so the problem is to write a >> method which >> takes a string (which could include many paragraphs), and >> capitalizes words that >> should be capitalized. at minimum it should do the starts of >> sentences. >> >> solutions could range from simple (a few regexes) to complex (lots >> of special >> cases are possible, like abbreviations that use a period). an >> addition would be >> using a dictionary to find proper nouns and capitalize those. it >> could also ask >> the user about cases the program can't figure out. or log them. >> >> i can provide an example solution (regex based) and a list of >> reasons it doesn't >> work very well, if you want. >> >> sample input: >> >> - this email itself works nicely >> >> - this one is hard. sometimes i might want to write about gsub vs. >> gsub! without >> the "." or "!" causing any capitalization (or the punctuation in >> quotes). >> >> one problem is maybe dealing with sentences that contain periods >> is too hard. i >> don't know. >> >> >> > It would be nice if you could assume two spaces after a end of > sentence with puncuation. Generally I think that's correct > grammar, although my grammar stinks so I could easily be wrong. If > you have to get into parsing incorrect grammar it becomes much more > difficult. It's not correct grammar, just a typographical convention; one which is sort of semi-obsolete and regularly gives rise to great debate in typographical circles over its perceived rightness, wrongness, and pragmatic value. That isn't to say you shouldn't use it, since it'll be very accurate in the general case, but redefining the problem to say "anything that doesn't use two spaces is wrong" is a bit of a dodge. ---- Matthew Smillie <M.B.Smillie / sms.ed.ac.uk> Institute for Communicating and Collaborative Systems University of Edinburgh