Skip to content
Permalink
66918f812e
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
49 lines (44 sloc) 2.06 KB
import math
import nltk
from nltk.corpus import brown as sc
from collections import Counter
def genConj(training):
conj = open('conj.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 training: #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"):
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")
f = open('words.txt', 'r+')
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] >= 20):
f.write(n+" \n")