/// <summary> /// Command line arguments for this program: /// <br /> /// -output: the model file to output /// -input: a list of model files to input /// </summary> public static void Main(string[] args) { string outputModelFilename = null; IList <string> inputModelFilenames = Generics.NewArrayList(); for (int argIndex = 0; argIndex < args.Length;) { if (Sharpen.Runtime.EqualsIgnoreCase(args[argIndex], "-output")) { outputModelFilename = args[argIndex + 1]; argIndex += 2; } else { if (Sharpen.Runtime.EqualsIgnoreCase(args[argIndex], "-input")) { for (++argIndex; argIndex < args.Length && !args[argIndex].StartsWith("-"); ++argIndex) { Sharpen.Collections.AddAll(inputModelFilenames, Arrays.AsList(args[argIndex].Split(","))); } } else { throw new Exception("Unknown argument " + args[argIndex]); } } } if (outputModelFilename == null) { log.Info("Need to specify output model name with -output"); System.Environment.Exit(2); } if (inputModelFilenames.Count == 0) { log.Info("Need to specify input model names with -input"); System.Environment.Exit(2); } log.Info("Averaging " + inputModelFilenames); log.Info("Outputting result to " + outputModelFilename); LexicalizedParser lexparser = null; IList <DVModel> models = Generics.NewArrayList(); foreach (string filename in inputModelFilenames) { LexicalizedParser parser = ((LexicalizedParser)LexicalizedParser.LoadModel(filename)); if (lexparser == null) { lexparser = parser; } models.Add(DVParser.GetModelFromLexicalizedParser(parser)); } IList <TwoDimensionalMap <string, string, SimpleMatrix> > binaryTransformMaps = CollectionUtils.TransformAsList(models, null); IList <TwoDimensionalMap <string, string, SimpleMatrix> > binaryScoreMaps = CollectionUtils.TransformAsList(models, null); IList <IDictionary <string, SimpleMatrix> > unaryTransformMaps = CollectionUtils.TransformAsList(models, null); IList <IDictionary <string, SimpleMatrix> > unaryScoreMaps = CollectionUtils.TransformAsList(models, null); IList <IDictionary <string, SimpleMatrix> > wordMaps = CollectionUtils.TransformAsList(models, null); TwoDimensionalMap <string, string, SimpleMatrix> binaryTransformAverages = AverageBinaryMatrices(binaryTransformMaps); TwoDimensionalMap <string, string, SimpleMatrix> binaryScoreAverages = AverageBinaryMatrices(binaryScoreMaps); IDictionary <string, SimpleMatrix> unaryTransformAverages = AverageUnaryMatrices(unaryTransformMaps); IDictionary <string, SimpleMatrix> unaryScoreAverages = AverageUnaryMatrices(unaryScoreMaps); IDictionary <string, SimpleMatrix> wordAverages = AverageUnaryMatrices(wordMaps); DVModel newModel = new DVModel(binaryTransformAverages, unaryTransformAverages, binaryScoreAverages, unaryScoreAverages, wordAverages, lexparser.GetOp()); DVParser newParser = new DVParser(newModel, lexparser); newParser.SaveModel(outputModelFilename); }