Skip to content

Instantly share code, notes, and snippets.

@language-engineering
Last active October 11, 2015 13:27
Show Gist options
  • Select an option

  • Save language-engineering/3865389 to your computer and use it in GitHub Desktop.

Select an option

Save language-engineering/3865389 to your computer and use it in GitHub Desktop.
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