FileDocCategorySizeDatePackage
WordlistLoader.javaAPI DocApache Lucene 1.93426Mon Feb 20 09:19:44 GMT 2006org.apache.lucene.analysis.de

WordlistLoader

public class WordlistLoader extends Object
Loader for text files that represent a list of stopwords.
deprecated
Use {@link org.apache.lucene.analysis.WordlistLoader} instead
author
Gerhard Schwarz
version
$Id: WordlistLoader.java 150527 2004-09-20 19:27:01Z dnaber $

Fields Summary
Constructors Summary
Methods Summary
public static java.util.HashSetgetWordSet(java.io.File wordfile)
Loads a text file and adds every line as an entry to a HashSet (omitting leading and trailing whitespace). Every line of the file should contain only one word. The words need to be in lowercase if you make use of an Analyzer which uses LowerCaseFilter (like GermanAnalyzer).

param
wordfile File containing the wordlist
return
A HashSet with the file's words

    HashSet result = new HashSet();
    FileReader freader = null;
    LineNumberReader lnr = null;
    try {
      freader = new FileReader(wordfile);
      lnr = new LineNumberReader(freader);
      String word = null;
      while ((word = lnr.readLine()) != null) {
        result.add(word.trim());
      }
    }
    finally {
      if (lnr != null)
        lnr.close();
      if (freader != null)
        freader.close();
    }
    return result;
  
public static java.util.HashtablegetWordtable(java.lang.String path, java.lang.String wordfile)

param
path Path to the wordlist
param
wordfile Name of the wordlist
deprecated
Use {@link #getWordSet(File)} getWordSet(File)} instead

    return getWordtable(new File(path, wordfile));
  
public static java.util.HashtablegetWordtable(java.lang.String wordfile)

param
wordfile Complete path to the wordlist
deprecated
Use {@link #getWordSet(File)} getWordSet(File)} instead

    return getWordtable(new File(wordfile));
  
public static java.util.HashtablegetWordtable(java.io.File wordfile)

param
wordfile File object that points to the wordlist
deprecated
Use {@link #getWordSet(File)} getWordSet(File)} instead

    HashSet wordSet = (HashSet)getWordSet(wordfile);
    Hashtable result = makeWordTable(wordSet);
    return result;
  
private static java.util.HashtablemakeWordTable(java.util.HashSet wordSet)
Builds a wordlist table, using words as both keys and values for backward compatibility.

param
wordSet stopword set

    Hashtable table = new Hashtable();
    for (Iterator iter = wordSet.iterator(); iter.hasNext();) {
      String word = (String)iter.next();
      table.put(word, word);
    }
    return table;