~snowball-yiddish-dev/snowball-yiddish/trunk

« back to all changes in this revision

Viewing changes to snowball/java/org/tartarus/snowball/TestApp.java

  • Committer: richard
  • Date: 2004-08-29 11:52:42 UTC
  • Revision ID: svn-v4:633ccae0-01f4-0310-8c99-d3591da6f01f:trunk:262
Import Java support files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
package net.sf.snowball;
 
3
 
 
4
import java.lang.reflect.Method;
 
5
import java.io.Reader;
 
6
import java.io.Writer;
 
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;
 
14
 
 
15
public class TestApp {
 
16
    public static void main(String [] args) throws Throwable {
 
17
        Class stemClass = Class.forName("net.sf.snowball.ext." +
 
18
                                        args[0] + "Stemmer");
 
19
        SnowballProgram stemmer = (SnowballProgram) stemClass.newInstance();
 
20
        Method stemMethod = stemClass.getMethod("stem", new Class[0]);
 
21
 
 
22
        Reader reader;
 
23
        reader = new InputStreamReader(new FileInputStream(args[1]));
 
24
        reader = new BufferedReader(reader);
 
25
 
 
26
        StringBuffer input = new StringBuffer();
 
27
 
 
28
        OutputStream outstream;
 
29
 
 
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>]");
 
34
            return;
 
35
        } else {
 
36
            outstream = System.out;
 
37
        }
 
38
        Writer output = new OutputStreamWriter(outstream);
 
39
        output = new BufferedWriter(output);
 
40
 
 
41
        int repeat = 1;
 
42
        if (args.length > 4) {
 
43
            repeat = Integer.parseInt(args[4]);
 
44
        }
 
45
 
 
46
        Object [] emptyArgs = new Object[0];
 
47
        int character;
 
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);
 
55
                    }
 
56
                    output.write(stemmer.getCurrent());
 
57
                    output.write('\n');
 
58
                    input.delete(0, input.length());
 
59
                }
 
60
            } else {
 
61
                input.append(Character.toLowerCase(ch));
 
62
            }
 
63
        }
 
64
        output.flush();
 
65
    }
 
66
}