Skip to content

Apache Lucene open-source search software

LUCENE-2212: add test for PorterStemFilter

Robert Muir7c0cb27edd26
diff --git a/src/test/org/apache/lucene/analysis/TestPorterStemFilter.java b/src/test/org/apache/lucene/analysis/TestPorterStemFilter.java
new file mode 100644
index 00000000000..d377577cd9a
--- /dev/null
+++ b/src/test/org/apache/lucene/analysis/TestPorterStemFilter.java
@@ -0,0 +1,59 @@
+package org.apache.lucene.analysis;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringReader;
+import java.util.zip.ZipFile;
+
+/**
+ * Test the PorterStemFilter with Martin Porter's test data.
+ */
+public class TestPorterStemFilter extends BaseTokenStreamTestCase {
+ /**
+ * Run the stemmer against all strings in voc.txt
+ * The output should be the same as the string in output.txt
+ */
+ public void testPorterStemFilter() throws IOException {
+ Tokenizer tokenizer = new KeywordTokenizer(new StringReader(""));
+ TokenStream filter = new PorterStemFilter(tokenizer);
+ ZipFile zipFile = new ZipFile(
+ new File(getClass().getResource("porterTestData.zip").getFile()));
+ InputStream voc = zipFile.getInputStream(zipFile.getEntry("voc.txt"));
+ InputStream out = zipFile.getInputStream(zipFile.getEntry("output.txt"));
+ BufferedReader vocReader = new BufferedReader(new InputStreamReader(
+ voc, "UTF-8"));
+ BufferedReader outputReader = new BufferedReader(new InputStreamReader(
+ out, "UTF-8"));
+ String inputWord = null;
+ while ((inputWord = vocReader.readLine()) != null) {
+ String expectedWord = outputReader.readLine();
+ assertNotNull(expectedWord);
+ tokenizer.reset(new StringReader(inputWord));
+ filter.reset();
+ assertTokenStreamContents(filter, new String[] { expectedWord });
+ }
+ vocReader.close();
+ outputReader.close();
+ zipFile.close();
+ }
+}
diff --git a/src/test/org/apache/lucene/analysis/porterTestData.zip b/src/test/org/apache/lucene/analysis/porterTestData.zip
new file mode 100644
index 00000000000..ccb55e5564f
Binary files /dev/null and b/src/test/org/apache/lucene/analysis/porterTestData.zip differ