Skip to content
Permalink
e3075760a6
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
58 lines (49 sloc) 2.25 KB
import math
import nltk
from nltk.corpus import brown as sc
from collections import Counter
from nltk.corpus import movie_reviews
def genConj():
conj = open('movieconj.txt', 'r+')
ands = open('ands.txt', 'r+')
ors = open('ors.txt', 'r+')
buts = open('buts.txt', 'r+')
nor = open('nor.txt', 'r+')
eor = open('eor.txt', 'r+')
j = 0
for review in sorted(movie_reviews.fileids()): #For every review
tokens = nltk.pos_tag(nltk.word_tokenize(movie_reviews.raw(fileids=[review])))
print j
j = j+1
for i in range(0,len(tokens)-3):
if ((tokens[i][1]== "JJ" or tokens[i][1] == "JJR" or tokens[i][1] == "JJS") and (tokens[i+2][1]== "JJ" or tokens[i+2][1] == "JJR" or tokens[i+2][1] == "JJS")):
if (tokens[i+1][0] == "and"):
print tokens[i][0]
conj.write(tokens[i][0]+ " " + tokens[i+2][0] + " " + tokens[i+1][0] + "\n")
#ands.write(tokens[i][0]+ " " + tokens[i+2][0]+ "\n")
elif (tokens[i+1][0] == "or"):
conj.write(tokens[i][0]+ " " + tokens[i+2][0] + " " + tokens[i+1][0] + "\n")
#ors.write(tokens[i][0]+ " " + tokens[i+2][0]+ "\n")
elif (tokens[i+1][0] == "but"+ "\n"):
conj.write(tokens[i][0]+ " " + tokens[i+2][0] + " " + tokens[i+1][0] + "\n")
#buts.write(tokens[i][0]+ " " + tokens[i+2][0]+ "\n")
elif (tokens[i+1][0] == "either-or"):
conj.write(tokens[i][0]+ " " + tokens[i+2][0] + " " + tokens[i+1][0] + "\n")
#eor.write(tokens[i][0]+ " " + tokens[i+2][0]+ "\n")
elif (tokens[i+1][0] == "neither-nor"):
conj.write(tokens[i][0]+ " " + tokens[i+2][0] + " " + tokens[i+1][0] + "\n")
#nor.write(tokens[i][0]+ " " + tokens[i+2][0]+ "\n")
def doBrown():
f = open('movieconj.txt', 'w')
list1 = []
for word in sc.tagged_sents():
for w in word:
if(w[1] == "JJ" or w[1] == "JJR" or w[1] == "JJS" or w[1] == "JJT"):
list1.append(w[0])
counts = Counter(list1)
d = dict(counts)
for n in d:
if( d[n] >= 15):
f.write(n+" \n")
f.close()
genConj()