Want more features on Pastebin? Sign Up, it's FREE!
Guest

mit 6.00

By: a guest on Nov 10th, 2012  |  syntax: Python  |  size: 1.10 KB  |  views: 505  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. problem set 6
  2. problem 5
  3.  
  4.  
  5. class WordTrigger(Trigger):
  6.     def __init__(self, word):
  7.         self.word = word
  8.     def isWordIn(self, text):
  9.         word = self.word.lower()
  10.         text = text.lower()
  11.         # Remove punctation and split the text
  12.         for punc in string.punctuation:
  13.             text = text.replace(punc, " ")
  14.         splittext = text.split(" ")
  15.  
  16.         # Check if the word is in the text
  17.         return word in splittext
  18.  
  19.  
  20. # TODO: TitleTrigger
  21. class TitleTrigger(WordTrigger):
  22.     def __init__(self, word):
  23.         WordTrigger.__init__(self, word)
  24.  
  25.     def evaluate(self, story):
  26.         return self.isWordIn(story.getTitle())
  27.    
  28. # TODO: SubjectTrigger
  29. class SubjectTrigger(WordTrigger):
  30.     def __init__(self, word):
  31.         WordTrigger.__init__(self, word)
  32.  
  33.     def evaluate(self, story):
  34.         return self.isWordIn(story.getSubject())
  35.    
  36. # TODO: SummaryTrigger
  37. class SummaryTrigger(WordTrigger):
  38.     def __init__(self, word):
  39.         WordTrigger.__init__(self, word)
  40.  
  41.     def evaluate(self, story):
  42.         return self.isWordIn(story.getSummary())
clone this paste RAW Paste Data