mirror of https://github.com/apache/lucene.git
snowball touchups
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150935 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b3c97c801e
commit
0d43020b12
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
package net.sf.snowball;
|
package net.sf.snowball;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
@ -13,7 +12,12 @@ import java.io.OutputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
|
||||||
public class TestApp {
|
public class TestApp {
|
||||||
public static void main(String [] args) throws Throwable {
|
public static void main(String[] args) throws Throwable {
|
||||||
|
|
||||||
|
if (args.length < 2) {
|
||||||
|
exitWithUsage();
|
||||||
|
}
|
||||||
|
|
||||||
Class stemClass = Class.forName("net.sf.snowball.ext." +
|
Class stemClass = Class.forName("net.sf.snowball.ext." +
|
||||||
args[0] + "Stemmer");
|
args[0] + "Stemmer");
|
||||||
SnowballProgram stemmer = (SnowballProgram) stemClass.newInstance();
|
SnowballProgram stemmer = (SnowballProgram) stemClass.newInstance();
|
||||||
|
@ -25,16 +29,14 @@ public class TestApp {
|
||||||
|
|
||||||
StringBuffer input = new StringBuffer();
|
StringBuffer input = new StringBuffer();
|
||||||
|
|
||||||
OutputStream outstream;
|
OutputStream outstream = System.out;
|
||||||
|
|
||||||
if (args.length > 2 && args[2].equals("-o")) {
|
if (args.length > 2 && args[2].equals("-o")) {
|
||||||
outstream = new FileOutputStream(args[3]);
|
outstream = new FileOutputStream(args[3]);
|
||||||
} else if (args.length == 2) {
|
} else if (args.length > 2) {
|
||||||
System.err.println("Usage: TestApp <input file> [-o <output file>]");
|
exitWithUsage();
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
outstream = System.out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Writer output = new OutputStreamWriter(outstream);
|
Writer output = new OutputStreamWriter(outstream);
|
||||||
output = new BufferedWriter(output);
|
output = new BufferedWriter(output);
|
||||||
|
|
||||||
|
@ -43,11 +45,11 @@ public class TestApp {
|
||||||
repeat = Integer.parseInt(args[4]);
|
repeat = Integer.parseInt(args[4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object [] emptyArgs = new Object[0];
|
Object[] emptyArgs = new Object[0];
|
||||||
int character;
|
int character;
|
||||||
while ((character = reader.read()) != -1) {
|
while ((character = reader.read()) != -1) {
|
||||||
char ch = (char) character;
|
char ch = (char) character;
|
||||||
if (Character.isWhitespace((char) ch)) {
|
if (Character.isWhitespace(ch)) {
|
||||||
if (input.length() > 0) {
|
if (input.length() > 0) {
|
||||||
stemmer.setCurrent(input.toString());
|
stemmer.setCurrent(input.toString());
|
||||||
for (int i = repeat; i != 0; i--) {
|
for (int i = repeat; i != 0; i--) {
|
||||||
|
@ -63,4 +65,9 @@ public class TestApp {
|
||||||
}
|
}
|
||||||
output.flush();
|
output.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void exitWithUsage() {
|
||||||
|
System.err.println("Usage: TestApp <stemmer name> <input file> [-o <output file>]");
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package org.apache.lucene.analysis.snowball;
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
* The Apache Software License, Version 1.1
|
* 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.
|
* reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -89,6 +89,7 @@ public class SnowballFilter extends TokenFilter {
|
||||||
Class stemClass =
|
Class stemClass =
|
||||||
Class.forName("net.sf.snowball.ext." + name + "Stemmer");
|
Class.forName("net.sf.snowball.ext." + name + "Stemmer");
|
||||||
stemmer = (SnowballProgram) stemClass.newInstance();
|
stemmer = (SnowballProgram) stemClass.newInstance();
|
||||||
|
// why doesn't the SnowballProgram class have an (abstract?) stem method?
|
||||||
stemMethod = stemClass.getMethod("stem", new Class[0]);
|
stemMethod = stemClass.getMethod("stem", new Class[0]);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e.toString());
|
throw new RuntimeException(e.toString());
|
||||||
|
|
|
@ -3,7 +3,7 @@ package org.apache.lucene.analysis.snowball;
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
* The Apache Software License, Version 1.1
|
* 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.
|
* reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -61,10 +61,6 @@ import org.apache.lucene.analysis.*;
|
||||||
|
|
||||||
public class TestSnowball extends TestCase {
|
public class TestSnowball extends TestCase {
|
||||||
|
|
||||||
public TestSnowball(String name) {
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void assertAnalyzesTo(Analyzer a,
|
public void assertAnalyzesTo(Analyzer a,
|
||||||
String input,
|
String input,
|
||||||
String[] output) throws Exception {
|
String[] output) throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue