Last active
October 11, 2015 13:27
-
-
Save language-engineering/3865389 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| from nltk.classify.api import ClassifierI | |
| import random | |
| class SimpleClassifier(ClassifierI): | |
| def __init__(self, pos, neg): | |
| self._pos = pos | |
| self._neg = neg | |
| def classify(self, words): | |
| score = 0 | |
| # add code here that assigns an appropriate value to score | |
| return "N" if score < 0 else "P" | |
| def batch_classify(self, docs): | |
| return [self.classify(doc.words() if hasattr(doc, 'words') else doc) for doc in docs] | |
| def labels(self): | |
| return ("P", "N") | |
| #Example usage: | |
| book_classifier = SimpleClassifier(positive_book_words_list, negative_book_words_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment