Exemple #1
0
        public Dictionary <String, titleHits> loadResultSet(String DataFile)
        {
            Dictionary <String, titleHits> ResultSet = new Dictionary <String, titleHits>();

            System.IO.StreamReader fr = null;
            try
            {
                fr = new System.IO.StreamReader(DataFile);
                String fileLine;
                while ((fileLine = fr.ReadLine()) != null)
                {
                    String[]  explodedLine = fileLine.Split('+');
                    titleHits temp         = new titleHits();
                    temp.Hits = Convert.ToInt64(explodedLine[0]);
                    temp.Link = explodedLine[2];

                    if (ResultSet.ContainsKey(explodedLine[1]) == false)
                    {
                        ResultSet.Add(explodedLine[1], temp);
                    }
                    else
                    {
                        ResultSet[explodedLine[1]].Hits += Convert.ToInt64(explodedLine[0]);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                if (fr != null)
                {
                    fr.Close();
                }
            }
            return(ResultSet);
        }
Exemple #2
0
        public Dictionary <String, String> findRelatedLinks2(String pageTitle)
        {
            System.IO.StreamReader fr = null;
            String pageSource         = "";
            Dictionary <string, string> relatedLinks = new Dictionary <string, string>();
            String dataSource = "";

            try
            {
                dataSource = AppDomain.CurrentDomain.BaseDirectory + @"\DataStore\" + pageTitle + ".html";

                fr         = new System.IO.StreamReader(dataSource);
                pageSource = fr.ReadToEnd();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                if (fr != null)
                {
                    fr.Close();
                }

                LinkFinder linkfinder = new LinkFinder();
                linkfinder.FindHtmlAgility(dataSource);
                List <LinkItem> linkitems = linkfinder.Find(pageSource);
                Dictionary <String, titleHits> linkCounts = new Dictionary <string, titleHits>();
                foreach (var linkitem in linkitems)
                {
                    if (linkCounts.ContainsKey(linkitem.Text) == false)
                    {
                        titleHits temp = new titleHits();
                        temp.Hits = 1;
                        temp.Link = linkitem.Href;
                        linkCounts.Add(linkitem.Text, temp);
                    }
                    else
                    {
                        linkCounts[linkitem.Text].Hits++;
                    }
                }

                var SortedLinkCounts = from linkcount in linkCounts
                                       orderby linkcount.Value.Hits descending
                                       select linkcount;

                foreach (var link in SortedLinkCounts)
                {
                    try
                    {
                        relatedLinks.Add(link.Key, link.Value.Link);
                    }
                    catch
                    {
                        continue;
                    }
                }
            }
            return(relatedLinks);
        }
Exemple #3
0
 public titleHits(titleHits tH)
 {
     this.Hits = tH.Hits;
     this.Link = tH.Link;
 }