Exemplo n.º 1
0
 private void backgroundWorker_authSearchWork(object sender, DoWorkEventArgs e)
 {
     if (prevSelectedIndex != suggestedIndex)
     {
         if (a[0] == true)
         {
             authStats = CSParser.getAuthStatistics(auth_url[suggestedIndex]);
             authStats.Type = 0;
         }
         else if (a[1] == true)
         {
             authStats = GSScraper.getAuthStatistics(auth_url[suggestedIndex]);
             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 if (a[2] == true)
         {
             authStats = MSParser.getAuthStatistics(auth_url[suggestedIndex]);
             authStats.Type = 2;
         }
         prevSelectedIndex = suggestedIndex;
     }
 }
Exemplo n.º 2
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;
                }
            }
        }
Exemplo n.º 3
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());
     }
 }
Exemplo n.º 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();

            }
        }
Exemplo n.º 5
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();

            }
        }
Exemplo n.º 6
0
 // RESULTS FROM AUTHOR PROFILE PAGE
 public SG.Author getAuthStatistics(string authUrl)
 {
     bool isOK = true;
     if (authUrl == null) return null;
     authUrl += "&pagesize=100";
     GSAuthScraper authScraper = new GSAuthScraper(authUrl, 0,ref isOK);
     if (!isOK) return null;
     authScraper.getCitationStats();
     SG.Author author = new SG.Author(authScraper.getName(), authScraper.getAffiliation(), authScraper.getHomePage(), authScraper.getHIndex(), authScraper.getIIndex());
     //Console.WriteLine(author.Name + "," + author.getHIndex() + "," + author.getI10Index());
     List<SG.Paper> papers = authScraper.getPapersOfCurrentPage();
     if (papers == null) return null;
     if (papers.Count == 0) return author;
     foreach (SG.Paper paper in papers) author.addPaper(paper);
     return author;
 }
Exemplo n.º 7
0
        // SEARCH PAGE RESULTS
        public SG.Author getAuthors(string authName, string affiliation, string keywords, ref string next_url)
        {
            // CONNECTIONS

            SG.Author result = new SG.Author(authName);
            if (authName == null) authName = "";
            else
            {
                authName.Trim();
                authName = Regex.Replace(authName, @"\s+", "+");
                //authName = authName.Insert(0, "author:");
                //Console.WriteLine(authName);
            }
            if (affiliation == null) affiliation = "";
            else
            {
                affiliation = affiliation.Trim();
                affiliation = Regex.Replace(affiliation, @"\s+", "+");
            }
            if (keywords == null) keywords = "";
            else
            {
                keywords = keywords.Trim();
                keywords = Regex.Replace(keywords, @"\s+", "+");
            }

            //string url = "http://scholar.google.com/scholar?q=" + authName + "&btnG=&hl=en&as_sdt=1.";//keywords + "&as_epq=&as_oq=" //affiliation + "&as_eq=&as_occt=any&as_sauthors=" + authName;// + "&as_publication=&as_ylo=&as_yhi=&btnG=&hl=en&as_sdt=0%2C5";
            string url = "http://scholar.google.com/scholar?as_q=&as_epq=&as_oq=&as_eq=&as_occt=any&as_sauthors="  + authName + "&as_publication=&as_ylo=&as_yhi=&btnG=&hl=en&as_sdt=0,5&num=20";

            Console.WriteLine(url);
            HtmlWeb web = new HtmlWeb();

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

            //Console.WriteLine(doc.DocumentNode.InnerHtml);

            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
            {
                Console.WriteLine(url);
                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 = 1970;
                    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;", "");
                        }

                    }

                    publisher.Trim();
                    publication.Trim();
                    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;
        }