def main(): path_dict = '/home/idris/word_lists/CROSSWD.TXT' d_word_list = load_word_dictionary( path_dict ) l_words_end_s = [word for word in d_word_list if ends_with_letter(word, 's')] path_output = 'output.txt' fout = open(path_output, 'w') #go through list of words ending with s for word_end_s in l_words_end_s: #go through list of ways to split word_ending_with_s for splits in split_word_once( word_end_s ): if word_in_dict(splits[0], d_word_list) and word_in_dict(splits[1], d_word_list): s = '%s, %s %s\n' % (word_end_s, splits[0], splits[1]) syn_test = '%s_%s' % (splits[0], splits[1]) l_syns = check_synonym(word_end_s, syn_test) fout.write(s)
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)