from utils import print_sorted_dict from os import path if __name__ == '__main__': w1 = WebPage( url="http://automotive.about.com/b/2012/06/14/how-to-become-a-new-car-dealer.htm" ) w2 = WebPage( url="http://ipod.about.com/od/KidsiPhoneiPodTouch/tp/Roadtrips-With-Iphone-And-Apps.htm" ) print "Text Similarity for w1 and w2" comparsion = w1.get_text_similarity(w2) print "Result: ", comparsion.similarity_result print "Important categories:" for cat in comparsion.important_categories: print cat print_sorted_dict(w1.content.categories_membership, "car") print_sorted_dict(w2.content.categories_membership, "ipod") print("\nMany images:") comparsion = w1.get_image_similatiry(w2) print "Result: ", comparsion.similarity_result print "Pictures with each other:" for pair, result in comparsion.image_pairs_results.items(): first, sec = map(lambda x: path.split(x)[-1], pair) print "{} : {} is {}".format(first, sec, result)
def process_command(command): """ Processes a command. Valids commands are as follows: - `create <name>` - `feed <name>` - `play <name>` - `wait` An invalid command will result in an error message "Invalid command." being printed to the console; Tamagotchi's that have not been created will cause error message "No Tamagotchi with that name." being printed to the console; using the `create` command with the name of an existing Tamagotchi will cause error message "You already have a Tamagotchi called that." being printed to the console. :param command: The command to process. Note that this command must be a valid command as specified above. Non-valid commands will result in a variety of error messages being printed. :type command: string """ # Start by splitting command into words command = command.split() # Parse command => identify first word in command if command[0] == 'create' and len(command) == 2: # If command is create, check if a Tamagotchi with that name already exists if command[1] in db.pets.keys(): # If it exists, check if it is still alive if not db.pets[command[1]].is_dead(): # If not dead, print error message and exit (do nothing) print('You already have a Tamagotchi called that.') return # If it doesn't already exist or is dead, create a new one db.pets[command[1]] = Tamagotchi(command[1]) elif command[0] == 'feed' and len(command) == 2: # If command is feed, check if Tamagotchi with that name already exists if command[1] not in db.pets.keys(): # If it doesn't exist, print error message and exit (do nothing) print('No Tamagotchi with that name.') return # If it exists, call feed method db.pets[command[1]].feed() elif command[0] == 'play' and len(command) == 2: # If command is play, check if Tamagotchi with that name already exists if command[1] not in db.pets.keys(): # If it doesn't exist, print error message and exit (do nothing) print('No Tamagotchi with that name.') return # If it exits, call play method db.pets[command[1]].play() elif command[0] == 'wait' and len(command) == 1: # If command is wait, do nothing and pass time pass else: # Print error message and exit (do nothing) print('Invalid command.') return # After the command has been processed, display current state of all # Tamagotchi's in NAME SORTED ORDER and increment time # Start by printing the pets sorted by alphabetical order print_sorted_dict(db.pets) # Call increment time method on all Tamagotchi's increment_time()
from glob import glob from os import path if __name__ == '__main__': ad1 = AnalizedDocument.from_file("./data/test_doc") ad2 = AnalizedDocument.from_file("./data/test_doc2") print "Text Similarity for ad1 and ad2" comparsion = ad1.compare(ad2) print "Result: ", comparsion.similarity_result print "Important categories:" for cat in comparsion.important_categories: print cat print_sorted_dict(ad1.categories_membership, "test_doc") print_sorted_dict(ad2.categories_membership, "test_doc2") print "Two images:" im1 = Image.open("./data/red.jpg") im2 = Image.open("./data/pom.png") print compare(im1, im2) print "Many images:" first_group = glob("./data/test_a/*") sec_group = glob("./data/test_b/*") creator = lambda x: (x, Image.open(x)) comparsion = compare_many(map(creator, first_group), map(creator, sec_group)) print "Result: ", comparsion.similarity_result print "Pictures with each other:"