Skip to content

Commit

Permalink
Some additional ngrams methods
Browse files Browse the repository at this point in the history
  • Loading branch information
pranjalv123 committed Nov 1, 2011
1 parent 6124344 commit 9c980f6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions movie.py
Expand Up @@ -8,8 +8,8 @@

def read_reviews():
print "Reading and parsing files..."
pos_files = [ngrams.ngrams(1, open("pos/"+i).read()) for i in os.listdir("pos")]
neg_files = [ngrams.ngrams(1, open("neg/"+i).read()) for i in os.listdir("neg")]
pos_files = [ngrams.ngrams(3, open("pos/"+i).read()) for i in os.listdir("pos")]
neg_files = [ngrams.ngrams(3, open("neg/"+i).read()) for i in os.listdir("neg")]
classes = [1] * len(pos_files) + [0] * len(neg_files)
print "Creating matrix..."
mat = ngrams.ngrams_to_matrix(pos_files + neg_files, classes)
Expand Down
6 changes: 6 additions & 0 deletions ngrams.py
Expand Up @@ -43,6 +43,12 @@ def ngrams(n, s):
grams[" ".join(current)] += 1
return grams

def ngrams_range(b, e, s):
g = {}
for i in range(b, e+1):
g.update(ngrams(i, s))
return g

def ngrams_to_matrix(grams, classes):
print "a"
keysets = [set(k) for k in grams]
Expand Down

0 comments on commit 9c980f6

Please sign in to comment.