Developing Apama Applications > Developing Apama Applications in EPL > Common EPL Patterns in Monitors > Contrasting using a dictionary with spawning > Translation using a dictionary
Translation using a dictionary
The events to be processed:
event Input { string value; }
event Output { string value; }
event Translation {
   string raw;
   string converted;
}
The monitor:
monitor Translator {
   dictionary < string, string > translations;
 
   action onload() {
      Translation t;
on all Translation():t addTranslation(t);
      Input i;
on all Input():i translate(i);
   }
   action addTranslation(Translation t) {
      translations[t.raw] := t.converted ;
   }
   action translate(Input i) {
      if translations.hasKey(i.value) then {
         send Output( translations[i.value] ) to "output";
      }
      else { fail(i); }
   }
   action fail(Input i ) {
      print "Cannot translate: " + i.value;
   }
}
Copyright © 2013-2015 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.
Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG.