Example #1
0
        private void backgroundWorker_genSearchWork(object sender, DoWorkEventArgs e)
        {
            Console.WriteLine("Background worker...");
            if (authorCheckBox.Checked == true)
            {
                prevSelectedIndex = -1;
                // get suggestions
                if (a[0])
                    authSug = CSParser.getAuthSuggestions(searchField.Text);
                else if (a[1])
                {
                    authSug = GSScraper.getAuthSuggestions(searchField.Text);
                }
                else
                    authSug = MSParser.getAuthSuggestions(searchField.Text);

                if (authSug == null || !authSug.isSet())
                {
                    /* Case : No suggestions */
                    if (a[0] == true)
                    {
                        authStats = CSParser.getAuthors(searchField.Text, "", "");
                        authStats.Type = 0;
                    }
                    else if (a[1] == true)
                    {
                        authStats = GSScraper.getAuthors(searchField.Text, "", "", ref gs_nextUrl);
                        if (authStats == null)
                            MessageBox.Show("Oops! You have reached administrative limit for Google Scholar." +
                                "\nIf you are behind a proxy server, please try changing your settings.");
                        else
                            authStats.Type = 1;
                    }
                    else
                    {
                        authStats = MSParser.getAuthors(searchField.Text, "", "");
                        authStats.Type = 2;
                    }
                    suggestions = false;
                }
                else
                {
                    authors = authSug.getSuggestions();
                    auth_url = authSug.getSuggestionsURL();

                    suggestions = true;
                }
            }
            else // journal
            {
                if (a[0])
                {
                    journalStats = CSParser.getJournals(searchField.Text, "", "");
                    journalStats.Type = 0;
                }
                else if (a[1])
                {
                    journalStats = GSScraper.getJournals(searchField.Text, "", "", ref gs_nextUrl);
                    if(journalStats == null)
                       MessageBox.Show("Oops! You have reached administrative limit for Google Scholar." +
                                "\nIf you are behind a proxy server, please try changing your settings.");
                    else
                        journalStats.Type = 1;
                }
                else
                {
                    journalStats = MSParser.getJournals(searchField.Text, "", "");
                    journalStats.Type = 2;
                }
            }
        }
Example #2
0
 private void viewStatisticsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         if (favouritesTreeView.SelectedNode != null)
         {
             if (favouritesTreeView.SelectedNode.Level == 2)
             {
                 if (favouritesTreeView.SelectedNode.Parent.Index == 0)
                 {
                     authStats = FavAuthorList[favouritesTreeView.SelectedNode.Index];
                     populateAuthor();
                 }
                 else if (favouritesTreeView.SelectedNode.Parent.Index == 1)
                 {// Journal selected
                     journalStats = FavJournalList[favouritesTreeView.SelectedNode.Index];
                     populateJournal();
                 }
             }
         }
     }
     catch (Exception exception)
     {
         Console.WriteLine(exception.GetBaseException());
     }
 }
Example #3
0
        private void recentListView_MouseDoubleClick(object sender, EventArgs e)
        {
            if (recentListView.FocusedItem.SubItems[1].Text.Equals("Author")) {

                authStats = (SG.Author)cacheObject.Get(recentListView.FocusedItem.SubItems[0].Text, true);
                populateAuthor();

            }
            else if (recentListView.FocusedItem.SubItems[1].Text.Equals("Journal")) {

                journalStats = (SG.Journal)cacheObject.Get(recentListView.FocusedItem.SubItems[0].Text, false);
                populateJournal();

            }
        }
Example #4
0
        public void cachedListView_Click(object sender, EventArgs e)
        {
            Console.WriteLine(cachedListView.FocusedItem.Text);
            searchField.Text = cachedListView.FocusedItem.Text;
            cachedListView.Visible = false;
            /* Display cached object */
            if (authorCheckBox.Checked)
            {
                authStats = (SG.Author)cacheObject.Get(searchField.Text, authorCheckBox.Checked);
                populateAuthor();
            }
            else
            {
                journalStats = (SG.Journal)cacheObject.Get(searchField.Text, authorCheckBox.Checked);
                populateJournal();

            }
        }
Example #5
0
        //  JOURNAL SEARCH RESULTS
        public SG.Journal getJournals(string journalName, string ISSN, string keywords, ref string next_url)
        {
            // CONNECTIONS

            if (journalName == null) journalName = null;
            else journalName.Trim();
            SG.Journal result = new SG.Journal(journalName);

            // FORMATTIONG STRINGS
            if (ISSN == null) ISSN = "";
            else
            {
                ISSN = ISSN.Trim();
                ISSN = Regex.Replace(ISSN, @"\s+", "+");
            }
            if (keywords == null) keywords = "";
            else
            {
                keywords = keywords.Trim();
                keywords = Regex.Replace(keywords, @"\s+", "+");
            }
            string temp = (ISSN.Equals("") || keywords.Equals("")) ? keywords + ISSN : keywords + "+" + ISSN;

            string name = Regex.Replace(journalName, @"\s+", "+");
            string url = "http://scholar.google.com/scholar?as_q=&as_epq=&as_oq=&as_eq=&as_occt=any&as_sauthors=&as_publication=" + journalName + "&as_ylo=&as_yhi=&btnG=&hl=en&as_sdt=0,5&num=20";
            //string url = "http://scholar.google.co.in/scholar?hl=en&q=anil+kumar&btnG=&as_sdt=1,5&as_sdtp=";
            Console.WriteLine(url);

            //Console.WriteLine("loaded !!!");

            HtmlWeb web = new HtmlWeb();

            try
            {
                doc = web.Load(url);
            }
            catch (Exception e)
            {
                return null;
            }

            //Console.WriteLine(doc.DocumentNode.InnerHtml);
            //string html = client.DownloadString(url);
            //doc.LoadHtml(html);

            string xpath = "//div[@class=\"gs_ri\"]";
            string title, titleLink, authors, publication, publisher, cited_by_url, summary;
            int year, rank = 1, no_of_citations;
            HtmlNodeCollection searchResults = doc.DocumentNode.SelectNodes(xpath);
            if (searchResults == null)
            {
                if (checkForCaptcha())
                {
                    Console.WriteLine("Captcha problem ...");
                    return null;
                }
                Console.WriteLine("No results ...");
                return result;
            }
            else
            {
                foreach (HtmlNode n in searchResults)
                {

                    // TITLE AND TITLE LINK
                    HtmlNode child = n.SelectSingleNode(".//*[@class=\"gs_rt\"]");
                    title = child.InnerText;
                    titleLink = "";
                    HtmlNode url_node = child.SelectSingleNode(".//a");
                    if (url_node != null)
                    {
                        titleLink = url_node.GetAttributeValue("href", "");
                        if (!titleLink.Equals(""))
                        {
                            //titleLink = "http://scholar.google.com" + titleLink;
                            titleLink = titleLink.Replace("amp;", "");
                        }
                    }

                    // AUTHORS AND PUBLICATION
                    child = n.SelectSingleNode(".//*[@class=\"gs_a\"]");
                    authors = "";
                    publication = "";
                    publisher = "";
                    year = -1;
                    if (child != null)
                    {
                        string[] names = child.InnerText.Split('-');
                        if (names.Length == 1) authors = names[0];
                        else if (names.Length == 2)
                        {
                            authors = names[0];
                            bool flag = false;
                            names[1].Trim();
                            try { year = Convert.ToInt32(names[1]); }
                            catch (FormatException fe) { flag = true; }
                            if (flag)
                            {
                                string[] p = names[1].Split(',');
                                try { year = Convert.ToInt32(p[1]); }
                                catch (Exception e) { }
                                publication = p[0];
                            }
                        }
                        else
                        {
                            authors = names[0];
                            publisher = names[2];
                            bool flag = false;
                            names[1].Trim();
                            try { year = Convert.ToInt32(names[1]); }
                            catch (FormatException fe) { flag = true; }
                            if (flag)
                            {
                                string[] p = names[1].Split(',');
                                try { year = Convert.ToInt32(p[1]); }
                                catch (Exception e) { }
                                publication = p[0];
                            }
                        }
                    }

                    // SUMMARY
                    child = n.SelectSingleNode(".//*[@class=\"gs_rs\"]");
                    summary = "";
                    if (child != null)
                    {
                        summary = child.InnerText;
                    }

                    // CITATION STUFF
                    no_of_citations = 0;
                    cited_by_url = "";
                    child = n.SelectSingleNode(".//*[@class=\"gs_fl\"]");
                    if (child != null) child = child.FirstChild;
                    if (child != null)
                    {

                        string text = child.InnerText;

                        try
                        {
                            text = text.Replace("Cited by", "");
                            text = text.Trim();
                            no_of_citations = Convert.ToInt32(text);
                        }
                        catch (Exception e) { }

                        cited_by_url = no_of_citations != 0 ? child.GetAttributeValue("href", "") : "";
                        if (!cited_by_url.Equals(""))
                        {
                            cited_by_url = "http://scholar.google.com" + cited_by_url;
                            cited_by_url = cited_by_url.Replace("amp;", "");
                        }

                    }

                    SG.Paper paper = new SG.Paper(title, titleLink, authors, summary, year, publication, publisher, no_of_citations, cited_by_url, rank);
                    result.addPaper(paper);
                    rank++;
                }

                //NEXT PAGE URL
                HtmlNode bottom = doc.DocumentNode.SelectSingleNode(".//*[@id=\"gs_n\"]//table//td[@align=\"left\"]//a");
                if (bottom != null)
                {
                    url = bottom.GetAttributeValue("href", "");
                    if (!url.Equals(""))
                    {
                        url = "http://scholar.google.com" + url;
                        url = url.Replace("amp;", "");
                        next_url = url;
                    }
                    else next_url = null;
                }
                else next_url = null;
            }
            return result;
        }