Skip to content

Commit

Permalink
pickles are back, s/name/name() nltk/nltk#566 nltk changed it upon vu…
Browse files Browse the repository at this point in the history
…p to 3.0 ?
  • Loading branch information
kevincobain2000 committed Mar 31, 2015
1 parent c39fd0a commit 13c6ac4
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions src/senti_classifier/senti_classifier.py
Expand Up @@ -184,7 +184,7 @@ def classify(text, synsets_scores, bag_of_words):
sent_score_pos = sent_score_neg = 0
for word in sentence.split():
if disambiguateWordSenses(sentence, word):
disamb_syn = disambiguateWordSenses(sentence, word).name
disamb_syn = disambiguateWordSenses(sentence, word).name()
if synsets_scores.has_key(disamb_syn):
#uncomment the disamb_syn.split... if also want to check synsets polarity
if bag_of_words['neg'].has_key(word.lower()):
Expand All @@ -198,11 +198,11 @@ def classify(text, synsets_scores, bag_of_words):

#========== Skipping pickle for a while ==========*/

# senti_pickle = resource_stream('senti_classifier', 'data/SentiWn.p')
# bag_of_words_pickle = resource_stream('senti_classifier', 'data/bag_of_words.p')
# synsets_scores = pickle.load(senti_pickle)
# bag_of_words = pickle.load(bag_of_words_pickle)
# bag_of_words = classify_polarity(bag_of_words)
senti_pickle = resource_stream('senti_classifier', 'data/SentiWn.p')
bag_of_words_pickle = resource_stream('senti_classifier', 'data/bag_of_words.p')
synsets_scores = pickle.load(senti_pickle)
bag_of_words = pickle.load(bag_of_words_pickle)
bag_of_words = classify_polarity(bag_of_words)

def polarity_scores(lines_list):
scorer = defaultdict(list)
Expand All @@ -211,26 +211,32 @@ def polarity_scores(lines_list):

if __name__ == "__main__":
pickles = ['SentiWn.p']
parser = argparse.ArgumentParser(add_help = True)
parser = argparse.ArgumentParser(description= 'Sentiment classification')
parser.add_argument('-p','--pickle', action="store", dest="SentiWN_path", type=str, help='SentiWordNet_*.txt')
parser.add_argument('-c','--classify', action="store", nargs = '*', dest="files", type=argparse.FileType('rt'), help='-c reviews')
myarguments = parser.parse_args()
synsets_scores = SentiWordNet_to_pickle(SentiWordNetCorpusReader(myarguments.SentiWN_path))
print classify( ["The movie was the worst movie bad super worst"], synsets_scores, bag_of_words)

#=====================================
# Debug Code =
#====================================*/

# parser = argparse.ArgumentParser(add_help = True)
# parser = argparse.ArgumentParser(description= 'Sentiment classification')
# parser.add_argument('-p','--pickle', action="store", dest="SentiWN_path", type=str, help='SentiWordNet_*.txt')
# parser.add_argument('-c','--classify', action="store", nargs = '*', dest="files", type=argparse.FileType('rt'), help='-c reviews')
# myarguments = parser.parse_args()
# synsets_scores = SentiWordNet_to_pickle(SentiWordNetCorpusReader(myarguments.SentiWN_path))
# pickle.dump(synsets_scores, open(pickles[0],'wb'))

# Fix me: TypeError: can't pickle instancemethod objects
# Not able to dump the pickle somehow. http://stackoverflow.com/questions/16439301/cant-pickle-defaultdict
# pickle.dump(synsets_scores, open(pickles[0],'wb'))
#
# Temporary Fix, just don't pickle them (it takes long time ! its better to pickle)

bag_of_words = train_bag_of_words()
bag_of_words = classify_polarity(bag_of_words)
print classify( ["The movie was the worst movie"], synsets_scores, bag_of_words)
# bag_of_words = train_bag_of_words()
# bag_of_words = classify_polarity(bag_of_words)




#=====================================
# Obsolete Code =
#====================================*/

# pickle.dump(synsets_scores, open(pickles[0],'wb'))
# if myarguments.SentiWN_path or not os.path.exists(pickles[0]):
Expand Down

0 comments on commit 13c6ac4

Please sign in to comment.