Пример #1
0
def main():
    word_list = load_dictionary.load('words.txt')
    trigrams = load_dictionary.load('least-likely_trigrams.txt')
    name = get_user_input()
    words = prep_words(name, word_list)
    cv_mapped = cv_map_words(words)
    filtered = cv_map_filter(name, cv_mapped)
    candidates = trigram_filter(filtered, trigrams)
    candidates = digram_filter(candidates)
    view_by_letter(candidates)
    try_again(candidates)
def main():
    """Load files, run filters, allow user to view anagrams by the 1st letter."""
    name = 'tmvoordle'
    name = name.lower()

    word_list_ini = load_dictionary.load('words.txt')
    trigrams_filtered = load_dictionary.load('least-likely_trigrams.txt')

    word_list = prep_words(name, word_list_ini)
    filtered_cv_map = cv_map_words(word_list)
    filter_1 = cv_map_words(word_list)
    filter_2 = trigram_filter(filter_1, trigrams_filtered)
    filter_3 = letter_pair_filter(filter_2)
    view_by_letter(name, filter_3)
Пример #3
0
def main():
    """Call funtions to limit the anagrams and help the user find one."""
    name = "tmvoordle"
    name = name.lower()

    word_list = load_dictionary.load("dictionary.txt")
    bad_trigrams = load_dictionary.load("least_likely_trigrams.txt")

    word_list = prep_words(name, word_list)
    filtered_cv_map = cv_map_words(word_list)
    filter_1 = cv_map_filter(name, filtered_cv_map)
    filter_2 = trigram_filter(filter_1, bad_trigrams)
    filter_3 = digram_filter(filter_2)
    view_by_letter(name, filter_3)
def main():
    """Read file, filter them, and User can see anagrams at the first character"""
    name = 'tmvoordle'
    name = name.lower()

    word_list_ini = load_dictionary.load('2of4brif.txt')

    trigrams_filtered = load_dictionary.load('least-likely_trigrams.txt')

    word_list = prep_words(name, word_list_ini)
    filtered_cv_map = cv_map_words(word_list)
    filter_1 = cv_map_filter(name, filtered_cv_map)
    filter_2 = trigram_filter(filter_1, trigrams_filtered)
    filter_3 = letter_pair_filter(filter_2)
    view_by_letter(name, filter_3)
def main():
    """Find palingrams and print them."""
    words = load_dictionary.load("../../dictionary.txt")
    words = dictionary_cleanup.single_letters_removed(words)
    words = set(words)
    to_print = find_palingrams(words)
    print("\n".join(sorted(to_print)))
def main():
    dictfile = load(args['dictionary'])
    len_dictfile = len(dictfile)
    with open('missing_words.json') as f:
        missing_words = json.load(f)
    print("Welcome to Dictionary Syllable Counter.")
    print(
        "Enter the number of random words to count syllables for, else press Enter to exit:"
    )
    while True:
        n_words = input()
        if n_words == '':
            sys.exit(1)
        if not n_words.isdigit():
            print("Enter the number instead of a character.")
        if int(n_words) > len_dictfile:
            print("Sample size larger than dictionary. Pick a smaller number.")
            continue
        words = random.sample(dictfile, int(n_words))
        for word in words:
            try:
                num_syllables = count_syllables(word)
                print("{}: {}".format(word, num_syllables))
            except KeyError:
                print("{} not found.".format(word), file=sys.stderr)
def fill_dummy_words(textlist):
    """Fills the bottom row with random dummy words"""
    len_cipher = len(textlist)
    dict_list = load_dictionary.load("dict.txt")
    compare = ROWS * COLS
    if compare != len_cipher and compare > len_cipher:
        for i in range(compare - len_cipher):
            textlist.append(random.choice(dict_list).upper())
Пример #8
0
def main():
    """Call funtions to limit the anagrams and help the user find one."""
    name = "tmvoordle"
    name = name.lower()

    word_list = load_dictionary.load("dictionary.txt")

    freqs = enumerate_digrams(word_list)
    print_counts(name, freqs)
Пример #9
0
def main():
    word_list = load_dictionary.load('2of4brif.txt')
    pali_list = []

    for word in word_list:
        if len(word) > 1 and word == word[::-1]:
            pali_list.append(word)

    print("\nNumber of palindromes found =", len(pali_list))
    print(*pali_list, sep='\n')
def main():
    """Print all the palindromes in the dictionary."""
    word_list = sorted(set(load_dictionary.load('../../dictionary.txt')))
    pali_list = []
    for word in word_list:
        if len(word) > 1 and pali_check(word):
            pali_list.append(word)

    print("\nNumber of palindromes found = {}\n".format(len(pali_list)))
    print(*pali_list, sep='\n')
Пример #11
0
def main(file_path):  #file path or file_name for current dir
    """The main function to find palindromes"""
    words = load_dictionary.load(file_path)
    palindromes_list = []

    for word in words:
        if len(word) > 1 and word == word[::-1]:
            palindromes_list.append(word)

    print(f"No of palindromes found {len(palindromes_list)} ")
    print(palindromes_list, sep='\n')
Пример #12
0
def find_palingrams():
    """Return a list of space spearated word pairs that are palingrams."""
    words = sorted(set(load_dictionary.load("dictionary.txt")))
    palingrams = []
    for word in words:
        if len(word) > 1:
            for i in range(1, len(word)):
                if word[i:] == word[i:][::-1] and word[:i][::-1] in words:
                    palingrams.append(" ".join([word, word[:i][::-1]]))
                if word[:i] == word[:i][::-1] and word[i:][::-1] in words:
                    palingrams.append(" ".join([word[i:][::-1], word]))
    return palingrams
Пример #13
0
def main():
    """Wczytuje plik ze slownikiem wykorzystujac modul load_directory,
        nastepnie znajduje palindromy i zapisuje je do listy."""
    word_list = load_dictionary.load("2of4brif.txt")
    palindrome_list = []

    for word in word_list:
        if len(word) > 1 and word == word[::-1]:
            palindrome_list.append(word)

    print("\nNumber of palindromes found: {}\n".format(len(palindrome_list)))
    print(*palindrome_list, sep="\n")
def main():
    """Call functions to show the user their anagrams."""
    phrase, min_word_size = get_user_input()
    phrase = list(phrase)

    word_list = load_dictionary.load("dictionary.txt")
    word_list = set([word for word in word_list if len(word) >= min_word_size])
    word_list = get_sub_anagrams(phrase, word_list)

    anagrams = get_anagrams(phrase, word_list, phrase.copy())
    print(anagrams)
    to_print = min(500, len(anagrams))
    for anagram in anagrams[0:to_print]:
        print(" ".join(anagram))
Пример #15
0
def find_palingrams():
    file = "2of4brif.txt"
    word_list = load_dictionary.load(file)
    pali_list = []

    for word in word_list:
        end = len(word)
        rev_word = word[::-1]
        if end > 1:
            for i in range(end):
                if word[i:] == rev_word[: end - i] and rev_word[end - i :] in word_list:
                    pali_list.append((word, rev_word[end - i :]))
                if word[:i] == rev_word[end - i :] and rev_word[: end - i] in word_list:
                    pali_list.append((rev_word[: end - i], word))
    return pali_list
Пример #16
0
def find_palingrams(file):
    path = Path.cwd() / 'palingram' / file
    master = set(load_dictionary.load(path))
    palingrams = []
    for word in master:
        end = len(word)
        rev_word = word[::-1]
        if end > 1:
            for i in range(end):
                if word[i:] == rev_word[:end - i] and rev_word[end -
                                                               i:] in master:
                    palingrams.append((word, rev_word[end - i:]))
                if word[:i] == rev_word[end - i:] and rev_word[:end -
                                                               i] in master:
                    palingrams.append((rev_word[:end - i], word))
    return palingrams
def list_cipher(message, n):
    """Create a vocabulary list.
    
    The nth char in each word reads the message.
    """
    dictionary = load_dictionary.load("dictionary.txt")
    random.shuffle(dictionary)
    message = "".join(message.split()).lower()
    vocab = []
    for letter in message:
        for word in dictionary:
            if len(word) > 6:
                if word[n] == letter and word not in vocab:
                    vocab.append(word)
                    break
    return vocab
Пример #18
0
def main():
    file = "2of4brif.txt"
    words = load_dictionary.load(file)
    palindromes = []
    for w in words:
        if len(w) > 1 and w == w[::-1]:
            palindromes.append(w)
    print("\nNumber of palindromes found = {}\n".format(len(palindromes)))
    """ 
        You can use the splat operator (designated by
        the *), which takes a list as input and expands it into positional arguments in the
        function call. The last argument is the separator used between multiple list values for
        printing. The default separator is a space (sep=' '), but instead, print each item on a new
        line (sep='\n').
    """

    print(*palindromes, sep="\n")
Пример #19
0
def main():
    word_list = load_dictionary.load('words.txt')
    print("Iterate method:")
    pali_list = []
    for entry in word_list:
        if len(entry) > 1 and entry == entry[::-1]:
            pali_list.append(entry)
    print(f"\nNumber of palindromes found = {len(pali_list)}\n")
    print(*pali_list, sep=', ')

    print("\nRecursive method")
    pali_list = []
    for entry in word_list:
        if is_palindrome(entry):
            pali_list.append(entry)
    print(f"\nNumber of palindromes found = {len(pali_list)}\n")
    print(*pali_list, sep=', ')
def main():
    """Ask the user for a word and print the anagrams."""
    words = set(load_dictionary.load("dictionary.txt"))
    while True:
        query_word = input("\ngizzus a word\n")
        query = sorted(query_word)
        anagrams = []
        for word in words:
            if word != query_word:
                if is_anagram(query, word):
                    anagrams.append(word)

        print("\nAnagrams:\n" + "\n".join(anagrams))

        choice = input("\nPlay again?\n")
        if choice.lower() in ["n", "no", "q", "quit"]:
            exit()
Пример #21
0
def find_anagrams():

    word_list = load_dictionary.load('2of4brif.txt')
    anagram_list = []

    name = 'dog'
    name = name.lower()
    name_sorted = sorted(name)

    for word in word_list:
        word = word.lower()
        if word != name and sorted(word) == name_sorted:
            anagram_list.append(word)

    if len(anagram_list) == 0:
        print("None anagrams found")
    else:
        print(f"Anagrams: {anagram_list}")
Пример #22
0
def main():

    dict_file = load_dictionary.load('english_dict.txt')  # upload dict

    comb_2_let = perm_2_let()

    dict_2_let = build_2l_dic(dict_file, comb_2_let)

    # prompt for word length
    w_length = int(input("\nEnter desired length: "))
    # prompt for word amount
    w_amount = int(input("Enter desired amount of words to generate: "))

    nword_list_m2 = w_mark2_gen(w_amount, w_length, dict_2_let)

    # prints words build with Markov order 2
    print("\nHere is the list of new words: ")
    pprint.pprint(nword_list_m2)
Пример #23
0
def main():
    """Load words, format name, get anagrams and print first no more 500 phrases."""
    dict_file = load_dictionary.load('words.txt')

    # ensure "a" & "I" are included
    dict_file.append('a')
    dict_file.append('i')

    dict_file = sorted(dict_file)

    ini_name = input("Enter a name: ")
    name = ''.join(
        ini_name.lower().split())  # remove spaces & convert to lower case
    name = name.replace('-', '')  # remove hyphens in hyphenated names

    phrases = phrases_gen(name, dict_file)
    print(len(phrases))

    for i in range(500 if len(phrases) > 500 else len(phrases)):
        print(phrases[i])
Пример #24
0
def solve_anagram():

    # load dictionary list
    dictionary_list = load_dictionary.load('words.txt')

    # accept word from user & change to lowercase
    user_word = input('Type a word: ').lower()

    # empty list to hold anagrams
    anagram_list = []

    # sort user input word
    user_word_sorted = sorted(user_word)

    # loop through each word in list:
    for word in dictionary_list:

        # do not add to anagram list if it matches user word
        if word != user_word:
            # sort each word
            sorted_word = sorted(word)

            # if word sorted is equal to user word sorted:
            if sorted_word == user_word_sorted:
                # append unsorted word to anagram list
                anagram_list.append(word)

    # print anagram list
    # if no matches - try a different word
    if len(anagram_list) == 0:
        print('Try a different word')
        solve_anagram()
    else:
        print(anagram_list)

    # ask user to play again
    play_again = input('Would you like to play again? [y/n] ').lower()
    if play_again == 'y':
        solve_anagram()
    else:
        sys.exit()
Пример #25
0
    def test_trigramFilterRemovesPermsWithUnlikelyTrigrams(self):
        candidates = {
            'dosl', 'dlos', 'ldos', 'odsl', 'olds', 'slod', 'dlso', 'ldso',
            'sldo', 'osdl', 'lsdo', 'sdol', 'dsol', 'dols', 'lods', 'osld',
            'odls', 'sdlo', 'sodl', 'losd', 'sold', 'lsod', 'olsd', 'dslo'
        }
        trigrams = load_dictionary.load('least-likely_trigrams.txt')
        expected = set([
            'ldso', 'ldos', 'dslo', 'olsd', 'sldo', 'lsod', 'olds', 'osdl',
            'sold', 'lsdo', 'dlso', 'losd', 'dosl', 'sdlo', 'dsol', 'osld',
            'odsl', 'dlos'
        ])
        expected_len_list = f'# choices after trigram_filter = {len(expected)}'

        with captured_output() as (out, err):
            actual = bruteforce_anagrams.trigram_filter(candidates, trigrams)
        len_list = out.getvalue().strip('\n')
        error = err.getvalue()
        self.assertSetEqual(actual, expected)
        self.assertEqual(len_list, expected_len_list)
        self.assertFalse(error)
Пример #26
0
def main():
    import load_dictionary as ld
    word_list = ld.load('common_words.txt')
    
    # Define a minimum baseword length to produce more interesting results
    min_base_len = 2
    test_list = [i for i in word_list if len(i)>=min_base_len]
    pali_list = []
    word_list = set(word_list)
    for tmp_word in test_list[:]:
        end = len(tmp_word)
        #rev_word = tmp_word[::-1]
        for i in range(end):
            if tmp_word[i::-1] in word_list and ispalindrome(tmp_word[(i+1):]):
                pali_list.append(tmp_word+' '+tmp_word[i::-1])
                print(pali_list[-1])
            if tmp_word[-1:-(2+i):-1] in word_list and ispalindrome(tmp_word[:-(i+1)]):
                pali_list.append(tmp_word[-1:-(2+i):-1]+' '+tmp_word)
                print(pali_list[-1])
    
    print("There were {} word-pair palingrams found!".format(len(pali_list)))
def main():
    ini_name = input('Enter a name: ')
    dict_file = load_dictionary.load('2of4brif.txt')
    dict_file.append('a')
    dict_file.append('I')
    ini_word_list = dict_file

    name = ''.join(ini_name.lower().split())
    name = name.replace('-', '')
    phrase = ''
    ini_name_anagrams = []
    not_ini_anagrams = []

    for i in range(10000):
        ini_anagram = ''
        ini_anagram = create_anagram_list(name, phrase, dict_file,
                                          ini_name_anagrams, ini_anagram,
                                          ini_word_list, not_ini_anagrams)
        if ini_anagram != '' and ini_anagram in ini_word_list:
            ini_word_list.remove(ini_anagram)
        print(ini_name_anagrams)
    print(ini_name_anagrams[:500])
Пример #28
0
def main():
    """Generate names with MESSAGE embedded"""
    user_message = input("What is your message to encrypt? ")
    # open dictionary file
    name_list = load_dictionary.load("supporters.txt")
    # prep and parse MESSAGE for comparison process
    message = ''
    for char in user_message.lower():
        if char in string.ascii_letters:
            message += char
    message = ''.join(message.split())
    output_names = []
    is_even = True  # tracks when to switch between odd/even for char comparison
    for letter in message:
        for i in range(0, len(name_list)):
            # grabs random name from list
            name = name_list[randint(0, len(name_list) - 1)]
            # adds first name without starting process
            if len(output_names) == 0:
                pos = randint(0, len(name_list))
                output_names.append(name_list[pos])
            if is_even is True and letter == name[
                    1] and name not in output_names:
                output_names.append(name)
                is_even = False
                break
            elif is_even is False and letter == name[
                    2] and name not in output_names:
                output_names.append(name)
                is_even = True
                break
    # place null names in random index of output_names
    output_names.insert(randint(0, len(output_names)), NAME1)
    output_names.insert(randint(0, len(output_names)), NAME2)
    # display whole message
    print(FAKE_TEXT)
    for name in output_names:
        print(name)
Пример #29
0
def main():
    # Load the dictionary file
    word_list = ld.load('corncob_lowercase.txt')
    
    # Accept a word from the user
    user_word = input("\nInput a word to find the anagrams: ")
    # Sort the user-word
    user_word_srt = sorted(user_word)
    
    # Create an empty list to hold the anagrams
    anagrams_list = []
    # Loop through each word in the word list
    for check_word in word_list[:]:
        # Sort the word
        check_word_srt = sorted(check_word)
        
        # Check to see if sorted word is equal to the sorted user-word 
        if check_word_srt == user_word_srt and check_word != user_word:
            # Append to list of anagrams
            anagrams_list.append(check_word)
    
    # Print list of anagrams
    print(anagrams_list)
def main():
    """load word list. prep text. look for words to put them in
    and add them to the list. print"""
    dictionary = load("words.txt")
    word_list = []
    plaintext = list(PLAINTEXT.lower().strip().replace(" ", ""))
    letters_after = LETTERS_AFTER - 1  # Align to 0-index
    temp_list = []
    for word in (w for w in dictionary if len(w) > LETTERS_AFTER):
        if word[letters_after] == plaintext[0]:
            temp_list.append(word)
        if len(temp_list) == 10:
            word_list.append(random.choice(temp_list))
            temp_list.clear()
            plaintext.pop(0)
            if len(plaintext) == 0:
                break
    if len(plaintext) > 0:
        print("Couldn't find enough words!")
        return
    print("\nPlaintext\n")
    print(PLAINTEXT)
    print("\nEncoded as vocabulary list\n")
    print(*word_list, sep="\n")
"""
Find all word-pair palingrams in a dictionary file
"""
import time
import load_dictionary

start_time = time.time()
word_list = load_dictionary.load('words.txt')


def find_palingrams():
    """
    Find dictionary palingrams
    :return: a list of word-pairs which are palindromes
    """

    palingram_list = []
    words = set(word_list)
    for word in words:
        end = len(word)
        rev_word = ''.join(reversed(word))
        if end > 1:
            for i in range(end):
                if word[i:] == rev_word[:end-i] and rev_word[end-i:] in words:
                    palingram_list.append((word, rev_word[end-i:]))
                if word[i:] == rev_word[end-i:] and rev_word[:end-i] in words:
                    palingram_list.append((rev_word[:end-i], word))
    return palingram_list


palingrams = find_palingrams()