Skip to content

Commit

Permalink
Merge pull request #13 from JediRhymeTrix/master
Browse files Browse the repository at this point in the history
Patch fix for the "ImportError: no module named collections" issue.
  • Loading branch information
kevincobain2000 committed Jan 20, 2018
2 parents 654046b + dd790f2 commit 107e9f5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/senti_classifier/classifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def get_train_set(texts):
train_set = get_train_set(texts)
#classifier = NaiveBayesClassifier.train(train_set)
#classifier = MaxentClassifier.train(train_set)
pickle.dump(classifier, open(pickled_classifier,'w'))
pickle.dump(classifier, open(pickled_classifier,'wb'))
else: classifier = pickle.load(open(pickled_classifier,'r'))
#classifier.show_most_informative_features(20)

Expand Down
10 changes: 6 additions & 4 deletions src/senti_classifier/senti_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,12 @@ 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)
# temporary fix for "no module named collections" error in some cases due to unexpected \r in .p files
senti_pickle = resource_stream('senti_classifier', 'data/SentiWn.p').read().replace('\r', '')
bag_of_words_pickle = resource_stream('senti_classifier', 'data/bag_of_words.p').read().replace('\r', '')
synsets_scores = pickle.loads(senti_pickle)
bag_of_words = pickle.loads(bag_of_words_pickle)
# #
bag_of_words = classify_polarity(bag_of_words)


Expand Down

0 comments on commit 107e9f5

Please sign in to comment.