Permalink
Browse files

Added documentation

  • Loading branch information...
1 parent 2d867d0 commit dfcd26f6130f671c8459f2885952bd5fde826131 @maddenpj committed Aug 29, 2012
Showing with 15 additions and 6 deletions.
  1. +15 −6 mc-d.py
View
21 mc-d.py
@@ -6,24 +6,33 @@
trainingData = open('./Data.txt').readlines()
-table = {} #lol will get massive
+# Used for storing the Markov states
+table = {}
-data = []
+# Stores all the words
words = []
+# The size of the tuple that represents the Markov State
ChainLength = 2
+# Length of hte output chain
Size = int(sys.argv[1])
if(len(sys.argv) >= 3): ChainLength = int(sys.argv[2])
-
+# Read in data and split into words
for line in trainingData:
for word in line.split():
- word = word.translate(string.maketrans("",""), string.punctuation)
+ #word = word.translate(string.maketrans("",""), string.punctuation)
words.append(word)
-
+# For each set of words
for idx in xrange(0,len(words)-ChainLength):
+ # Now we have ChainLength+1 amount of words
ws = words[idx:idx+ChainLength+1]
+ # Construct our table
+ # For example Chain Lenght of 2
+ # A valid key val pair would be
+ # table[('see', 'spot')] = ['run','play']
+ # Indicating that if you are in teh state of ('see', 'spot') the next word has a 50% chance of being run and a 50% chance of being play
key = tuple(ws[:ChainLength])
val = ws[ChainLength]
if key in table:
@@ -35,9 +44,9 @@
seed = random.randint(0, len(words)-ChainLength+1)
ws = words[seed:seed+ChainLength]
gen = []
-
for i in xrange(0,int(sys.argv[1])):
gen.append(ws[0])
+ # Actually find the next word randomally given the current state Ie: the tuple of words
val = random.choice(table[tuple(ws)])
ws.append(val)
ws.pop(0)

0 comments on commit dfcd26f

Please sign in to comment.