1 package org.apache.lucene.analysis.ru; 2 3 18 19 import junit.framework.TestCase; 20 21 import java.io.BufferedReader ; 22 import java.io.File ; 23 import java.io.InputStreamReader ; 24 import java.io.FileInputStream ; 25 import java.util.ArrayList ; 26 27 public class TestRussianStem extends TestCase 28 { 29 private ArrayList words = new ArrayList (); 30 private ArrayList stems = new ArrayList (); 31 32 public TestRussianStem(String name) 33 { 34 super(name); 35 } 36 37 40 protected void setUp() throws Exception 41 { 42 super.setUp(); 43 String str; 45 46 File dataDir = new File (System.getProperty("dataDir")); 47 48 BufferedReader inWords = 50 new BufferedReader ( 51 new InputStreamReader ( 52 new FileInputStream (new File (dataDir, "/org/apache/lucene/analysis/ru/wordsUnicode.txt")), 53 "Unicode")); 54 while ((str = inWords.readLine()) != null) 55 { 56 words.add(str); 57 } 58 inWords.close(); 59 60 BufferedReader inStems = 62 new BufferedReader ( 63 new InputStreamReader ( 64 new FileInputStream (new File (dataDir, "/org/apache/lucene/analysis/ru/stemsUnicode.txt")), 65 "Unicode")); 66 while ((str = inStems.readLine()) != null) 67 { 68 stems.add(str); 69 } 70 inStems.close(); 71 } 72 73 76 protected void tearDown() throws Exception 77 { 78 super.tearDown(); 79 } 80 81 public void testStem() 82 { 83 for (int i = 0; i < words.size(); i++) 84 { 85 String realStem = 87 RussianStemmer.stem( 88 (String ) words.get(i), 89 RussianCharsets.UnicodeRussian); 90 assertEquals("unicode", stems.get(i), realStem); 91 } 92 } 93 94 private String printChars(String output) 95 { 96 StringBuffer s = new StringBuffer (); 97 for (int i = 0; i < output.length(); i++) 98 { 99 s.append(output.charAt(i)); 100 } 101 return s.toString(); 102 } 103 } 104 | Popular Tags |