You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by eh...@apache.org on 2004/01/23 13:05:03 UTC
cvs commit: jakarta-lucene-sandbox/contributions/snowball/src/test/org/apache/lucene/analysis/snowball TestSnowball.java
ehatcher 2004/01/23 04:05:03
Modified: contributions/snowball/src/java/net/sf/snowball TestApp.java
contributions/snowball/src/java/org/apache/lucene/analysis/snowball
SnowballFilter.java
contributions/snowball/src/test/org/apache/lucene/analysis/snowball
TestSnowball.java
Log:
snowball touchups
Revision Changes Path
1.2 +57 -50 jakarta-lucene-sandbox/contributions/snowball/src/java/net/sf/snowball/TestApp.java
Index: TestApp.java
===================================================================
RCS file: /home/cvs/jakarta-lucene-sandbox/contributions/snowball/src/java/net/sf/snowball/TestApp.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestApp.java 20 Dec 2002 22:39:43 -0000 1.1
+++ TestApp.java 23 Jan 2004 12:05:03 -0000 1.2
@@ -1,4 +1,3 @@
-
package net.sf.snowball;
import java.lang.reflect.Method;
@@ -13,54 +12,62 @@
import java.io.FileOutputStream;
public class TestApp {
- public static void main(String [] args) throws Throwable {
- 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;
-
- if (args.length > 2 && args[2].equals("-o")) {
- outstream = new FileOutputStream(args[3]);
- } else if (args.length == 2) {
- System.err.println("Usage: TestApp <input file> [-o <output file>]");
- return;
- } else {
- outstream = System.out;
- }
- 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((char) 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();
+ public static void main(String[] args) throws Throwable {
+
+ 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();
+ }
+
+ private static void exitWithUsage() {
+ System.err.println("Usage: TestApp <stemmer name> <input file> [-o <output file>]");
+ System.exit(1);
+ }
}
1.6 +2 -1 jakarta-lucene-sandbox/contributions/snowball/src/java/org/apache/lucene/analysis/snowball/SnowballFilter.java
Index: SnowballFilter.java
===================================================================
RCS file: /home/cvs/jakarta-lucene-sandbox/contributions/snowball/src/java/org/apache/lucene/analysis/snowball/SnowballFilter.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SnowballFilter.java 5 Jan 2004 15:37:49 -0000 1.5
+++ SnowballFilter.java 23 Jan 2004 12:05:03 -0000 1.6
@@ -3,7 +3,7 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2004 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -89,6 +89,7 @@
Class stemClass =
Class.forName("net.sf.snowball.ext." + name + "Stemmer");
stemmer = (SnowballProgram) stemClass.newInstance();
+ // why doesn't the SnowballProgram class have an (abstract?) stem method?
stemMethod = stemClass.getMethod("stem", new Class[0]);
} catch (Exception e) {
throw new RuntimeException(e.toString());
1.2 +4 -8 jakarta-lucene-sandbox/contributions/snowball/src/test/org/apache/lucene/analysis/snowball/TestSnowball.java
Index: TestSnowball.java
===================================================================
RCS file: /home/cvs/jakarta-lucene-sandbox/contributions/snowball/src/test/org/apache/lucene/analysis/snowball/TestSnowball.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestSnowball.java 20 Dec 2002 22:39:44 -0000 1.1
+++ TestSnowball.java 23 Jan 2004 12:05:03 -0000 1.2
@@ -3,7 +3,7 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2004 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -61,12 +61,8 @@
public class TestSnowball extends TestCase {
- public TestSnowball(String name) {
- super(name);
- }
-
- public void assertAnalyzesTo(Analyzer a,
- String input,
+ public void assertAnalyzesTo(Analyzer a,
+ String input,
String[] output) throws Exception {
TokenStream ts = a.tokenStream("dummy", new StringReader(input));
for (int i=0; i<output.length; i++) {
@@ -80,7 +76,7 @@
public void testEnglish() throws Exception {
Analyzer a = new SnowballAnalyzer("English");
- assertAnalyzesTo(a, "he abhorred accents",
+ assertAnalyzesTo(a, "he abhorred accents",
new String[] { "he", "abhor", "accent" });
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org