This entry selects words from whole system dictionary. It takes advantage of the fact that you can make most nouns into verbs and vice-versa,. It uses a few heuristics to classify words and avoid obvious impossibilities.
$ man python | python words.py The disabled comma-separated source is using those wizards at exit. $ cat COPYING | python words.py #GPL My user accord actions a gnu of software. $ cat pg2591.txt | python words.py #Grimm's Fairy Tales Some bargain receives my threepence. Any wrong worms your world. $ cat words.py | python words.py #self reflection Your filter_possesive not_nouned those prepositions. $ man python | python words.py The disabled comma-separated source is using those wizards at exit. $ cat COPYING | python words.py #GPL My user accord actions a gnu of software. $ cat pg2591.txt | python words.py #Grimm's Fairy Tales Some bargain receives my threepence. Any wrong worms your world. $ cat words.py | python words.py #self reflection Your filter_possesive not_nouned those prepositions. $ ls /usr/bin | python words.py #directory lists Their dropbox funziped an arch. import random import string import sys import re #words = open("/usr/share/dict/words").readlines() words = re.sub("[]:;.,:?!<>{}()|=\"`[]",' ',sys.stdin.read(),flags=re.M).split() words = list(set(words)) articles=('','a ','the ','some ','this ','that ','my ','any ','your ','their ', 'all ','more ' 'an ') #an must be last pl_articles=('','some ','those ','many ','the ','these ') prepositions = ('of','by','to','for','from','in','with','on','which','when','at', 'into','as','if','near') conjunctions = ('and','or','but') verbs = ('is','are','was', 'be','do','came','been','had','have') pronouns_s = ('he','she','it','we','you') pronouns_o = ('him','her','them') possesive=False modifiers=0 use_prep = None MAX_MODIFIERS=2 def is_modifier(w): return ("'" in w or w[-2:] in ('ry','ed','er','ic','al') or w[-3:] in ('ing','est','ble','ous') or w[-4:] in ('less','ical','mmon') ) def is_verb(w): return (w in verbs or w[-2:] in ('ed',) or w[-3:] in ('ing','ize') ) def is_article(w): return w+' ' in articles or w+' ' in pl_articles def is_conjunction(w): return w in conjunctions def filter_possesive(w,always=False): global possesive #allow only one result = True if "'" in w else False if result: if always: return False if not possesive: possesive = True return False return result def is_preposition(w): global use_prep if w in prepositions: use_prep = w return True return False def is_adverb(w): return w[-2:]=='ly' def is_gerund(w): return w[-3:]=='ing' def is_plural(w): return w[-1]=='s' def not_verb(w): return (w in ('you','they','our','yes') or w[-4:] in ('ness','such') or w in pronouns_o or w in pronouns_s ) def not_noun(w): return (w in verbs) def getword(): while True: w=words[random.randrange(len(words))].rstrip() if w[0] in string.ascii_uppercase: continue if is_article(w) or is_preposition(w): continue if filter_possesive(w): continue #print w return w def get_article(): return articles[random.randrange(len(articles)-1)] #print '--s--' substr='' conjunction = False while True: w=getword() if is_modifier(w): if modifiers < MAX_MODIFIERS: substr+=w+' ' modifiers+=1 else: continue elif is_adverb(w) or is_plural(w) or not_noun(w): continue else: if is_conjunction(w): conjunction = w continue substr= substr+w+' ' if conjunction: substr+=conjunction+' ' conjunction = False continue if w in pronouns_s: substr = w+' ' art='' else: art = get_article() if art is 'a ' and substr[0] in 'aeiou': art='an ' substr= string.capwords(art+substr,'.') break #print '--v--' verbstr='' while True: w=getword() if not_verb(w) or filter_possesive(w,True): continue elif is_adverb(w): verbstr+=w+' ' elif is_gerund(w): verbstr+='is '+w+' ' break elif is_verb(w): verbstr= verbstr+w+' ' break elif is_modifier(w) or is_conjunction(w): continue else: if not is_plural(w): w=w+'ed' if w[-1]!='e' else w+'d' verbstr= verbstr+w+' ' break #print '--o--' obstr='' conjunction = False while True: w=getword() if is_modifier(w): if modifiers<MAX_MODIFIERS: obstr+=w+' ' modifiers+=1 else: continue elif is_adverb(w) or not_noun(w) or w in pronouns_s: continue else: if is_conjunction(w): conjunction = w continue obstr = obstr+w if conjunction: obstr+=' '+conjunction+' ' conjunction = False continue if is_plural(w): art = pl_articles[random.randrange(len(pl_articles))] else: art = articles[random.randrange(len(articles)-1)] if art is 'a ' and obstr[0] in 'aeiou': art='an ' if w in pronouns_o: obstr=w else: obstr= art+obstr break #print '--p--' while use_prep: w=getword() if (is_modifier(w) or is_preposition(w) or is_gerund(w) or not_noun(w) or is_conjunction(w)): continue obstr+=' '+use_prep+' '+w use_prep=None print substr+verbstr+obstr+'.' import random import string import sys import re #words = open("/usr/share/dict/words").readlines() words = re.sub("[]:;.,:?!<>{}()|=\"`[]",' ',sys.stdin.read(),flags=re.M).split() words = list(set(words)) articles=('','a ','the ','some ','this ','that ','my ','any ','your ','their ', 'all ','more ' 'an ') #an must be last pl_articles=('','some ','those ','many ','the ','these ') prepositions = ('of','by','to','for','from','in','with','on','which','when','at', 'into','as','if','near') conjunctions = ('and','or','but') verbs = ('is','are','was', 'be','do','came','been','had','have') pronouns_s = ('he','she','it','we','you') pronouns_o = ('him','her','them') possesive=False modifiers=0 use_prep = None MAX_MODIFIERS=2 def is_modifier(w): return ("'" in w or w[-2:] in ('ry','ed','er','ic','al') or w[-3:] in ('ing','est','ble','ous') or w[-4:] in ('less','ical','mmon') ) def is_verb(w): return (w in verbs or w[-2:] in ('ed',) or w[-3:] in ('ing','ize') ) def is_article(w): return w+' ' in articles or w+' ' in pl_articles def is_conjunction(w): return w in conjunctions def filter_possesive(w,always=False): global possesive #allow only one result = True if "'" in w else False if result: if always: return False if not possesive: possesive = True return False return result def is_preposition(w): global use_prep if w in prepositions: use_prep = w return True return False def is_adverb(w): return w[-2:]=='ly' def is_gerund(w): return w[-3:]=='ing' def is_plural(w): return w[-1]=='s' def not_verb(w): return (w in ('you','they','our','yes') or w[-4:] in ('ness','such') or w in pronouns_o or w in pronouns_s ) def not_noun(w): return (w in verbs) def getword(): while True: w=words[random.randrange(len(words))].rstrip() if w[0] in string.ascii_uppercase: continue if is_article(w) or is_preposition(w): continue if filter_possesive(w): continue #print w return w def get_article(): return articles[random.randrange(len(articles)-1)] #print '--s--' substr='' conjunction = False while True: w=getword() if is_modifier(w): if modifiers < MAX_MODIFIERS: substr+=w+' ' modifiers+=1 else: continue elif is_adverb(w) or is_plural(w) or not_noun(w): continue else: if is_conjunction(w): conjunction = w continue substr= substr+w+' ' if conjunction: substr+=conjunction+' ' conjunction = False continue if w in pronouns_s: substr = w+' ' art='' else: art = get_article() if art is 'a ' and substr[0] in 'aeiou': art='an ' substr= string.capwords(art+substr,'.') break #print '--v--' verbstr='' while True: w=getword() if not_verb(w) or filter_possesive(w,True): continue elif is_adverb(w): verbstr+=w+' ' elif is_gerund(w): verbstr+='is '+w+' ' break elif is_verb(w): verbstr= verbstr+w+' ' break elif is_modifier(w) or is_conjunction(w): continue else: if not is_plural(w): w=w+'ed' if w[-1]!='e' else w+'d' verbstr= verbstr+w+' ' break #print '--o--' obstr='' conjunction = False while True: w=getword() if is_modifier(w): if modifiers<MAX_MODIFIERS: obstr+=w+' ' modifiers+=1 else: continue elif is_adverb(w) or not_noun(w) or w in pronouns_s: continue else: if is_conjunction(w): conjunction = w continue obstr = obstr+w if conjunction: obstr+=' '+conjunction+' ' conjunction = False continue if is_plural(w): art = pl_articles[random.randrange(len(pl_articles))] else: art = articles[random.randrange(len(articles)-1)] if art is 'a ' and obstr[0] in 'aeiou': art='an ' if w in pronouns_o: obstr=w else: obstr= art+obstr break #print '--p--' while use_prep: w=getword() if (is_modifier(w) or is_preposition(w) or is_gerund(w) or not_noun(w) or is_conjunction(w)): continue obstr+=' '+use_prep+' '+w use_prep=None print substr+verbstr+obstr+'.'