Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
../../../../img/srcFileCovDistChart3.png 83% of files have more coverage
37   119   11   12.33
16   65   0.3   3
3     3.67  
1    
 
  WordlistLoader       Line # 33 37 11 28.6% 0.2857143
 
  (1)
 
1    package org.apache.lucene.analysis;
2   
3    /**
4    * Copyright 2004 The Apache Software Foundation
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10    * http://www.apache.org/licenses/LICENSE-2.0
11    *
12    * Unless required by applicable law or agreed to in writing, software
13    * distributed under the License is distributed on an "AS IS" BASIS,
14    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    * See the License for the specific language governing permissions and
16    * limitations under the License.
17    */
18   
19    import java.io.BufferedReader;
20    import java.io.File;
21    import java.io.FileReader;
22    import java.io.IOException;
23    import java.io.Reader;
24    import java.util.HashMap;
25    import java.util.HashSet;
26   
27    /**
28    * Loader for text files that represent a list of stopwords.
29    *
30    * @author Gerhard Schwarz
31    * @version $Id: WordlistLoader.java 413180 2006-06-09 22:15:47Z dnaber $
32    */
 
33    public class WordlistLoader {
34   
35    /**
36    * Loads a text file and adds every line as an entry to a HashSet (omitting
37    * leading and trailing whitespace). Every line of the file should contain only
38    * one word. The words need to be in lowercase if you make use of an
39    * Analyzer which uses LowerCaseFilter (like StandardAnalyzer).
40    *
41    * @param wordfile File containing the wordlist
42    * @return A HashSet with the file's words
43    */
 
44  0 toggle public static HashSet getWordSet(File wordfile) throws IOException {
45  0 HashSet result = new HashSet();
46  0 FileReader reader = null;
47  0 try {
48  0 reader = new FileReader(wordfile);
49  0 result = getWordSet(reader);
50    }
51    finally {
52  0 if (reader != null)
53  0 reader.close();
54    }
55  0 return result;
56    }
57   
58    /**
59    * Reads lines from a Reader and adds every line as an entry to a HashSet (omitting
60    * leading and trailing whitespace). Every line of the Reader should contain only
61    * one word. The words need to be in lowercase if you make use of an
62    * Analyzer which uses LowerCaseFilter (like StandardAnalyzer).
63    *
64    * @param reader Reader containing the wordlist
65    * @return A HashSet with the reader's words
66    */
 
67  2 toggle public static HashSet getWordSet(Reader reader) throws IOException {
68  2 HashSet result = new HashSet();
69  2 BufferedReader br = null;
70  2 try {
71  2 if (reader instanceof BufferedReader) {
72  1 br = (BufferedReader) reader;
73    } else {
74  1 br = new BufferedReader(reader);
75    }
76  2 String word = null;
77  ? while ((word = br.readLine()) != null) {
78  6 result.add(word.trim());
79    }
80    }
81    finally {
82  2 if (br != null)
83  2 br.close();
84    }
85  2 return result;
86    }
87   
88    /**
89    * Reads a stem dictionary. Each line contains:
90    * <pre>word<b>\t</b>stem</pre>
91    * (i.e. two tab seperated words)
92    *
93    * @return stem dictionary that overrules the stemming algorithm
94    * @throws IOException
95    */
 
96  0 toggle public static HashMap getStemDict(File wordstemfile) throws IOException {
97  0 if (wordstemfile == null)
98  0 throw new NullPointerException("wordstemfile may not be null");
99  0 HashMap result = new HashMap();
100  0 BufferedReader br = null;
101  0 FileReader fr = null;
102  0 try {
103  0 fr = new FileReader(wordstemfile);
104  0 br = new BufferedReader(fr);
105  0 String line;
106  0 while ((line = br.readLine()) != null) {
107  0 String[] wordstem = line.split("\t", 2);
108  0 result.put(wordstem[0], wordstem[1]);
109    }
110    } finally {
111  0 if (fr != null)
112  0 fr.close();
113  0 if (br != null)
114  0 br.close();
115    }
116  0 return result;
117    }
118   
119    }