/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package at.illecker.storm.examples.util.wordlist;

import java.util.Map;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import at.illecker.storm.examples.util.Configuration;
import at.illecker.storm.examples.util.io.FileUtils;

public class SlangCorrection {
  private static final Logger LOG = LoggerFactory
      .getLogger(SlangCorrection.class);
  private static final SlangCorrection instance = new SlangCorrection();

  private Map<String, String> m_slangWordList = null;

  private SlangCorrection() {
    Map<String, Properties> slangWordLists = Configuration.getSlangWordlists();
    for (Map.Entry<String, Properties> slangWordListEntry : slangWordLists
        .entrySet()) {
      String file = slangWordListEntry.getKey();
      String separator = slangWordListEntry.getValue().getProperty("separator");

      LOG.info("Load SlangLookupTable from: " + file);
      if (m_slangWordList == null) {
        m_slangWordList = FileUtils.readFile(file, separator);
      } else {
        Map<String, String> slangWordList = FileUtils.readFile(file, separator);
        for (Map.Entry<String, String> entry : slangWordList.entrySet()) {
          if (!m_slangWordList.containsKey(entry.getKey())) {
            m_slangWordList.put(entry.getKey(), entry.getValue());
          }
        }
      }
    }
  }

  public static SlangCorrection getInstance() {
    return instance;
  }

  public String getCorrection(String slangString) {
    String correctionStr = null;
    if (m_slangWordList != null) {
      correctionStr = m_slangWordList.get(slangString);
    }
    // LOG.info("getCorrection('" + slangString + "'): " + correctionStr);
    return correctionStr;
  }

  public static void main(String[] args) {
    SlangCorrection slangCorrection = SlangCorrection.getInstance();
    System.out.println("SlangCorrection of 'afaik': '"
        + slangCorrection.getCorrection("afaik") + "'");
    System.out.println("SlangCorrection of 'cum': '"
        + slangCorrection.getCorrection("cum") + "'");
  }
}

@@ -847,16 +847,67 @@
 dlist;%0A%0A
+import java.util.Arrays;%0Aimport java.util.HashMap;%0A
 import j
@@ -1340,16 +1340,18 @@
 , String
+%5B%5D
 %3E m_slan
@@ -1363,19 +1363,46 @@
 List = n
-ull
+ew HashMap%3CString, String%5B%5D%3E()
 ;%0A%0A  pri
@@ -1794,125 +1794,8 @@
 e);%0A
-      if (m_slangWordList == null) %7B%0A        m_slangWordList = FileUtils.readFile(file, separator);%0A      %7D else %7B%0A  
     
@@ -1875,18 +1875,16 @@
 ;%0A      
- 
- 
 for (Map
@@ -1938,26 +1938,24 @@
 trySet()) %7B%0A
-  
         if (
@@ -2012,18 +2012,16 @@
         
-  
 m_slangW
@@ -2068,22 +2068,21 @@
 ue()
-);%0A          %7D
+.split(%22 %22));
 %0A   
@@ -2196,16 +2196,18 @@
 c String
+%5B%5D
  getCorr
@@ -2224,252 +2224,160 @@
 ing 
-slangString) %7B%0A    String correctionStr = null;%0A    if (m_slangWordList != null) %7B%0A      correctionStr = m_slangWordList.get(slangString);%0A    %7D%0A    // LOG.info(%22getCorrection('%22 + slangString + %22'): %22 + correctionStr);%0A    return correctionStr
+token) %7B%0A    // LOG.info(%22getCorrection('%22 + token + %22'): %22%0A    // + Arrays.toString(m_slangWordList.get(token)));%0A    return m_slangWordList.get(token)
 ;%0A  
@@ -2548,32 +2548,48 @@
 ': '%22%0A        + 
+Arrays.toString(
 slangCorrection.
@@ -2610,16 +2610,17 @@
 %22afaik%22)
+)
  + %22'%22);
@@ -2683,16 +2683,32 @@
       + 
+Arrays.toString(
 slangCor
@@ -2735,16 +2735,17 @@
 n(%22cum%22)
+)
  + %22'%22);

Return String[] in SlangCorrection