示例#1
0
        /// <summary>
        /// query all google custom searches for a document statistic
        /// </summary>
        /// <param name="documentStatistics"></param>
        public void Check(DocumentStatistics documentStatistics)
        {
            foreach (string sentence in documentStatistics.getSentences())
            {
                LinkedList <GoogleSearchResult> googleSearchResults = new LinkedList <GoogleSearchResult>();

                foreach (GoogleCustomSearch customSearch in customSearchs)
                {
                    Uri             apiUri          = new Uri(API + "?key=" + apikey + "&cx=" + customSearch.id + "&q=" + sentence);
                    HTTPRestRequest httpRestRequest = new HTTPRestRequest(apiUri.ToString());
                    dynamic         json            = httpRestRequest.MakeRequest();

                    //no results
                    if (json != null && json.items != null)
                    {
                        int count = 0;
                        foreach (dynamic item in json.items)
                        {
                            //A bit ugly but we need it because its the easiest way too break
                            // out of the loop.
                            if (count >= 3)
                            {
                                break;
                            }

                            googleSearchResults.AddLast(new GoogleSearchResult(customSearch.name, (string)item.title, (string)item.link, (string)item.snippet));
                            count++;
                        }
                    }
                }

                documentStatistics.updateGoogleSearchResults(sentence, googleSearchResults);
            }
        }
示例#2
0
        /// <summary>
        /// query pmc and store results in the document statistic
        /// </summary>
        /// <param name="documentStatistics"></param>
        public void Check(DocumentStatistics documentStatistics)
        {
            foreach (string sentence in documentStatistics.getSentences())
            {
                LinkedList <EuropaPMCSearchResult> europaPMCSearchResult = new LinkedList <EuropaPMCSearchResult>();

                Uri apiUri = new Uri(API + "query=" + sentence + "&resultType=core&synonym=NO&cursorMark=*&pageSize=3&format=json");

                HTTPRestRequest httpRestRequest = new HTTPRestRequest(apiUri.ToString());
                dynamic         json            = httpRestRequest.MakeRequest();

                if (json != null)
                {
                    foreach (dynamic item in json.resultList.result)
                    {
                        if (item.abstractText != null)
                        {
                            europaPMCSearchResult.AddLast(new EuropaPMCSearchResult((string)item.title, (string)item.authorString, (string)item.abstractText, (string)item.pubYear, (string)item.fullTextUrlList.fullTextUrl[0].url));
                        }
                    }
                }

                documentStatistics.updateEuropaPMCSearchResults(sentence, europaPMCSearchResult);
            }
        }