Pattern Recgonition
Posted by MikeWade | Posted in Artificial Intelligence, Whatever Whatever. | Posted on 01-07-2009
Tags: patterns, philosophy, vision
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.
| |
|
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();















