// scans an input_file to replace all occurances of words in HashSet
  // with a replacement string
  public static void replaceWords(String input_file, String output_file) {

    BufferedWriter bw = null;
    BufferedReader br = null;

    try {
      br = new BufferedReader(new FileReader(input_file));
      bw = new BufferedWriter(new FileWriter(output_file));
      String str = br.readLine();
      while (str != null) {
        for (String s : StringUtils.split(str, " ")) {
          String replacement = Normalizer.getReplacement(s);
          if (replacement != null) {
            str = StringUtils.replace(str, s, replacement);
            // System.out.println(s+" "+replacement+" "+str);
          }
        }
        bw.write(str);
        bw.newLine();
        str = br.readLine();
      }
      bw.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  public static void tagFile(Tagger tagger, String input_file, String output_file) {

    BufferedWriter bw = null;
    BufferedReader br = null;

    try {
      br = new BufferedReader(new FileReader(input_file));
      bw = new BufferedWriter(new FileWriter(output_file));
      String str = br.readLine();
      List<String> sentence = new ArrayList<String>();
      List<String> tags = new ArrayList<String>();
      while (str != null) {
        if (StringUtils.isBlank(str)) {
          tags = tagger.tag(sentence);
          for (int i = 0; i < sentence.size(); i++) {
            bw.write(sentence.get(i) + " " + tags.get(i));
            bw.newLine();
          }
          bw.write("");
          bw.newLine();
          sentence = new ArrayList<String>();
          str = br.readLine();
          tags = new ArrayList<String>();
          continue;
        }
        sentence.add(str);
        str = br.readLine();
      }
      bw.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  public static void parseFile(Parser parser, String inputfile, String outputfile) {

    BufferedWriter bw = null;
    BufferedReader br = null;

    try {
      br = new BufferedReader(new FileReader(inputfile));
      bw = new BufferedWriter(new FileWriter(outputfile));
      int count = 1;
      String str = br.readLine();
      List<String> sentence = new ArrayList<String>();
      while (str != null) {
        System.out.println("Processing Sentence " + count);
        sentence = Arrays.asList(StringUtils.split(str, " "));
        bw.write(parser.parse(sentence).toString());
        bw.newLine();
        str = br.readLine();
        count++;
      }
      bw.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }