Advertisement
Guest User

mit 6.00

a guest
Nov 10th, 2012
1,562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  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())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement