Lucene.Net  3.0.3
Lucene.Net is a port of the Lucene search engine library, written in C# and targeted at .NET runtime users.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
PlainTextDictionary.cs
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 using System;
19 
20 namespace SpellChecker.Net.Search.Spell
21 {
22 
23 
24  /// <summary> Dictionary represented by a file text.
25  /// <p/>Format allowed: 1 word per line:<br/>
26  /// word1<br/>
27  /// word2<br/>
28  /// word3<br/>
29  ///
30  /// </summary>
31  /// <author> Nicolas Maisonneuve
32  /// </author>
33  public class PlainTextDictionary : IDictionary, System.Collections.Generic.IEnumerable<string>
34  {
35  virtual public System.Collections.Generic.IEnumerator<string> GetWordsIterator()
36  {
37  return new FileIterator(this);
38  }
39 
40  public System.Collections.Generic.IEnumerator<string> GetEnumerator()
41  {
42  return GetWordsIterator();
43  }
44 
45  System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
46  {
47  return GetEnumerator();
48  }
49 
50  private System.IO.StreamReader in_Renamed;
51  private System.String line;
52  private bool has_next_called;
53 
54  public PlainTextDictionary(System.IO.FileInfo file)
55  {
56  in_Renamed = new System.IO.StreamReader(new System.IO.StreamReader(file.FullName, System.Text.Encoding.Default).BaseStream, new System.IO.StreamReader(file.FullName, System.Text.Encoding.Default).CurrentEncoding);
57  }
58 
59  public PlainTextDictionary(System.IO.Stream dictFile)
60  {
61  in_Renamed = new System.IO.StreamReader(new System.IO.StreamReader(dictFile, System.Text.Encoding.Default).BaseStream, new System.IO.StreamReader(dictFile, System.Text.Encoding.Default).CurrentEncoding);
62  }
63 
64 
65  internal sealed class FileIterator : System.Collections.Generic.IEnumerator<string>
66  {
67  public FileIterator(PlainTextDictionary enclosingInstance)
68  {
69  InitBlock(enclosingInstance);
70  }
71 
72  private void InitBlock(PlainTextDictionary enclosingInstance)
73  {
74  this.enclosingInstance = enclosingInstance;
75  }
76 
77  private PlainTextDictionary enclosingInstance;
78 
79  public string Current
80  {
81  get
82  {
83  if (!Enclosing_Instance.has_next_called)
84  {
85  MoveNext();
86  }
87  Enclosing_Instance.has_next_called = false;
88  return Enclosing_Instance.line;
89  }
90  }
91 
92  object System.Collections.IEnumerator.Current
93  {
94  get
95  {
96  if (!Enclosing_Instance.has_next_called)
97  {
98  MoveNext();
99  }
100  Enclosing_Instance.has_next_called = false;
101  return Enclosing_Instance.line;
102  }
103 
104  }
105 
106  public PlainTextDictionary Enclosing_Instance
107  {
108  get { return enclosingInstance; }
109 
110  }
111 
112  public bool MoveNext()
113  {
114  Enclosing_Instance.has_next_called = true;
115  try
116  {
117  Enclosing_Instance.line = Enclosing_Instance.in_Renamed.ReadLine();
118  }
119  catch (System.IO.IOException ex)
120  {
121  System.Console.Error.WriteLine(ex.StackTrace);
122  Enclosing_Instance.line = null;
123  return false;
124  }
125  return (Enclosing_Instance.line != null) ? true : false;
126  }
127 
128 
129  public void Remove()
130  {
131  }
132 
133  public void Reset()
134  {
135  }
136 
137  public void Dispose()
138  {
139 
140  }
141  }
142  }
143 }