/// <summary> /// Loads the articles. /// </summary> private void LoadArticles() { Results = IE_lib.Main.View(Path); ListRawListArticles = new List <ListArticle>(); if (Results == null) { MessageBox.Show(Application.Current.MainWindow, "There was a problem in loading the result files. Either the file selected does not contain any articles or the other result files are missing. \n\nKindly check your result files.", "Loading result files"); } else { foreach (DisplayArticle d in Results.ListDisplayArticles) { ListRawListArticles.Add(new ListArticle() { DisplayArticle = d, MatchedString = String.Format("{0} ยท {1}", d.Article.Date, d.Article.Author) }); } } if (!IsAdvanced) { DisplayArticles(ListRawListArticles); } }
/// <summary> /// Views the specified path. /// </summary> /// <param name="path">The path.</param> /// <returns>Parsed results to be used for viewing</returns> public static ParsedResults View(string path) { if (path.Contains("_inverted_index")) { path = path.Replace("_inverted_index", ""); } string invertedIndexDestinationPath = path.Insert(path.Length - 4, "_inverted_index"); string formattedDateDestinationPath = path.Insert(path.Length - 4, "_format_date"); FileParser fileParser = new FileParser(); List <Article> listArticles = fileParser.parseFile(path); List <Annotation> listAnnotations = fileParser.parseAnnotations(path); List <Annotation> listFormattedDateAnnotations = fileParser.parseAnnotations(formattedDateDestinationPath); ParsedResults results = new ParsedResults(); results.FilePath = path; results.ListDisplayArticles = new List <DisplayArticle>(); results.WhoReverseIndex = new Dictionary <string, List <int> >(); results.WhenReverseIndex = new Dictionary <string, List <int> >(); results.WhereReverseIndex = new Dictionary <string, List <int> >(); results.WhatReverseIndex = new Dictionary <string, List <int> >(); results.WhyReverseIndex = new Dictionary <string, List <int> >(); if (listArticles.Count <= 0 || listAnnotations.Count <= 0) { return(null); } if (File.Exists(formattedDateDestinationPath) && listAnnotations.Count == listFormattedDateAnnotations.Count) { foreach (int i in Enumerable.Range(0, listAnnotations.Count())) { listAnnotations[i].Index = i; listAnnotations[i].FormattedWhen = listFormattedDateAnnotations[i].When; results.ListDisplayArticles.Add(new DisplayArticle() { Article = listArticles[i], Annotation = listAnnotations[i] }); } } else { return(null); } if (File.Exists(invertedIndexDestinationPath)) { XmlDocument doc = new XmlDocument(); doc.Load(invertedIndexDestinationPath); XmlNodeList whoNodes = doc.DocumentElement.SelectNodes("/data/who/entry"); XmlNodeList whenNodes = doc.DocumentElement.SelectNodes("/data/when/entry"); XmlNodeList whereNodes = doc.DocumentElement.SelectNodes("/data/where/entry"); XmlNodeList whatNodes = doc.DocumentElement.SelectNodes("/data/what/entry"); XmlNodeList whyNodes = doc.DocumentElement.SelectNodes("/data/why/entry"); foreach (XmlNode entry in whoNodes) { List <int> indices = new List <int>(); foreach (XmlNode index in entry.SelectNodes("articleIndex")) { indices.Add(Convert.ToInt32(index.InnerText)); } results.WhoReverseIndex.Add(entry["text"].InnerText, indices); } foreach (XmlNode entry in whenNodes) { List <int> indices = new List <int>(); foreach (XmlNode index in entry.SelectNodes("articleIndex")) { indices.Add(Convert.ToInt32(index.InnerText)); } results.WhenReverseIndex.Add(entry.SelectSingleNode("text").InnerText, indices); } foreach (XmlNode entry in whereNodes) { List <int> indices = new List <int>(); foreach (XmlNode index in entry.SelectNodes("articleIndex")) { indices.Add(Convert.ToInt32(index.InnerText)); } results.WhereReverseIndex.Add(entry.SelectSingleNode("text").InnerText, indices); } foreach (XmlNode entry in whatNodes) { List <int> indices = new List <int>(); foreach (XmlNode index in entry.SelectNodes("articleIndex")) { indices.Add(Convert.ToInt32(index.InnerText)); } results.WhatReverseIndex.Add(entry.SelectSingleNode("text").InnerText, indices); } foreach (XmlNode entry in whyNodes) { List <int> indices = new List <int>(); foreach (XmlNode index in entry.SelectNodes("articleIndex")) { indices.Add(Convert.ToInt32(index.InnerText)); } results.WhyReverseIndex.Add(entry.SelectSingleNode("text").InnerText, indices); } } else { return(null); } return(results); }