FileDocCategorySizeDatePackage
TestApp.javaAPI DocApache Lucene 1.92063Mon Feb 20 09:17:48 GMT 2006net.sf.snowball

TestApp

public class TestApp extends Object

Fields Summary
Constructors Summary
Methods Summary
private static voidexitWithUsage()

    System.err.println("Usage: TestApp <stemmer name> <input file> [-o <output file>]");
    System.exit(1);
  
public static voidmain(java.lang.String[] args)


    if (args.length < 2) {
      exitWithUsage();
    }

    Class stemClass = Class.forName("net.sf.snowball.ext." +
                                    args[0] + "Stemmer");
    SnowballProgram stemmer = (SnowballProgram) stemClass.newInstance();
    Method stemMethod = stemClass.getMethod("stem", new Class[0]);

    Reader reader;
    reader = new InputStreamReader(new FileInputStream(args[1]));
    reader = new BufferedReader(reader);

    StringBuffer input = new StringBuffer();

    OutputStream outstream = System.out;

    if (args.length > 2 && args[2].equals("-o")) {
      outstream = new FileOutputStream(args[3]);
    } else if (args.length > 2) {
      exitWithUsage();
    }

    Writer output = new OutputStreamWriter(outstream);
    output = new BufferedWriter(output);

    int repeat = 1;
    if (args.length > 4) {
      repeat = Integer.parseInt(args[4]);
    }

    Object[] emptyArgs = new Object[0];
    int character;
    while ((character = reader.read()) != -1) {
      char ch = (char) character;
      if (Character.isWhitespace(ch)) {
        if (input.length() > 0) {
          stemmer.setCurrent(input.toString());
          for (int i = repeat; i != 0; i--) {
            stemMethod.invoke(stemmer, emptyArgs);
          }
          output.write(stemmer.getCurrent());
          output.write('\n");
          input.delete(0, input.length());
        }
      } else {
        input.append(Character.toLowerCase(ch));
      }
    }
    output.flush();