Ejemplo n.º 1
0
 def generate_actions(self, dim_actions, n_actions):
     if (dim_actions == 6):
         action_choice = [0.3, 0, -0.3]
         action_list = util.permutate([],[] , action_choice, dim_actions)
     else:
         action_choice = [0.5,0,  -0.5]
         action_list = util.permutate([],[] , action_choice, dim_actions)
     return action_list
Ejemplo n.º 2
0
from util import word_in_dict

#dict to hold all words
d_words = load_word_dictionary()

#dict to hold all words of length 6 with letter q
d_6q_words = dict()
for word in d_words:
    if has_string(word, 'q') and is_len(word, 6):
        d_6q_words[word]=None

#dict to hold all words of length with letter q, and 'q' swapped for 'n'
d_6n_words = dict()
for word in d_6q_words:
    new_word = swap_letter(word,'n',word.find('q'))
    d_6n_words[new_word] = word

for word in d_6n_words:
    #get all anagrams of words with q already swapped for n
    l_perm = permutate(word)
    s_perm = set(l_perm)

    for j in s_perm:
        #for each anagram, see if anagram is in dictionary
        if word_in_dict(j, d_words):
            q_word = d_6n_words[word ]
            n_word = j
            #if anagram in dictionary, use WordNet functionality to see if q_word and n_word are synonyms
            if check_synonym( q_word, n_word):
                print 'Orig q-word:%s, New n-word:%s' % (q_word, n_word)
Ejemplo n.º 3
0
from util import load_word_dictionary
from util import swap_letter
from util import permutate
from util import word_in_dict

# string from a to g
s = 'abcdefg'

l_words = list()

# loads word list into dict()
d_dict = load_word_dictionary()

#creates list of possible words when swapping one letter from 'abcdefg'
for i in range(0, len(s)):
    for j in range(0, len(s)):
        # i == j just reproduces original string
        if i <> j :
            swap_word = swap_letter(s, s[i], j) 
            l_words.append( swap_word )

#tests all permutations and checks if permutation of string is in dictionary and prints any finds
for i in l_words:
    l_perm = permutate(i)
    s_perm = set(l_perm)
    for j in s_perm:
        if word_in_dict(j, d_dict):
            print "Original String:\t%s" % ( i,) 
            print "Rearranged String:\t%s" % (j,)