Comparing two data sourcesThe Comparator component tests two incoming streams to see if the items they contain match (pass an equality test). Example UsageCompares contents of two files and prints "MISMATCH!" whenever one is found: class DetectFalse(component): def main(self): while 1: yield 1 if self.dataReady("inbox"): if not self.recv("inbox"): print "MISMATCH!" Graphline( file1 = RateControlledFileReader(filename="file 1", ...), file2 = RateControlledFileReader(filename="file 2", ...), compare = Comparator(), fdetect = DetectFalse(), output = ConsoleEchoer(), linkages = { ("file1","outbox") : ("compare","inA"), ("file2","outbox") : ("compare","inB"), ("compare", "outbox") : ("fdetect", "inbox"), ("fdetect", "outbox") : ("output", "inbox"), }, ).run() How does it work?The component simply waits until there is data ready on both its "inA" and "inB" inboxes, then takes an item from each and compares them. The result of the comparison is sent to the "outbox" outbox. If data is available at neither, or only one, of the two inboxes, then the component will wait indefinitely until data is available on both. If a producerFinished or shutdownMicroprocess message is received on the "control" inbox, then a producerFinished message is sent out of the "signal" outbox and the component terminates. The comparison is done by the combine() method. This method returns the result of a simple equality test of the two arguments. You could always subclass this component and reimplement the combine() method to perform different functions (for example, an 'adder'). Kamaelia.Util.Comparator.Comparatorclass Comparator(Axon.Component.component)Comparator() -> new Comparator component. Compares items received on "inA" inbox with items received on "inB" inbox. For each pair, outputs True if items compare equal, otherwise False. Inboxes
Outboxes
Methods defined hereWarning! You should be using the inbox/outbox interface, not these methods (except construction). This documentation is designed as a roadmap as to their functionalilty for maintainers and new component developers. combine(self, valA, valB)Returns result of (valA == valB) Reimplement this method to change the type of comparison from equality testing. mainBody(self)Main loop body. FeedbackGot a problem with the documentation? Something unclear that could be clearer? Want to help improve it? Constructive criticism is very welcome - especially if you can suggest a better rewording! Please leave you feedback here in reply to the documentation thread in the Kamaelia blog. -- Automatic documentation generator, 05 Jun 2009 at 03:01:38 UTC/GMT |
Kamaelia
is an open source project originated from and guided by BBC
Research. For more information browse the site or get in
contact.
This is an ongoing community based development site. As a result the contents of this page is the opinions of the contributors of the pages involved not the organisations involved. Specificially, this page may contain personal views which are not the views of the BBC. (the site is powered by a wiki engine)
(C) Copyright 2008 Kamaelia Contributors, including the British Broadcasting Corporation, All Rights Reserved.