コード例 #1
0
	def initialize_dictionary(self):
		#instantiate a word dictionary containing n letter words
		self.dictionary = wordlist(WORDLIST)
		self.dictionary.filter_n_chars(self.width)
		if not self.startword:
			self.startword = self.dictionary.get_random()
		else:
			#check validity of our starting word
			if not self.dictionary.in_dictionary(self.startword):
				raise ValueError("startword must already be in the dictionary file you chose.")
コード例 #2
0
import json
from twitter import Twitter, OAuth, TwitterHTTPError
from time import sleep
from sys import exit
from random import choice

try:
    import config
except ImportError as e:
    print("ERROR: Could not import config. Make sure config.py exists.")

try:
    from wordlist import wordlist

    if config.LANGUAGE:
        WORDLIST = wordlist(config.LANGUAGE)
except ImportError:
    WORDLIST = [
        ['The space'],
        ['is'],
        ['open'],
        ['closed'],
        [''],
        ['']
    ]

try:
    twitter = Twitter(auth=OAuth(
                            config.OAUTH_TOKEN,
                            config.OAUTH_SECRET,
                            config.CONSUMER_KEY,
コード例 #3
0
ファイル: distancechart.py プロジェクト: anneCarlson/Igbo
import sys
import math
import re
import wordlist

def distancechart(wordlist,outfile):
    output = open(outfile,'w')
    distances = {}
    sorted_wordlist = sorted(wordlist)
    for first_coords in sorted_wordlist:
        first_coord_list = re.split('[,\n]',first_coords)
        first_latitude = float(first_coord_list[0])
        first_longitude = float(first_coord_list[1])
        for second_coords in sorted_wordlist:
            second_coord_list = re.split('[,\n]',second_coords)
            second_latitude = float(second_coord_list[0])
            second_longitude = float(second_coord_list[1])

            latitude_difference = second_latitude-first_latitude
            longitude_difference = second_longitude-first_longitude
            pythagorean_distance = math.sqrt(math.pow(latitude_difference,2) + math.pow(longitude_difference,2))
            if pythagorean_distance > 0:
                distances[pythagorean_distance] = ((first_latitude,first_longitude),(second_latitude,second_longitude))

    for distance in sorted(distances):
        coordinate_pair = distances[distance]
        output.write('(' + str(coordinate_pair[0][0]) + ',' + str(coordinate_pair[0][1]) + '), (' + str(coordinate_pair[1][0]) + ',' + str(coordinate_pair[1][1]) + ')\t' + str(distance) + '\n')

if __name__ == '__main__':
    distancechart(wordlist.wordlist(sys.argv[1]),sys.argv[2])
コード例 #4
0
import submapping
import wordlist
import message
import levenshtein

word_list = wordlist.wordlist()
coded_message = message.message()
solution = {}

ordered_message = coded_message.getorderedcodedwords()

for coded_word in ordered_message:
	coded_word_len = len(coded_word)
	
	known = set(solution.keys())
	unknown = set(coded_word)
	if len(unknown - known) == 0:
		print
		print "coded word already known: " + str(coded_word) + " -> " + coded_message.decodeword(coded_word, solution)
		continue
	
	filtered_word_list = word_list.getfilteredlist(coded_word)
	if len(filtered_word_list) == 1:
		partial_mapping = word_list.convertmatchtomapping(coded_word, filtered_word_list[0])
		print filtered_word_list[0]
		newly_known = set(partial_mapping.keys()) - set(solution.keys())
		for key in newly_known:
			if partial_mapping[key] not in set(solution.values()):
				solution[key] = partial_mapping[key]                  	
	else:
		solver = submapping.ga(solution, filtered_word_list)
コード例 #5
0
ファイル: comparelists.py プロジェクト: anneCarlson/Igbo
def write_dictionary(first_town, second_town, distance_info, maximum_distance, outfile):
    distance_dictionary = distance_info[0]
    avg_min_dist = distance_info[1]
    output = codecs.open(outfile,'w',encoding='utf-8')
    output.write('Comparison: ' + first_town + ' and ' + second_town + ' (' + str(avg_min_dist) + ')\n')
    for distance in distance_dictionary:
        if distance <= maximum_distance:
            output.write('\n' + str(distance) + ' changes:\n')
            paths = distance_dictionary[distance]
            for path in sorted(paths, key=lambda k: -len(paths[k])):
                output.write('\t\t' + path + '\t(' + str(len(paths[path])) + ')\n')
                for pair in paths[path]:
                    if True:
                    #not (pair[0].encode('utf-8') in worddict[second_town+'\n'] and pair[1].encode('utf-8') in worddict[first_town+'\n']):
                        output.write(path + '\t' + pair[0] + ', ' + pair[1] + '\n')

def represent_path(path):
    representation = ''
    for change in path:
        if change[0] == None:
            representation += '[-' + change[1] + ']'
        elif change[1] == None:
            representation += '[+' + change[0] + ']'
        else:
            representation += '[' + change[0] + change[1] + ']'
    return representation

if __name__ == '__main__':
    worddict = wordlist.wordlist(sys.argv[1])
    write_dictionary(sys.argv[2], sys.argv[3], compare(sys.argv[2]+'\n', sys.argv[3]+'\n'), int(sys.argv[5]), sys.argv[4])