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.
62 lines (57 sloc)
2.02 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 string | |
import nltk | |
from nltk.corpus import brown as sc | |
from collections import Counter | |
from nltk.corpus import movie_reviews | |
from nltk.corpus import wordnet as wn | |
import MPQALexicon | |
# NLTK's pos tagger kinda sucks sometimes. Let's double check with Wordnet. | |
def isAdj(word): | |
global tagger, mpqa_words | |
#return tagger.tag([word])[0][1].startswith("JJ") | |
#return len(wn.synsets(word, wn.ADJ)) > 0 | |
#return tagger.tag([word])[0][1].startswith("JJ") and len(wn.synsets(word, wn.ADJ)) > 0 and word in mpqa_words | |
return word in mpqa_words | |
def genConj(): | |
conj = open('movieconj.txt', 'w') | |
global tagger | |
tagger = nltk.tag.perceptron.PerceptronTagger() | |
num_lines = 0 | |
for review in sorted(movie_reviews.fileids()): #For every review | |
tokens = movie_reviews.words(fileids=[review]) | |
for i in range(0,len(tokens)-2): | |
if isAdj(tokens[i]) and isAdj(tokens[i+2]): | |
line = tokens[i]+ " " + tokens[i+2] + " " + tokens[i+1] + "\n" | |
print line.strip() | |
if (tokens[i+1] == "and"): | |
conj.write(line) | |
num_lines += 1 | |
elif (tokens[i+1] == "or"): | |
conj.write(line) | |
num_lines += 1 | |
elif (tokens[i+1] == "but"+ "\n"): | |
conj.write(line) | |
num_lines += 1 | |
elif (tokens[i+1] == "either-or"): | |
conj.write(line) | |
num_lines += 1 | |
elif (tokens[i+1] == "neither-nor"): | |
conj.write(line) | |
num_lines += 1 | |
print num_lines | |
def doBrown(): | |
f = open('movieconj.txt', 'w') | |
list1 = [] | |
for word in sc.tagged_sents(): | |
for w in word: | |
if w[1].startswith("JJ"): | |
list1.append(w[0]) | |
counts = Counter(list1) | |
d = dict(counts) | |
for n in d: | |
if( d[n] >= 15): | |
f.write(n+" \n") | |
f.close() | |
(mpqa_words, mpqa_labels) = MPQALexicon.load() | |
genConj() |