You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2014/02/28 08:13:19 UTC

svn commit: r1572841 - in /lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell: StemmerTestBase.java TestCaseInsensitive.java TestMorph.java TestStemmer.java TestTwoFold.java morph.aff morph.dic twofold.aff

Author: rmuir
Date: Fri Feb 28 07:13:19 2014
New Revision: 1572841

URL: http://svn.apache.org/r1572841
Log:
LUCENE-5480: add the tests i have so far... (not including this bug yet though)

Added:
    lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/StemmerTestBase.java   (with props)
    lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestMorph.java   (with props)
    lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestTwoFold.java   (with props)
    lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/morph.aff   (with props)
    lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/morph.dic   (with props)
    lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/twofold.aff   (with props)
Modified:
    lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestCaseInsensitive.java
    lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestStemmer.java

Added: lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/StemmerTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/StemmerTestBase.java?rev=1572841&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/StemmerTestBase.java (added)
+++ lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/StemmerTestBase.java Fri Feb 28 07:13:19 2014
@@ -0,0 +1,79 @@
+package org.apache.lucene.analysis.hunspell;
+
+/*
+ * 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.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.ParseException;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.IOUtils;
+import org.apache.lucene.util.LuceneTestCase;
+
+/** base class for hunspell stemmer tests */
+abstract class StemmerTestBase extends LuceneTestCase {
+  private static Stemmer stemmer;
+  
+  static void init(String affix, String dictionary) throws IOException, ParseException {
+    init(false, affix, dictionary);
+  }
+
+  static void init(boolean ignoreCase, String affix, String... dictionaries) throws IOException, ParseException {
+    if (dictionaries.length == 0) {
+      throw new IllegalArgumentException("there must be at least one dictionary");
+    }
+    
+    InputStream affixStream = StemmerTestBase.class.getResourceAsStream(affix);
+    if (affixStream == null) {
+      throw new FileNotFoundException("file not found: " + affix);
+    }
+    
+    InputStream dictStreams[] = new InputStream[dictionaries.length];
+    for (int i = 0; i < dictionaries.length; i++) {
+      dictStreams[i] = StemmerTestBase.class.getResourceAsStream(dictionaries[i]);
+      if (dictStreams[i] == null) {
+        throw new FileNotFoundException("file not found: " + dictStreams[i]);
+      }
+    }
+    
+    try {
+      Dictionary dictionary = new Dictionary(affixStream, Arrays.asList(dictStreams), true);
+      stemmer = new Stemmer(dictionary);
+    } finally {
+      IOUtils.closeWhileHandlingException(affixStream);
+      IOUtils.closeWhileHandlingException(dictStreams);
+    }
+  }
+  
+  static void assertStemsTo(String s, String... expected) {
+    assertNotNull(stemmer);
+    Arrays.sort(expected);
+    
+    List<CharsRef> stems = stemmer.stem(s);
+    String actual[] = new String[stems.size()];
+    for (int i = 0; i < actual.length; i++) {
+      actual[i] = stems.get(i).toString();
+    }
+    Arrays.sort(actual);
+    
+    assertArrayEquals(expected, actual);
+  }
+}

Modified: lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestCaseInsensitive.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestCaseInsensitive.java?rev=1572841&r1=1572840&r2=1572841&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestCaseInsensitive.java (original)
+++ lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestCaseInsensitive.java Fri Feb 28 07:13:19 2014
@@ -17,33 +17,13 @@ package org.apache.lucene.analysis.hunsp
  * limitations under the License.
  */
 
-import org.apache.lucene.analysis.hunspell.Dictionary;
-import org.apache.lucene.analysis.hunspell.Stemmer;
-import org.apache.lucene.util.CharsRef;
-import org.apache.lucene.util.LuceneTestCase;
-import org.junit.AfterClass;
 import org.junit.BeforeClass;
 
-import java.io.InputStream;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-public class TestCaseInsensitive extends LuceneTestCase {
-  private static Stemmer stemmer;
+public class TestCaseInsensitive extends StemmerTestBase {
 
   @BeforeClass
   public static void beforeClass() throws Exception {
-    try (InputStream affixStream = TestCaseInsensitive.class.getResourceAsStream("simple.aff");
-        InputStream dictStream = TestCaseInsensitive.class.getResourceAsStream("mixedcase.dic")) {
-     Dictionary dictionary = new Dictionary(affixStream, Collections.singletonList(dictStream), true);
-     stemmer = new Stemmer(dictionary);
-   }
-  }
-  
-  @AfterClass
-  public static void afterClass() {
-    stemmer = null;
+    init(true, "simple.aff", "mixedcase.dic");
   }
 
   public void testCaseInsensitivity() {
@@ -94,17 +74,4 @@ public class TestCaseInsensitive extends
     assertStemsTo("lucenee");
     assertStemsTo("solre");
   }
-  
-  private void assertStemsTo(String s, String... expected) {
-    Arrays.sort(expected);
-    
-    List<CharsRef> stems = stemmer.stem(s);
-    String actual[] = new String[stems.size()];
-    for (int i = 0; i < actual.length; i++) {
-      actual[i] = stems.get(i).toString();
-    }
-    Arrays.sort(actual);
-    
-    assertArrayEquals(expected, actual);
-  }
 }

Added: lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestMorph.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestMorph.java?rev=1572841&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestMorph.java (added)
+++ lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestMorph.java Fri Feb 28 07:13:19 2014
@@ -0,0 +1,33 @@
+package org.apache.lucene.analysis.hunspell;
+
+/*
+ * 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 org.junit.BeforeClass;
+
+public class TestMorph extends StemmerTestBase {
+  
+  @BeforeClass
+  public static void beforeClass() throws Exception {
+    init("morph.aff", "morph.dic");
+  }
+  
+  public void testExamples() {
+    assertStemsTo("drink", "drink");
+    assertStemsTo("drinkable", "drink");
+  }
+}

Modified: lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestStemmer.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestStemmer.java?rev=1572841&r1=1572840&r2=1572841&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestStemmer.java (original)
+++ lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestStemmer.java Fri Feb 28 07:13:19 2014
@@ -17,32 +17,13 @@ package org.apache.lucene.analysis.hunsp
  * limitations under the License.
  */
 
-import org.apache.lucene.analysis.hunspell.Dictionary;
-import org.apache.lucene.analysis.hunspell.Stemmer;
-import org.apache.lucene.util.CharsRef;
-import org.apache.lucene.util.LuceneTestCase;
-import org.junit.AfterClass;
 import org.junit.BeforeClass;
 
-import java.io.InputStream;
-import java.util.Arrays;
-import java.util.List;
-
-public class TestStemmer extends LuceneTestCase {
-  private static Stemmer stemmer;
+public class TestStemmer extends StemmerTestBase {
 
   @BeforeClass
   public static void beforeClass() throws Exception {
-    try (InputStream affixStream = TestStemmer.class.getResourceAsStream("simple.aff");
-        InputStream dictStream = TestStemmer.class.getResourceAsStream("simple.dic")) {
-     Dictionary dictionary = new Dictionary(affixStream, dictStream);
-     stemmer = new Stemmer(dictionary);
-   }
-  }
-  
-  @AfterClass
-  public static void afterClass() {
-    stemmer = null;
+    init("simple.aff", "simple.dic");
   }
 
   public void testSimpleSuffix() {
@@ -91,17 +72,4 @@ public class TestStemmer extends LuceneT
     assertStemsTo("lucenee");
     assertStemsTo("solre");
   }
-  
-  private void assertStemsTo(String s, String... expected) {
-    Arrays.sort(expected);
-    
-    List<CharsRef> stems = stemmer.stem(s);
-    String actual[] = new String[stems.size()];
-    for (int i = 0; i < actual.length; i++) {
-      actual[i] = stems.get(i).toString();
-    }
-    Arrays.sort(actual);
-    
-    assertArrayEquals(expected, actual);
-  }
 }

Added: lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestTwoFold.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestTwoFold.java?rev=1572841&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestTwoFold.java (added)
+++ lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestTwoFold.java Fri Feb 28 07:13:19 2014
@@ -0,0 +1,34 @@
+package org.apache.lucene.analysis.hunspell;
+
+/*
+ * 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 org.junit.BeforeClass;
+
+public class TestTwoFold extends StemmerTestBase {
+  
+  @BeforeClass
+  public static void beforeClass() throws Exception {
+    init("twofold.aff", "morph.dic");
+  }
+  
+  public void testExamples() {
+    assertStemsTo("drink", "drink");
+    assertStemsTo("drinkable", "drink");
+    assertStemsTo("drinkables", "drink");
+  }
+}

Added: lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/morph.aff
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/morph.aff?rev=1572841&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/morph.aff (added)
+++ lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/morph.aff Fri Feb 28 07:13:19 2014
@@ -0,0 +1,4 @@
+SET UTF-8
+
+SFX X Y 1
+SFX X 0 able . +ABLE

Added: lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/morph.dic
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/morph.dic?rev=1572841&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/morph.dic (added)
+++ lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/morph.dic Fri Feb 28 07:13:19 2014
@@ -0,0 +1,2 @@
+1
+drink/X   [VERB]

Added: lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/twofold.aff
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/twofold.aff?rev=1572841&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/twofold.aff (added)
+++ lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/twofold.aff Fri Feb 28 07:13:19 2014
@@ -0,0 +1,7 @@
+SET UTF-8
+
+SFX Y Y 1
+SFX Y 0 s . +PLUR
+
+SFX X Y 1
+SFX X 0 able/Y . +ABLE