Permalink
Cannot retrieve contributors at this time
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?
BigData/getAdjectives.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
58 lines (49 sloc)
2.25 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |