3 using System
.Collections
;
5 namespace Lucene
.Net
.Analysis
.De
7 /* ====================================================================
8 * The Apache Software License, Version 1.1
10 * Copyright (c) 2001 The Apache Software Foundation. All rights
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in
22 * the documentation and/or other materials provided with the
25 * 3. The end-user documentation included with the redistribution,
26 * if any, must include the following acknowledgment:
27 * "This product includes software developed by the
28 * Apache Software Foundation (http://www.apache.org/)."
29 * Alternately, this acknowledgment may appear in the software itself,
30 * if and wherever such third-party acknowledgments normally appear.
32 * 4. The names "Apache" and "Apache Software Foundation" and
33 * "Apache Lucene" must not be used to endorse or promote products
34 * derived from this software without prior written permission. For
35 * written permission, please contact apache@apache.org.
37 * 5. Products derived from this software may not be called "Apache",
38 * "Apache Lucene", nor may "Apache" appear in their name, without
39 * prior written permission of the Apache Software Foundation.
41 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
42 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
43 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
44 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
45 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
47 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
48 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
49 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
50 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
51 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * ====================================================================
55 * This software consists of voluntary contributions made by many
56 * individuals on behalf of the Apache Software Foundation. For more
57 * information on the Apache Software Foundation, please see
58 * <http://www.apache.org/>.
62 /// Loads a text file and adds every line as an entry to a Hashtable. Every line
63 /// should contain only one word. If the file is not found or on any error, an
64 /// empty table is returned.
66 /// <author>Gerhard Schwarz</author>
67 /// <version>$Id: WordlistLoader.cs,v 1.1.1.1 2004/04/29 22:53:51 trow Exp $</version>
68 public class WordlistLoader
72 /// <param name="path">Path to the wordlist</param>
73 /// <param name="wordfile">Name of the wordlist</param>
74 /// <returns></returns>
75 public static Hashtable
GetWordtable( String path
, String wordfile
)
77 if ( path
== null || wordfile
== null )
79 return new Hashtable();
81 return GetWordtable(new FileInfo(path
+ "\\" + wordfile
));
86 /// <param name="wordfile">Complete path to the wordlist</param>
87 /// <returns></returns>
88 public static Hashtable
GetWordtable( String wordfile
)
90 if ( wordfile
== null )
92 return new Hashtable();
94 return GetWordtable( new FileInfo( wordfile
) );
100 /// <param name="wordfile">File containing the wordlist</param>
101 /// <returns></returns>
102 public static Hashtable
GetWordtable( FileInfo wordfile
)
104 if ( wordfile
== null )
106 return new Hashtable();
108 Hashtable result
= null;
111 StreamReader lnr
= new StreamReader(wordfile
.FullName
);
113 String
[] stopwords
= new String
[100];
115 while ( ( word
= lnr
.ReadLine() ) != null )
118 if ( wordcount
== stopwords
.Length
)
120 String
[] tmp
= new String
[stopwords
.Length
+ 50];
121 Array
.Copy( stopwords
, 0, tmp
, 0, wordcount
);
124 stopwords
[wordcount
-1] = word
;
126 result
= MakeWordTable( stopwords
, wordcount
);
128 // On error, use an empty table
131 result
= new Hashtable();
137 /// Builds the wordlist table.
139 /// <param name="words">Word that where read</param>
140 /// <param name="length">Amount of words that where read into <tt>words</tt></param>
141 /// <returns></returns>
142 private static Hashtable
MakeWordTable( String
[] words
, int length
)
144 Hashtable table
= new Hashtable( length
);
145 for ( int i
= 0; i
< length
; i
++ )
147 table
.Add(words
[i
], words
[i
]);