def main(): wordbank2 = { 'Det': ['the', 'this', 'that', 'each', 'every', 'another'], 'Ord': ['first', 'second', 'last', 'middle', 'third', 'final', 'penultimate'], 'Adj': ['green', 'blue', 'illiterate', 'cheerful', 'elated', 'ethereal', 'transliterated', 'randy', 'greasy'], 'SingNoun': ['duck', 'ant', 'egg', 'window', 'cereal', 'AI project', 'ulna', 'trenchcoat', 'denture'], 'SingPropNoun': ['Jack', 'Jill', 'Fred', 'George', 'Doris', 'Illuminati', 'Big Brother', 'Arcady Ivanovich'], 'AdvPlace': ['here', 'there', 'everywhere'], 'AdvTimePres': ['today', 'Friday', 'this week', 'sometime'], 'AdvTimePast': ['yesterday', 'last Wednesday', 'last month'] } wordbank3 = { 'Det': ['the', 'this', 'that', 'every', 'another', 'a single'], 'Ord': ['fourth', 'eleventh', 'last', 'middle', 'third', 'final', 'penultimate'], 'Adj': ['red', 'blue', 'winning', 'cheerful', 'elated', 'big', 'little', 'scared', 'rare', 'mucosal', 'phallic'], 'SingNoun': ['spider', 'bucket', 'steak', 'milk', 'computer', 'snowman', 'milksteak', 'funnel', 'babycarrot'], 'SingPropNoun': ['Brendan', 'Ed', 'Jimmy', 'Hannah', 'Ryan', 'Helena', 'Svetlana', 'Pamela', 'Vladimir'], 'AdvDeg': ['very', 'mostly', 'rarely', 'never'] } skeleton_gram_str2 = ''.join(open('species2.pcfg')) skeleton_gram_str3 = ''.join(open('species3.pcfg')) for w in wordbank2.keys(): skeleton_gram_str2 = addterminals(skeleton_gram_str2, w, wordbank2[w]) for w in wordbank3.keys(): skeleton_gram_str3 = addterminals(skeleton_gram_str3, w, wordbank3[w]) user1 = environment.User('/u/_junebug_', None, True, None, True) prod1 = Producer(user1, skeleton_gram_str2, wordbank2) user1.producer = prod1 user2 = environment.User('/u/_gstring_', None, True, None, True) prod2 = Producer(user2, skeleton_gram_str3, wordbank3) user2.producer = prod2 user1.evaluator = evaluator.Evaluator([A(), L(), T(), W(['spider', 'Ryan', 'Doris'], ['little', 'elated']), B(user1)], user1) user2.evaluator = evaluator.Evaluator([A(), L(), T(), W(['Ed', 'steak', 'never'], ['funnel', 'milk', 'green']), B(user2)], user2) # run 5 'iterations' posts = [] for i in range(50): if i % 10 == 0: prod1.parent_grammar.mutate() prod2.parent_grammar.mutate() user1.evaluate_iteration(posts) user2.evaluate_iteration(posts) posts = [] posts.append(prod1.parent_grammar.make_post('1', i//10)) posts.append(prod2.parent_grammar.make_post('2', i//10))
def main(): rules = [('Det', ['the', 'this', 'that', 'each', 'every', 'another']), ('Ord', [ 'first', 'second', 'last', 'middle', 'third', 'final', 'penultimate' ]), ('Adj', ['green', 'blue', 'winning', 'cheerful', 'elated']), ('SingNoun', ['duck', 'ant', 'egg', 'window', 'cereal', 'AI project']), ('SingPropNoun', ['Jack', 'Jill', 'Fred', 'George']), ('Prep', ['on', 'for', 'from', 'by', 'with']), ('AdvPlace', ['here', 'there', 'everywhere']), ('AdvTimePres', ['today', 'Friday', 'this week', 'sometime']), ('AdvTimePast', ['yesterday', 'last Wednesday', 'last month'])] skeleton_gram_str = ''.join(open('species2.pcfg')) for r in rules: skeleton_gram_str = addterminals(skeleton_gram_str, r[0], r[1]) prod = Producer('/u/_junebug_', skeleton_gram_str) print(prod.parent_grammar.grammar) p = choice(prod.parent_grammar.grammar.productions()) prod.parent_grammar.add_new( [nltk.ProbabilisticProduction(p.lhs(), ['hii'], prob=0.3)]) print(prod.parent_grammar.grammar)
def getGString(): wordbank = { 'Det': ['the', 'this', 'that', 'every', 'another', 'a single'], 'Ord': [ 'fourth', 'eleventh', 'last', 'middle', 'third', 'final', 'penultimate' ], 'Adj': [ 'red', 'blue', 'winning', 'cheerful', 'elated', 'big', 'little', 'scared', 'rare', 'mucosal', 'phallic' ], 'SingNoun': [ 'spider', 'bucket', 'steak', 'milk', 'computer', 'snowman', 'milksteak', 'funnel', 'babycarrot' ], 'SingPropNoun': [ 'Brendan', 'Ed', 'Jimmy', 'Hannah', 'Ryan', 'Helena', 'Svetlana', 'Pamela', 'Vladimir' ], 'AdvDeg': ['very', 'mostly', 'rarely', 'never'] } skeleton_gram_str = ''.join(open('species3.pcfg')) for w in wordbank.keys(): skeleton_gram_str = addterminals(skeleton_gram_str, w, wordbank[w]) return skeleton_gram_str, wordbank
def getGString(): wordbank = { 'Det': ['the', 'this', 'that', 'each', 'every', 'another'], 'Ord': ['first', 'second', 'last', 'middle', 'third', 'final', 'penultimate'], 'Adj': [ 'green', 'blue', 'illiterate', 'cheerful', 'elated', 'ethereal', 'transliterated', 'randy', 'greasy' ], 'SingNoun': [ 'duck', 'ant', 'egg', 'window', 'cereal', 'AI project', 'ulna', 'trenchcoat', 'denture' ], 'SingPropNoun': [ 'Jack', 'Jill', 'Fred', 'George', 'Doris', 'Illuminati', 'Big Brother', 'Arcady Ivanovich' ], 'AdvPlace': ['here', 'there', 'everywhere'], 'AdvTimePres': ['today', 'Friday', 'this week', 'sometime'], 'AdvTimePast': ['yesterday', 'last Wednesday', 'last month'] } skeleton_gram_str = ''.join(open('species2.pcfg')) for w in wordbank.keys(): skeleton_gram_str = addterminals(skeleton_gram_str, w, wordbank[w]) return skeleton_gram_str, wordbank
def getGString(): wordbank = { 'Det': ['the', 'a', 'this', 'all' 'each', 'another', 'any'], 'Card': ['one', 'four', 'twenty'], 'Ord': ['first', 'last', 'second', 'next', 'other'], 'Quant': ['many', 'few'], 'Adj': [ 'smelly', 'hunky', 'smart', 'free', 'hungry', 'tasty', 'evil', 'loving' ], 'SingNoun': [ 'computer', 'freedom', 'cube', 'stream', 'planet', 'aventurine', 'nose', 'hunk', 'hyperbolic plane' ], 'SingPropNoun': ['Joe', 'Jake', 'Brendan', 'Adam Eck'], 'SubPersPro': ['he', 'she', 'they', 'it'], 'PosPro': ['him', 'her', 'my', 'them', 'it'], 'LV': [ 'appears', 'becomes', 'grows', 'smells', 'sounds', 'tastes', 'feels', 'remains' ] } skeleton_gram_str = ''.join(open('species1.pcfg')) for w in wordbank.keys(): skeleton_gram_str = addterminals(skeleton_gram_str, w, wordbank[w]) return skeleton_gram_str, wordbank
def getGString(): wordbank = { 'Det': ['the', 'this', '\'dis', 'each', 'every', 'another'], 'Ord': ['first', 'ninth', 'tenth', 'third', 'final'], 'Adj': [ 'yellow', 'slimy', 'gross', 'disgusting', 'hip', 'jovial', 'lovely', 'honest', 'wet', 'blotto', 'spooky' ], 'SingNoun': [ 'hair', 'kiosk', 'water', 'sludge', 'pond', 'simulation', 'horse', 'syndicate', 'bulldog' ], 'SingPropNoun': [ 'Jim', 'Bob', 'Adam', 'Sally', 'Jeb!', 'Cher', 'Charles Shaw', 'Leonard,' 'Gordon Ramsay' ], 'VintPast': [ 'disappeared', 'agreed', 'waited', 'vomited', 'flailed', 'slept', 'died' ], 'VintPres': ['vanishes', 'eats', 'stands', 'frolics', 'sleeps', 'fumbles'], 'VintFut': ['will appear', 'will live', 'will prevail', 'will sleep', 'will go'], 'Adverb': [ 'quickly', 'properly', 'sneakily', 'simply', 'courageously', 'covertly' ] } skeleton_gram_str = ''.join(open('species4.pcfg')) for w in wordbank.keys(): skeleton_gram_str = addterminals(skeleton_gram_str, w, wordbank[w]) return skeleton_gram_str, wordbank
def getGString(): walt = nltk.pos_tag(gutenberg.words('whitman-leaves.txt')) skeleton_gram_string = ''.join(open('species1.pcfg')) skeleton_gram_string = addterminals( skeleton_gram_string, 'Det', ['the', 'a', 'this', 'all' 'each', 'another', 'any']) skeleton_gram_string = addterminals(skeleton_gram_string, 'Card', ['one', 'four', 'twenty']) skeleton_gram_string = addterminals( skeleton_gram_string, 'Ord', ['first', 'last', 'second', 'next', 'other']) skeleton_gram_string = addterminals(skeleton_gram_string, 'Quant', ['many', 'few']) skeleton_gram_string = addterminals( skeleton_gram_string, 'Adj', sample( set([ word for (word, tag) in walt if tag == 'JJ' and len(word) > 3 ]), 25)) skeleton_gram_string = addterminals( skeleton_gram_string, 'SingNoun', sample( set([ word for (word, tag) in walt if tag == 'NN' and len(word) > 3 ]), 40)) skeleton_gram_string = addterminals(skeleton_gram_string, 'SingPropNoun', ['Joe', 'Jake', 'Brendan', 'Adam Eck']) skeleton_gram_string = addterminals( skeleton_gram_string, 'Prep', ['on', 'in', 'over', 'through', 'around', 'like']) skeleton_gram_string = addterminals(skeleton_gram_string, 'PersPro', ['he', 'she', 'they', 'it']) skeleton_gram_string = addterminals(skeleton_gram_string, 'PosPro', ['him', 'her', 'my', 'them', 'it']) skeleton_gram_string = addterminals(skeleton_gram_string, 'LV', [ 'appears', 'becomes', 'grows', 'smells', 'sounds', 'tastes', 'feels', 'remains' ]) #prod = Producer('/u/_junebug_', skeleton_gram_string) #for i in range(10): # print(prod.parent_grammar.get_post()) return skeleton_gram_string
def main(): wordbank2 = { 'Det' : ['the', 'this', 'that', 'each', 'every', 'another'], 'Ord' : ['first', 'second', 'last', 'middle', 'third', 'final', 'penultimate'], 'Adj' : ['green', 'blue', 'illiterate', 'cheerful', 'elated', 'ethereal', 'transliterated', 'randy', 'greasy'], 'SingNoun' : ['duck', 'ant', 'egg', 'window', 'cereal', 'AI project', 'ulna', 'trenchcoat', 'denture'], 'SingPropNoun' : ['Jack', 'Jill', 'Fred', 'George', 'Doris', 'Illuminati', 'Big Brother', 'Arcady Ivanovich'], 'AdvPlace' : ['here', 'there', 'everywhere'], 'AdvTimePres' : ['today', 'Friday', 'this week', 'sometime'], 'AdvTimePast' : ['yesterday', 'last Wednesday', 'last month'] } wordbank3 = { 'Det' : ['the', 'this', 'that', 'every', 'another', 'a single'], 'Ord' : ['fourth', 'eleventh', 'last', 'middle', 'third', 'final', 'penultimate'], 'Adj' : ['red', 'blue', 'winning', 'cheerful', 'elated', 'big', 'little', 'scared', 'rare', 'mucosal', 'phallic'], 'SingNoun' : ['spider', 'bucket', 'steak', 'milk', 'computer', 'snowman', 'milksteak', 'funnel', 'babycarrot'], 'SingPropNoun' : ['Brendan', 'Ed', 'Jimmy', 'Hannah', 'Ryan', 'Helena', 'Svetlana', 'Pamela', 'Vladimir'], 'AdvDeg' : ['very', 'mostly', 'rarely', 'never'] } skeleton_gram_str2 = ''.join(open('species2.pcfg')) skeleton_gram_str3 = ''.join(open('species3.pcfg')) for w in wordbank2.keys(): skeleton_gram_str2 = addterminals(skeleton_gram_str2, w, wordbank2[w]) for w in wordbank3.keys(): skeleton_gram_str3 = addterminals(skeleton_gram_str3, w, wordbank3[w]) user1 = environment.User('/u/_junebug_', None, True, None, True) prod1 = Producer(user1, skeleton_gram_str2, wordbank2) user1.producer = prod1 user2 = environment.User('/u/_gstring_', None, True, None, True) prod2 = Producer(user2, skeleton_gram_str3, wordbank3) user2.producer = prod2 user1.buddies = [user2] user2.buddies = [user1] ##### Mutate Tests ##### # for i in range(100): # prod1.parent_grammar.mutate_weights() # prod2.parent_grammar.mutate_weights() # print(prod1.parent_grammar.grammar) # print('_----------_') # print(prod2.parent_grammar.grammar) # for i in range(30): # prod1.parent_grammar.add_new([prod1.parent_grammar._getnewword()]) # prod1.parent_grammar.mutate_weights() # print(prod1.parent_grammar.grammar) # for i in range(100): # bw = prod2.parent_grammar._getbudword(user1.producer) # if bw is not None: # prod2.parent_grammar.add_new([bw]) # prod2.parent_grammar.mutate_weights() # print(prod2.parent_grammar.grammar) # for i in range(3): # prod1.parent_grammar.merge(prod1.parent_grammar._getsep(), prod2) # prod1.parent_grammar.separate() #print(prod1.parent_grammar.grammar) for i in range(200): prod1.parent_grammar.mutate() prod2.parent_grammar.mutate() print(prod1.parent_grammar.grammar) print('_----------_') print(prod2.parent_grammar.grammar) for i in range(10): print(prod1.parent_grammar.get_post()) print() print(prod2.parent_grammar.get_post()) print()