public override void run(string format, string[] args) { if (0 == args.Length) { Console.WriteLine(Help); } else { format = args[0]; ObjectStreamFactory streamFactory = getStreamFactory(format); string[] formatArgs = new string[args.Length - 1]; Array.Copy(args, 1, formatArgs, 0, formatArgs.Length); string helpString = createHelpString(format, ArgumentParser.createUsage(streamFactory.Parameters)); if (0 == formatArgs.Length || (1 == formatArgs.Length && "help".Equals(formatArgs[0]))) { Console.WriteLine(helpString); Environment.Exit(0); } string errorMessage = ArgumentParser.validateArgumentsLoudly(formatArgs, streamFactory.Parameters); if (null != errorMessage) { throw new TerminateToolException(1, errorMessage + "\n" + helpString); } ObjectStream <T> sampleStream = streamFactory.create(formatArgs); try { object sample; while ((sample = sampleStream.read()) != null) { Console.WriteLine(sample.ToString()); } } catch (IOException e) { throw new TerminateToolException(-1, "IO error while converting data : " + e.Message, e); } finally { if (sampleStream != null) { try { sampleStream.close(); } catch (IOException) { // sorry that this can fail } } } } }
public override void run(string format, string[] args) { validateAllArgs(args, this.paramsClass, format); @params = ArgumentParser.parse(ArgumentParser.filter(args, this.paramsClass), this.paramsClass); factory = getStreamFactory(format); string[] fargs = ArgumentParser.filter(args, factory.Parameters); validateFactoryArgs(factory, fargs); sampleStream = factory.create(fargs); }
public sealed override void run(string format, string[] args) { ModelUpdaterParams @params = validateAndParseParams <ModelUpdaterParams>(ArgumentParser.filter(args, typeof(ModelUpdaterParams)), typeof(ModelUpdaterParams)); // Load model to be updated Jfile modelFile = @params.Model; ParserModel originalParserModel = (new ParserModelLoader()).load(modelFile); ObjectStreamFactory factory = getStreamFactory(format); string[] fargs = ArgumentParser.filter(args, factory.Parameters); validateFactoryArgs(factory, fargs); ObjectStream <Parse> sampleStream = factory.create <Parse>(fargs); ParserModel updatedParserModel; try { updatedParserModel = trainAndUpdate(originalParserModel, sampleStream, @params); } catch (IOException e) { throw new TerminateToolException(-1, "IO error while reading training data or indexing data: " + e.Message, e); } finally { try { sampleStream.close(); } catch (IOException) { // sorry that this can fail } } CmdLineUtil.writeModel("parser", modelFile, updatedParserModel); }