public DatabaseQueryProcessor(DatabaseQueryProcessorSettings settingsIn = null) { if (settingsIn == null) { settingsIn = DatabaseQueryProcessorSettings.GenerateDefaultSettings(); } KeywordTagger = AveragedPerceptronTagger.GetTagger(); var keywordPredictorType = Type.GetType("OldManInTheShopServer.Models.KeywordPrediction." + settingsIn.KeywordPredictorIdString); if (keywordPredictorType == null) { throw new NullReferenceException("Type string " + settingsIn.KeywordPredictorIdString + " was not found matching a known class in KeywordPrediction"); } try { KeywordPredictor = keywordPredictorType.GetMethod("GetGlobalModel").Invoke(null, null) as IKeywordPredictor; } catch (NullReferenceException e) { Console.WriteLine("Type " + settingsIn.KeywordPredictorIdString + " did not contain a GetGlobalModel method. It needs to have one."); throw e; } if (KeywordPredictor == null) { throw new InvalidCastException("Loaded class could not be cast to IKeywordPredictor"); } var keywordClustererType = Type.GetType("OldManInTheShopServer.Models.KeywordClustering." + settingsIn.KeywordClustererIdString); if (keywordClustererType == null) { throw new NullReferenceException("Type string " + settingsIn.KeywordClustererIdString + " was not found matching a known class in KeywordClustering"); } KeywordClusterer = keywordClustererType.GetConstructor(new Type[0]).Invoke(null) as IDatabaseKeywordClusterer; if (KeywordClusterer == null) { throw new InvalidCastException("Loaded class could not be cast to IDatabaseKeywordClusterer"); } var problemPredictorType = Type.GetType("OldManInTheShopServer.Models.QueryProblemPrediction." + settingsIn.ProblemPredictorIdString); if (keywordPredictorType == null) { throw new NullReferenceException("Type string " + settingsIn.ProblemPredictorIdString + " was not found matching a known class in QueryProblemPrediction"); } ProblemPredictor = problemPredictorType.GetConstructor(new Type[0]).Invoke(null) as IDatabaseQueryProblemPredictor; if (ProblemPredictor == null) { throw new InvalidCastException("Loaded class could not be cast to IDatabaseQueryProblemPredictor"); } }
public static DatabaseQueryProcessorSettings GenerateDefaultSettings() { DatabaseQueryProcessorSettings ret = new DatabaseQueryProcessorSettings() { TaggerFilePath = "InitialData/averaged_perceptron_tagger.ans", KeywordPredictorFilePath = "InitialData/nb_keyword_predictor.ans", KeywordClustererIdString = "DatabaseKeywordSimilarityClusterer", KeywordPredictorIdString = "NaiveBayesKeywordPredictor", ProblemPredictorIdString = "DatabaseQueryProblemPredictor" }; return(ret); }
public static DatabaseQueryProcessorSettings RetrieveCompanySettings(MySqlDataManipulator manipulator, int companyId) { DatabaseQueryProcessorSettings companySettings = new DatabaseQueryProcessorSettings(); List <CompanySettingsEntry> settings = manipulator.GetCompanySettings(companyId); foreach (CompanySettingsEntry setting in settings) { if (CompanySettingsKey.KeywordClusterer.Equals(setting.SettingKey)) { if (setting.SettingValue.Equals("Similarity")) { companySettings.KeywordClustererIdString = "DatabaseKeywordSimilarityClusterer"; } else { companySettings.KeywordClustererIdString = "DatabaseKeywordSimilarityClusterer"; } } else if (CompanySettingsKey.KeywordPredictor.Equals(setting.SettingKey)) { if (setting.SettingValue.Equals("Bayesian")) { companySettings.KeywordPredictorIdString = "NaiveBayesKeywordPredictor"; } else { companySettings.KeywordPredictorIdString = "NaiveBayesKeywordPredictor"; } } else if (CompanySettingsKey.ProblemPredictor.Equals(setting.SettingKey)) { if (setting.SettingValue.Equals("Database")) { companySettings.ProblemPredictorIdString = "DatabaseQueryProblemPredictor"; } else { companySettings.ProblemPredictorIdString = "DatabaseQueryProblemPredictor"; } } } return(companySettings); }