2
package net.sf.snowball;
4
import java.lang.reflect.Method;
7
import java.io.BufferedReader;
8
import java.io.BufferedWriter;
9
import java.io.FileInputStream;
10
import java.io.InputStreamReader;
11
import java.io.OutputStreamWriter;
12
import java.io.OutputStream;
13
import java.io.FileOutputStream;
15
public class TestApp {
16
public static void main(String [] args) throws Throwable {
17
Class stemClass = Class.forName("net.sf.snowball.ext." +
19
SnowballProgram stemmer = (SnowballProgram) stemClass.newInstance();
20
Method stemMethod = stemClass.getMethod("stem", new Class[0]);
23
reader = new InputStreamReader(new FileInputStream(args[1]));
24
reader = new BufferedReader(reader);
26
StringBuffer input = new StringBuffer();
28
OutputStream outstream;
30
if (args.length > 2 && args[2].equals("-o")) {
31
outstream = new FileOutputStream(args[3]);
32
} else if (args.length == 2) {
33
System.err.println("Usage: TestApp <input file> [-o <output file>]");
36
outstream = System.out;
38
Writer output = new OutputStreamWriter(outstream);
39
output = new BufferedWriter(output);
42
if (args.length > 4) {
43
repeat = Integer.parseInt(args[4]);
46
Object [] emptyArgs = new Object[0];
48
while ((character = reader.read()) != -1) {
49
char ch = (char) character;
50
if (Character.isWhitespace((char) ch)) {
51
if (input.length() > 0) {
52
stemmer.setCurrent(input.toString());
53
for (int i = repeat; i != 0; i--) {
54
stemMethod.invoke(stemmer, emptyArgs);
56
output.write(stemmer.getCurrent());
58
input.delete(0, input.length());
61
input.append(Character.toLowerCase(ch));