Developing Apama Applications > Developing Apama Applications in EPL > Common EPL Patterns > 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 {
         emit Output( translations[i.value] );
      }
      else { fail(i); }
   }
   action fail(Input i ) {
      print "Cannot translate: " + i.value;
   }
}
Copyright © 2013 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or Terracotta Inc., San Francisco, CA, USA, and/or Software AG (Canada) Inc., Cambridge, Ontario, Canada, and/or, Software AG (UK) Ltd., Derby, United Kingdom, and/or Software A.G. (Israel) Ltd., Or-Yehuda, Israel and/or their licensors.