/// <summary> /// Filter out stop words from the list of HTML string. Get count for each word. /// </summary> /// <param name="listOfRawText"></param> /// <param name="stopWordList"></param> /// <returns>List of ResultBO. ResultBO fields: Word, Count</returns> public List <ResultBO> GetSEOResult(List <string> listOfRawText, List <string> stopWordList) { if (listOfRawText == null) { throw new Exception("empty listOfRawText"); } else { if (listOfRawText.Count < 1) { throw new Exception("empty listOfRawText"); } } if (stopWordList == null) { throw new Exception("empty stopWordList"); } else { if (stopWordList.Count < 1) { throw new Exception("empty stopWordList"); } } List <string> queryresult = listOfRawText.Where(item => !stopWordList.Contains(item)).ToList(); List <ResultBO> resultBoList = new List <ResultBO>(); foreach (string a in queryresult) { var checking = resultBoList.Where(o => o.Word == a).FirstOrDefault(); if (checking == null) { ResultBO resultBO = new ResultBO(); resultBO.Word = a; resultBO.Count = countOfString(a, queryresult); resultBoList.Add(resultBO); } } return(resultBoList); }
/// <summary> /// Gets results since 2001 and saves them to a JSON file /// </summary> private void SaveResultsToJSON() { var resultBO = new ResultBO(); // Get results list since 2001 for (int i = 2000; i < DateTime.Now.Year; i++) { var year = Convert.ToString(i + 1); Updater uiUpdater = new Updater(UpdateYearLabel); Dispatcher.BeginInvoke(DispatcherPriority.Send, uiUpdater, year); results.AddRange(resultBO.GetResultsByYear(year)); } // Save result as a JSON file File.Delete(@"historic_data.json"); using (FileStream fs = File.Open(@"historic_data.json", FileMode.Create)) using (StreamWriter sw = new StreamWriter(fs)) using (JsonWriter jw = new JsonTextWriter(sw)) { jw.Formatting = Formatting.Indented; JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(jw, results); } }