-
Notifications
You must be signed in to change notification settings - Fork 57
/
Composite Triggers.py
59 lines (37 loc) · 1.35 KB
/
Composite Triggers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Enter your code for WordTrigger, TitleTrigger,
# NotTrigger, AndTrigger, and OrTrigger in this box
class WordTrigger(Trigger):
def __init__(self, word):
self.word = word
def isWordIn(self, text):
text = [a.strip(string.punctuation).lower() for a in text.split(" ")]
for word in text:
if self.word.lower() in word.split("'"):
return True
return False
class TitleTrigger(WordTrigger):
def evaluate(self, story):
return self.isWordIn(story.getTitle())
class SubjectTrigger(WordTrigger):
def evaluate(self, story):
return self.isWordIn(story.getSubject())
class SummaryTrigger(WordTrigger):
def evaluate(self, story):
return self.isWordIn(story.getSummary())
class NotTrigger(Trigger):
def __init__(self, t1):
self.t1 = t1
def evaluate(self, story):
return not self.t1.evaluate(story)
class AndTrigger(Trigger):
def __init__(self, t1, t2):
self.t1 = t1
self.t2 = t2
def evaluate(self, story):
return self.t1.evaluate(story) and self.t2.evaluate(story)
class OrTrigger(Trigger):
def __init__(self, t1, t2):
self.t1 = t1
self.t2 = t2
def evaluate(self, story):
return self.t1.evaluate(story) or self.t2.evaluate(story)