title: Looking up variable keys in pig map
body: <p>I'm trying to use pig to break text into lowercased words, and then look up each word in a map. Here's my example map, which I have in map.txt (it is only 1 line long):</p>
  
  <pre><code>[this#1.9,is#2.5my#3.3,vocabulary#4.1]
  </code></pre>
  
  <p>I load this like so:</p>
  
  <pre><code>M = LOAD 'mapping.txt' USING PigStorage AS (mp: map[float]);
  </code></pre>
  
  <p>which works just fine. Then I do the following to load the text and break it into lowercased words:</p>
  
  <pre><code>LINES = LOAD 'test.txt' USING TextLoader() AS (line:chararray);
  TOKENS = FOREACH LINES GENERATE FLATTEN(TOKENIZE(LOWER(line))) as (word:chararray);
  </code></pre>
  
  <p>Now, I'd like to do something like this:</p>
  
  <pre><code>RESULTS = FOREACH TOKENS GENERATE M.mp#word;
  </code></pre>
  
  <p>so that if I have a line like "this my my vocabulary", I'd get the following output: 1 3 3 4 , but I keep getting various errors. How can I look up variable values in a map?</p>
  
  <p>I've looked at <a href="https://stackoverflow.com/questions/4069589/how-can-i-use-the-map-datatype-in-apache-pig">How can I use the map datatype in Apache Pig?</a> and <a href="http://pig.apache.org/docs/r0.10.0/basic.html#map-schema" rel="nofollow noreferrer">http://pig.apache.org/docs/r0.10.0/basic.html#map-schema</a> , but these only help if I'm looking up a <em>fixed</em> value in a map, for example M.mp#'this', which is not what I want to do here. </p>