예제 #1
0
        // its optional, passing null is allowed
        public static TrainingParameters loadTrainingParameters(string paramFile, bool supportSequenceTraining)
        {
            TrainingParameters @params = null;

            if (paramFile != null)
            {
                checkInputFile("Training Parameter", new Jfile(paramFile));

                InputStream paramsIn = null;
                try
                {
                    paramsIn = new FileInputStream(new Jfile(paramFile));

                    @params = new TrainingParameters(paramsIn);
                }
                catch (IOException e)
                {
                    throw new TerminateToolException(-1, "Error during parameters loading: " + e.Message, e);
                }
                finally
                {
                    try
                    {
                        if (paramsIn != null)
                        {
                            paramsIn.close();
                        }
                    }
                    catch (IOException)
                    {
                        //sorry that this can fail
                    }
                }

                if (!TrainUtil.isValid(@params.getSettings()))
                {
                    throw new TerminateToolException(1, "Training parameters file '" + paramFile + "' is invalid!");
                }

                if (!supportSequenceTraining && TrainUtil.isSequenceTraining(@params.getSettings()))
                {
                    throw new TerminateToolException(1, "Sequence training is not supported!");
                }
            }

            return(@params);
        }