private static bool LoadModel(KeywordPredictorFileMapping mapping) { IKeywordPredictor predictor = mapping.KeywordPredictorType.GetMethod("GetGlobalModel").Invoke(null, null) as IKeywordPredictor; Stream streamIn = null; try { streamIn = new AnsDecoderStream(new FileStream(mapping.DefaultFileLocation, FileMode.Open, FileAccess.Read)); } catch (FileNotFoundException) { return(false); } using (streamIn) { return(predictor.Load(streamIn)); } }
/** * Summary: * Loads the the currently selected KeywordPredictor from the file specified * Note: * This method does not do the above currently. It is hard coded to use the NaiveBayesKeywordPredictor. * This is a hold out until the proper method is in place to switch between implementations * through a configuration file. */ private bool LoadKeywordPredictor(string filePath) { KeywordPredictor = new NaiveBayesKeywordPredictor(); AnsDecoderStream streamIn; try { streamIn = new AnsDecoderStream( new FileStream(filePath, FileMode.Open, FileAccess.Read) ); } catch (IOException) { return(false); } if (!KeywordPredictor.Load(streamIn)) { streamIn.Close(); KeywordPredictorValid = false; return(false); } streamIn.Close(); KeywordPredictorValid = true; return(true); }