Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It is not "easy [...] to achieve", e.g. try the code on this sentence, Dr. bootload.


The only real constraints are sentences with first non-alpha. I'd try something like:

    converted is store for modified text
    new paragraph is store for modified sentences
    abbreviations is list of common abbreviations (eg,nb,dr...)

    paragraph is split by newline '\n'
    for each newline in paragraph
        /* abbreviation check using '.' seps */
        if fullstops in newline greater than one
            check newline for abbreviations and replace
  
        /* break down para into newlines by '.' */
        split newline into sentences by '.'
            for sentence in sentences
                if sentence starts with word
                    replace first letter with upper
                else
                    move to first word, replace with upper
                /* build up paragraphs */
                append sentence to new paragraph
 
      /* modified text */  
      append new paragraph to converted
    write converted to display
tricky bit is 'abbreviations & dots' [0] & preserving the format. Will fail on names (eg: J.A. Smith)

[0] https://en.wikipedia.org/wiki/Lists_of_abbreviations


Shouldn't it be "Dr. Bootload" anyway?


It is certainly Dr. bell hooks.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: