PS5: little confused about this paragraph: This trigger should produce its output by inverting the output of another trigger. The NOT trigger should take this other trigger as an argument to its constructor (why its constructor? Because we can’t change evaluate… that’d break our polymorphism). So, given a trigger T and a news item x, the output of the NOT trigger’s evaluate method should be equivalent to not T.evaluate(x). So should NotTrigger implement its own evaluate method or should it inherit from Trigger? Did we talk about polymorphism?
it seems like you want to invert your output, aka a NOT. Basically NOT changes 1's to 0's and 0's to 1's. It also seems like you're calling the Trigger in the NOT Trigger's Constructor. In Java it would be. public class notTrigger() { Trigger t; public notTrigger(Trigger T) { this.t = T; } } Next if we wanted to set up a Getter/Setter Methods we could also do this. Now we however want the INVERTED of whatever we are given. I'm also confused exactly what the Trigger is doing(true/false boolean)??? Also what is the news item/ what is our number set(0 and 1)???? What are we "inverting?"
Here is the inherited function: def evaluate(self, story): raise NotImplementedError The trick would seem to be to implement a subclass.evaluate method, but the instructions say, "we can't change evaluate", so this confuses me. A subclass eval would be: def subclass.evaluate(self,story): if word in story: return True or something like that
This works, but it's a different implementation of evaluate. Since I didn't know anything about raise exception, I had no idea this was part of that scheme. class NotTrigger(Trigger): def __init__(self,object): self.object = object def evaluate(self,object): return not self.object.evaluate(self)
Join our real-time social learning platform and learn together with your friends!