Featured Posts

World Cup The 2010 FIFA World Cup has started and I wanted to pay my respects to the sport by posting a few videos from my childhood that sum up my own soccer career.  Many thanks goes out to my Uncle Gary, who...

Read more

Pattern Recgonition In Pragmatic Thinking & Learning: Refactor Your Wetware, Andy Hunt gives several great examples of situations in which the brain takes input from one source and repackages the information into a context...

Read more

Pattern Recgonition

Posted by MikeWade | Posted in Artificial Intelligence, Whatever Whatever. | Posted on 01-07-2009

Tags: , ,

0

In Pragmatic Thinking & Learning: Refactor Your Wetware, Andy Hunt gives several great examples of situations in which the brain takes input from one source and repackages the information into a context that we understand.  My favorite example is the following sentence:

“Cna yuo raed tihs?” (p. 102)

No problem, right? That’s because your brain is processing the words individually and repackaging the characters into an order that would make sense given the context. Fascinating.  Oru abiltiy to ientrerpt centoxt at all is faaicnnstig, btu to go boeynd taht by re-irpretninetg rdnaom inupt into snesbile inupt is slpimy a ctaunmopiotal mlcarie.  Just imnaige teh moremy adn caompuaotnitl poewr nedeed to mcath ecah grnpiuog of lreetts to a pirmutaoeun taht hsa mnnieag in a gevin context…  It wuold be iimpssbole to srtoe teh wrod contbimniaos into memroy on most merdon coputerms, even if we liietmd wodrs to a mmiaxum of 10 leterts.

What’s more interesting is how this type of peripheral and contextual synthesis is not limited to a singular sense, but rather applies to all of our senses.  Stare directly into the face of someone you love (or a complete stranger) and you’ll eventually come to the conclusion that you recgonize every wrinkle.  Allow me to ruin that moment forever with a simple demonstration.  Sit back in your chair, close your left eye, and stare at the smily face with your right.  Ever so carefully, move forward while staring at the smily and eventually the frowny face will disappear.  Should happen when you’re about a foot from the screen.  It reappears as you move closer so don’t get too excited..
:) :(

Cna yuo bilevee that just haepnped!!??!  All these years your brain has filled in the blind spots with interpretations of what it thinks should be.  Words, sight, hearing, taste, feelings; everything is interpreted.  With that being the case, I’m not the least bit surprised that our world is constantly at war with itself when the first event we are given to interpret is a painful eviction followed by a stern smack on the ass.

As a tribute to Andy Hunt’s example, I baked up some fresh python code to create this effect from a text file. It’s also what I used to create parts of this blog.  Enojy!

# file: scramble.py
# poet: Michael Wade
# idea: Mix up the characters of words, but keep the first and last the same.
# The effect should be something along the lines of:
# Cna yuo raed tihs?  -- Andy Hunt, Pragmatic Thinking & Learning
import sys, getopt, random;

# scramble()
# Post: Randomizes the ordering of characters between the first
#       and last letter of a given input word.
def scramble(word):
    if len(word) <= 2:
        return word;
    elif len(word) == 3:
        word = word[0] + word[2] + word[1];
    else:
        # Need to leave any punctuation in place..
        last = len(word);
        end = word[len(word)-1];
        if end in "!?.,;":
            last = len(word)-1;
        else:
            last = len(word);
            end = '';

        # Hyphens are a special case..
        if "-" in word:
            splitWord = word.split("-");
            return scramble(splitWord[0]) + "-" + scramble(splitWord[1]);

        # Randomize the middle part
        middlePart = str(word[1:(last-1)]);
        middlePart = ''.join(random.sample(middlePart, len(middlePart)));

        # Bring it all back together.
        word = word[0] + middlePart + word[last-1] + end;

    return word;

if __name__ == "__main__":

    # First arguement MUST be a filename.
    if len(sys.argv) < 2:
        print "Please specify a text file like so:"
        print "python scramble.py myFile.txt"
    else:
        inputFile = ""; # Default to a blank filename
        try:
            inputFile = open(sys.argv[1],"r")
        except IOError:
            print "Error opening file:", sys.argv[1]
            sys.exit(2)

        # Each line in the file needs to be broken into words.
        for line in inputFile:
            scrambledLine = "";
            words = line.split(" ");

            # Each word needs to be scrambled.
            for word in words:
                scrambledLine += scramble(word) + " "

            # Each line needs to be reprinted
            print scrambledLine

        # Close the file
        inputFile.close();
Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Write a comment