SMILE.NET Learning: TextParser

From DSL

Jump to: navigation, search

This is a utility class that implements a simple parser for text files.

[edit] Interfaces

  • IDisposable

The .NET garbage collector automatically releases the memory allocated to objects when they are no longer used. It is, however, unpredictable when garbage collection will occur. Furthermore, the garbage collector has no knowledge of unmanaged resources such as the DSL_textParser C++ object wrapped by TextParser. The IDisposable.Dispose() method provides means to ensure that wrapped object is deleted before garbage collection occurs:

  TextParser tp = new TextParser();
  try {
    // use tp here
  }
  finally {
    if (tp != null) tp.Dispose();
  }

C# has the using statement, which is equivalent to the try/finally/Dispose construct in the preceding example:

  using (TextParser tp = new TextParser()) {
    // use tp here
  }


[edit] Properties

  • bool PreprocessFileEnabled (get, set)

When set to true, the parser produces a text file with parsed information. The file carries the name of original data file and the extension .glw (default = false).


  • bool TypesSpecified (get, set)

The marker that indicates if in the header of the data types are specified. There are three possible keywords: ordinal, discrete, and continuous. By default, the parser assumes the discrete type (values are treated as labels) (default = false).


  • bool UseHeader (get, set)

Defines if the first row in the text file contains the labels of the variables (default = true).


[edit] Methods

  • Dataset GetDataSet()

Returns the parsed data set. Note that you have to call Parse() prior to calling this method.


  • void Parse(string filename)

Parses the file specified by filename. This method can throw a FileNotFoundException and a SmileException.

Personal tools