Class CmdLineUtil

Namespace
NOpenNLP.Tools.Cmdline
Assembly
nopennlp.dll

Util class for simple file checks, listings and error handling.

Note: Do not use this class, internal use only!
public static class CmdLineUtil
Inheritance
CmdLineUtil
Inherited Members

Fields

IoBufferSize

public const int IoBufferSize = 1048576

Field Value

int

Methods

CheckInputFile(string, FileInfo)

Check that the given input file is valid.

To pass the test it must:

  • exist
  • not be a directory
  • accessibly
public static void CheckInputFile(string name, FileInfo inFile)

Parameters

name string

the name which is used to refer to the file in an error message, it should start with a capital letter.

inFile FileInfo

the particular file to check to qualify an input file

Exceptions

TerminateToolException

if the test does not pass this exception is thrown and an error message is printed to the console.

CheckLanguageCode(string)

public static void CheckLanguageCode(string code)

Parameters

code string

CheckOutputFile(string, FileInfo)

Tries to ensure that it is possible to write to an output file.

The method does nothing if it is possible to write, otherwise it prints an appropriate error message and a TerminateToolException is thrown.

Computing the contents of an output file (e.g. ME model) can be very time consuming. Prior to this computation it should be checked once that writing this output file is possible to be able to fail fast if not.

public static void CheckOutputFile(string name, FileInfo outFile)

Parameters

name string

human-friendly file name, for example perceptron model

outFile FileInfo

the file

ContainsParam(string, string[])

public static bool ContainsParam(string param, string[] args)

Parameters

param string
args string[]

Returns

bool

CreateInputStreamFactory(FileInfo)

public static IInputStreamFactory CreateInputStreamFactory(FileInfo file)

Parameters

file FileInfo

Returns

IInputStreamFactory

CreateObjectStreamError(IOException)

public static TerminateToolException CreateObjectStreamError(IOException e)

Parameters

e IOException

Returns

TerminateToolException

GetDoubleParameter(string, string[])

Retrieves the specified parameter from the specified arguments.

public static double? GetDoubleParameter(string param, string[] args)

Parameters

param string
args string[]

Returns

double?

GetIntParameter(string, string[])

Retrieves the specified parameter from the specified arguments.

public static int? GetIntParameter(string param, string[] args)

Parameters

param string
args string[]

Returns

int?

GetParameter(string, string[])

Retrieves the specified parameter from the given arguments.

public static string? GetParameter(string param, string[] args)

Parameters

param string
args string[]

Returns

string

GetParameterIndex(string, string[])

Returns the index of the parameter in the arguments, or -1 if the parameter is not found.

public static int GetParameterIndex(string param, string[] args)

Parameters

param string
args string[]

Returns

int

HandleCreateObjectStreamError(IOException)

public static void HandleCreateObjectStreamError(IOException e)

Parameters

e IOException

HandleStdinIoError(IOException)

public static void HandleStdinIoError(IOException e)

Parameters

e IOException

LoadTrainingParameters(string?, bool)

Loads the training parameters from paramFile, which is optional: passing null is allowed and yields null.

public static TrainingParameters? LoadTrainingParameters(string? paramFile, bool supportSequenceTraining)

Parameters

paramFile string
supportSequenceTraining bool

Returns

TrainingParameters

OpenInFile(FileInfo)

public static Stream OpenInFile(FileInfo file)

Parameters

file FileInfo

Returns

Stream

WriteModel(string, FileInfo, BaseModel)

Writes a BaseModel to disk. Occurring errors are printed to the console to inform the user.

public static void WriteModel(string modelName, FileInfo modelFile, BaseModel model)

Parameters

modelName string

type of the model, name is used in error messages.

modelFile FileInfo

output file of the model

model BaseModel

the model itself which should be written to disk