Skip to content

Commit

Permalink
minor formatting, documentation changes; added shebang to executables
Browse files Browse the repository at this point in the history
  • Loading branch information
Cathy Wu committed Nov 26, 2011
1 parent 9c980f6 commit 40a40e6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
2 changes: 2 additions & 0 deletions classifier.py 100644 → 100755
@@ -1,3 +1,5 @@
#!/usr/bin/python

import random
import data
from numpy import *
Expand Down
Empty file modified data.py 100644 → 100755
Empty file.
2 changes: 2 additions & 0 deletions movie.py 100644 → 100755
@@ -1,3 +1,5 @@
#!/usr/bin/python

import data
import ngrams
import validate
Expand Down
19 changes: 11 additions & 8 deletions ngrams.py 100644 → 100755
@@ -1,6 +1,9 @@
#!/usr/bin/python

import collections
import data
from numpy import *

def words(s):
words = []
current = ""
Expand Down Expand Up @@ -50,17 +53,17 @@ def ngrams_range(b, e, s):
return g

def ngrams_to_matrix(grams, classes):
print "a"
print "Entering ngrams_to_matrix"
keysets = [set(k) for k in grams]
allgramset = set()
print "b"
print "> Sets created"
for k in keysets:
allgramset = allgramset.union(k)
print "c"
print "> Sets unioned"
allgrams = list(allgramset)
print "d"
print "> Listed"
vecs = []
print "e"
print "> []"
allgramsdict = {}
for i in range(len(allgrams)):
allgramsdict[allgrams[i]] = i
Expand All @@ -80,9 +83,9 @@ def ngram_vector(n, s, dictionary):
return array(vec)

if __name__ == "__main__":
print ngrams(3, "Now is the time for all good men to not come to the aid of their party! Now is the time for all bad women to leave the aid of their country? This, being war, is bad")
print "Trigram example: %s" % ngrams(3, "Now is the time for all good men to not come to the aid of their party! Now is the time for all bad women to leave the aid of their country? This, being war, is bad")
g1 = ngrams(1, "Hello how are you")
g2 = ngrams(1, "Are you feeling well")
g3 = ngrams(1, "Well hello there")
print g3
print ngrams_to_matrix([g1, g2, g3], [1, 2, 1]).asMatrix()
print "Unigram example: %s" % g3
print "Matrix example: %s" % ngrams_to_matrix([g1, g2, g3], [1, 2, 1]).asMatrix()
25 changes: 13 additions & 12 deletions validate.py 100644 → 100755
@@ -1,3 +1,5 @@
#!/usr/bin/python

import classifier
import data
from numpy import *
Expand Down Expand Up @@ -31,20 +33,19 @@ def errorrate(classif, testdata):
error += 1
return (error, count)


if __name__ == "__main__":
d = data.Data(data.DefDict((), {
(1,2,3) : (1,),
(3,3,1) : (0,),
(1,2,3) : (1,),
(1,4,3) : (1,),
(1,2,4) : (1,),
(1,2,1) : (1,),
(1,2,6) : (1,),
(1,4,5) : (0,),
(1,5,3) : (1,),
(1,6,3) : (0,)
}))
(1,2,3) : (1,),
(3,3,1) : (0,),
(1,2,3) : (1,),
(1,4,3) : (1,),
(1,2,4) : (1,),
(1,2,1) : (1,),
(1,2,6) : (1,),
(1,4,5) : (0,),
(1,5,3) : (1,),
(1,6,3) : (0,)
}))
classif = classifier.OneClassifier
print d.asMatrix()

Expand Down

0 comments on commit 40a40e6

Please sign in to comment.