Esempio n. 1
0
def remix_it(form):       
    ''' Scramble word order, vary how many words get remixed '''
      
    tokens = list(form.output[0:])
    to_mix = []
    
    if len(tokens) > 2:
        to_mix = tokens
    elif len(form.last_five) > 0:
        to_mix = list(form.last_five)
    else: to_mix = tokens    
    
    # Get wave values for each word number possibility
    values = [wave.run() for wdx, wave in enumerate(form.winning_voice.sub_waves) if wdx < len(to_mix)]
    ranges = die.build_range_from_values(values)
    which = die.pick_one(ranges)

    print "Remix Values: " + str(values)      
    print "Re-order how many times? " + str(which)
    
        
    for wdx, word in enumerate(to_mix):
        if wdx < which + 1:  
            idx = random.randrange(0, len(to_mix))
            popped = to_mix.pop(idx)
            if len(to_mix) > 0: idx = random.randrange(0, len(to_mix))
            else: idx = 0
            to_mix.insert(idx, popped)
            
    remixed = to_mix            
    return tuple(remixed)
Esempio n. 2
0
    def __init__(self, user_input):
        '''Formula for poems'''
        
        # Change up "source of words" here.
        with open('data/commonwords_dict.pickle', 'rb') as c: self.worddict = pickle.load(c)
        with open('data/commonwords_list.pickle', 'rb') as c: self.wordlist = pickle.load(c)
        with open('data/collocations.pickle', 'rb') as c: self.collocations = pickle.load(c)
        with open('data/w5.pickle', 'rb') as p: self.phrases = pickle.load(p)
        
        self.input = user_input
        self.output = self.parse_input(self.input)
        print self.output
        self.output_str = self.get_str()
        self.last_five = deque()
                
        # Pre-calculated ranges for voices, waves and modes
        self.how_many_now = 1
        self.duration = 100
        self.voice_num_ranges = die.roll_die(5)
        print "Num of Voices: " + str(self.voice_num_ranges)
        
        self.mode_ranges = die.build_range_from_values([1, 5, 6, 4, 2, 3, 4]) #die.roll_die(7) 
        print "Modes: " + str(self.mode_ranges)

        self.wave_ranges = die.build_range_from_values([2, 1, 1, 2]) #die.roll_die(4)        
        print "Waves: " + str(self.wave_ranges)

        # A dictionary for each voice
        self.voices = []
        # Create 3 meta-voices for duration, capping, and clipping
        self.meta_voices = [voices.Voice(wave_idx = 0) for i in range(3)]
        
        # Keep track of which voice and mode
        self.winning_voice = 0
        self.winner = 0

        # Start up the Queue for moving outputs int mem-cache       
        self.q = queue.Queue()
        
        # Keep track of whether we're in Manual Mode
        self.manual = False
        self.new_manual = True
        
        # GO !
        self.run()
Esempio n. 3
0
def elide_it(form):
    ''' Find collocations, vary whether to return just the 2nd or both words ''' 
     
    tokens = form.output[0:]      
    this = tokens[-1]
    thats = el.get(form.collocations, this)
    
    # Calculate probably of returning one or two-word elision
    values = [wave.run() for wave in form.winning_voice.sub_waves]

    ranges = die.build_range_from_values(values)  
    which = die.pick_one(ranges) + 1

    print "Elision Values: " + str(values)      
    print "1 or 2 words? " + str(which)
    print thats
    
    if which == 1:
        return thats
    else:
        thisthats = []    
        for that in thats:
            thisthats.append((this, that)) 
        return tuple(thisthats)