/// <exception cref="System.IO.IOException"/> public PerformActionUpdateModel(Socket socket, int clientNumber) { this.socket = socket; this.clientNumber = clientNumber; this.annotate = new TextAnnotationPatterns(); Log("New connection with client# " + clientNumber + " at " + socket); }
/// <summary>Actually perform the GET request, given all the relevant information (already sanity checked).</summary> /// <remarks> /// Actually perform the GET request, given all the relevant information (already sanity checked). /// This is the meat of the servlet code. /// </remarks> /// <param name="out">The writer to write the output to.</param> /// <param name="q">The query string.</param> /// <exception cref="System.Exception"/> private void Run(PrintWriter @out, string q, string seedWords, string model) { // Clean the string a bit q = q.Trim(); if (q.Length == 0) { return; } char lastChar = q[q.Length - 1]; if (lastChar != '.' && lastChar != '!' && lastChar != '?') { q = q + "."; } TextAnnotationPatterns annotate = new TextAnnotationPatterns(); string quotedString = Quote(q); string jsonObject = "{\"input\":" + quotedString + ",\"seedWords\":{\"NAME\":[\"" + StringUtils.Join(seedWords.Split("[,;]"), "\",\"") + "\"]}}"; bool testmode = true; if (Sharpen.Runtime.EqualsIgnoreCase(model, "new")) { testmode = false; } logger.Info("Testmode is " + testmode); logger.Info("model is " + model); string suggestions; // Collect results if (testmode) { Properties testProps = new Properties(); if (testPropertiesFile != null && new File(testPropertiesFile).Exists()) { try { string props = IOUtils.StringFromFile(testPropertiesFile); testProps.Load(new StringReader(props)); } catch (IOException e) { WriteError(e, @out, "Cannot read test properties file"); return; } } else { WriteError(new Exception("test prop file not found"), @out, "Test properties file not found"); return; } string modelDir = GetServletContext().GetRealPath("/WEB-INF/data/" + modelNametoDirName[model]); testProps.SetProperty("patternsWordsDir", modelDir); logger.Info("Reading saved model from " + modelDir); string seedWordsFiles = "NAME," + modelDir + "/NAME/seedwords.txt," + modelDir + "/NAME/phrases.txt"; string modelPropertiesFile = modelDir + "/model.properties"; logger.Info("Loading model properties from " + modelPropertiesFile); string stopWordsFile = modelDir + "/stopwords.txt"; bool writeOutputFile = false; annotate.SetUpProperties(jsonObject, false, writeOutputFile, seedWordsFiles); suggestions = annotate.SuggestPhrasesTest(testProps, modelPropertiesFile, stopWordsFile); } else { bool writeOutputFile = false; annotate.SetUpProperties(jsonObject, false, writeOutputFile, null); annotate.ProcessText(writeOutputFile); suggestions = annotate.SuggestPhrases(); } @out.Print(suggestions); }