Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- problem set 6
- problem 5
- class WordTrigger(Trigger):
- def __init__(self, word):
- self.word = word
- def isWordIn(self, text):
- word = self.word.lower()
- text = text.lower()
- # Remove punctation and split the text
- for punc in string.punctuation:
- text = text.replace(punc, " ")
- splittext = text.split(" ")
- # Check if the word is in the text
- return word in splittext
- # TODO: TitleTrigger
- class TitleTrigger(WordTrigger):
- def __init__(self, word):
- WordTrigger.__init__(self, word)
- def evaluate(self, story):
- return self.isWordIn(story.getTitle())
- # TODO: SubjectTrigger
- class SubjectTrigger(WordTrigger):
- def __init__(self, word):
- WordTrigger.__init__(self, word)
- def evaluate(self, story):
- return self.isWordIn(story.getSubject())
- # TODO: SummaryTrigger
- class SummaryTrigger(WordTrigger):
- def __init__(self, word):
- WordTrigger.__init__(self, word)
- def evaluate(self, story):
- return self.isWordIn(story.getSummary())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement