Ejemplo n.º 1
0
  // 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();
    }
  }
Ejemplo n.º 2
0
  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();
    }
  }