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"); } }
private bool LoadPartOfSpeechTagger(string filePath) { try { AnsDecoderStream stream = new AnsDecoderStream( new FileStream(filePath, FileMode.Open, FileAccess.Read) ); PartOfSpeechTagger = AveragedPerceptronTagger.Load(stream); stream.Close(); } catch (IOException) { return(false); } return(true); }
private static float CalcSimilarity(RepairJobEntry query, RepairJobEntry other) { IKeywordPredictor keyPred = NaiveBayesKeywordPredictor.GetGlobalModel(); AveragedPerceptronTagger tagger = AveragedPerceptronTagger.GetTagger(); List <String> tokened = SentenceTokenizer.TokenizeSentence(query.Complaint); List <List <String> > tagged = tagger.Tag(tokened); List <String> InputComplaintKeywords = keyPred.PredictKeywords(tagged); tokened = SentenceTokenizer.TokenizeSentence(query.Problem); tagged = tagger.Tag(tokened); List <String> InputProblemKeywords = keyPred.PredictKeywords(tagged); float score = 0; tokened = SentenceTokenizer.TokenizeSentence(other.Complaint); tagged = tagger.Tag(tokened); List <String> JobComplaintKeywords = keyPred.PredictKeywords(tagged); tokened = SentenceTokenizer.TokenizeSentence(other.Problem); tagged = tagger.Tag(tokened); List <String> JobProblemKeywords = keyPred.PredictKeywords(tagged); foreach (String keyword in JobComplaintKeywords) { if (InputComplaintKeywords.Contains(keyword)) { score++; } } foreach (String keyword in JobProblemKeywords) { if (InputProblemKeywords.Contains(keyword)) { score++; } } return(score / (JobComplaintKeywords.Count + JobProblemKeywords.Count)); }
static void Main(string[] args) { Console.WriteLine(DateTime.Now.ToLocalTime().ToString()); DatabaseConfigurationFileContents config; try { config = RetrieveConfiguration(); } catch (ThreadInterruptedException) { return; } if (config == null) { Console.WriteLine("Failed to retrieve or restore database configuration file. Exiting"); return; } bool res = MySqlDataManipulator.GlobalConfiguration.Connect(new MySqlConnectionString(config.Host, config.Database, config.User).ConstructConnectionString(config.Pass.ConvertToString())); if (!res && MySqlDataManipulator.GlobalConfiguration.LastException.Number != 1049 && MySqlDataManipulator.GlobalConfiguration.LastException.Number != 0) { Console.WriteLine("Encountered an error opening the global configuration connection"); Console.WriteLine(MySqlDataManipulator.GlobalConfiguration.LastException.Message); return; } if (!MySqlDataManipulator.GlobalConfiguration.ValidateDatabaseIntegrity(new MySqlConnectionString(config.Host, null, config.User).ConstructConnectionString(config.Pass.ConvertToString()), config.Database)) { Console.WriteLine("Encountered an error opening the global configuration connection"); Console.WriteLine(MySqlDataManipulator.GlobalConfiguration.LastException.Message); return; } MySqlDataManipulator.GlobalConfiguration.Close(); CommandLineArgumentParser parser = new CommandLineArgumentParser(args); MySqlDataManipulator.GlobalConfiguration.Connect(new MySqlConnectionString(config.Host, config.Database, config.User).ConstructConnectionString(config.Pass.ConvertToString())); config.Pass.Dispose(); config = null; bool exit = DatabaseEntityCreationUtilities.PerformRequestedCreation(MySqlDataManipulator.GlobalConfiguration, parser); MySqlDataManipulator.GlobalConfiguration.Close(); if (exit) { return; } if (!GlobalModelHelper.LoadOrTrainGlobalModels(ReflectionHelper.GetAllKeywordPredictors())) { throw new NullReferenceException("One or more global models failed to load. Server cannot start."); } else if (AveragedPerceptronTagger.GetTagger() == null) { throw new NullReferenceException("Failed to load the Averaged Perceptron Tagger"); } Logger.GetLogger(Logger.LoggerDefaultFileLocations.DEFAULT).Log(Logger.LogLevel.INFO, "Server is starting up"); using (Logger.Disposer) { Thread t = new Thread(RenewCertificate); t.Start(); Thread train = new Thread(PerformTraining); train.Start(); var server = ApiLoader.LoadApiAndListen(16384); while (server.IsAlive) { Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(true); if (key.Key == ConsoleKey.Enter) { server.Close(); } } } t.Interrupt(); train.Interrupt(); } //QueryProcessor processor = new QueryProcessor(QueryProcessorSettings.GenerateDefaultSettings()); //processor.ProcessQuery(new Util.MechanicQuery("autocar", "xpeditor", null, null, "runs rough")); }