コード例 #1
0
ファイル: WikiQueryEngine.cs プロジェクト: srpanwar/graph
        /// <summary>
        ///
        /// </summary>
        /// <param name="action"></param>
        /// <param name="topic"></param>
        /// <returns></returns>
        public SearchSuggestion QueryServerSearch(string action, string topic)
        {
            String           endpoint      = String.Format("http://en.wikipedia.org/w/api.php?action={0}&search={1}&format=xml", action, topic);
            SearchSuggestion searchSuggest = ProcessSearchQuery(endpoint);

            return(searchSuggest);
        }
コード例 #2
0
ファイル: WikiQueryEngine.cs プロジェクト: srpanwar/graph
        /// <summary>
        ///
        /// </summary>
        /// <param name="action"></param>
        /// <param name="topic"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public SearchSuggestion QueryServerSearch(string action, string topic, int count)
        {
            topic = System.Web.HttpUtility.UrlEncode(topic);
            String           endpoint      = String.Format("http://en.wikipedia.org/w/api.php?action={0}&search={1}&format=xml&limit={2}", action, topic, count);
            SearchSuggestion searchSuggest = ProcessSearchQuery(endpoint);

            return(searchSuggest);
        }
コード例 #3
0
ファイル: WikiControl.cs プロジェクト: srpanwar/graph
        public String GetHtmlContent(string searchText, String data,String sense, Object source, Dictionary<String, String> uniqueLinks)
        {
            if (source == null)
                source = this.GetSource(searchText);

            if (source == null)
                throw new ArgumentNullException("Source is NULL");

            this.suggestion = source as SearchSuggestion;
            if (source == null)
                throw new InvalidCastException("Source is not of correct type");

            if (this.suggestion.Section == null)
                throw new ArgumentException("No Data found");

            if (this.suggestion.Section.Length == 0)
                throw new ArgumentException("No Data found");

            bool hasData = false;
            String html = String.Empty;
            html += "<tr>";
            html += "   <td id=\"tdWikipedia\" style=\"width: 100%;vertical-align: top\">";
            html += "       <table style=\"width: 100%\" cellpadding=\"0\" cellspacing=\"0\">";
            html += "           <tr>";
            html += "               <td style=\"border-bottom: solid 1px Silver; width: 100%; color: Black; font-family: Calibri;font-size: 16px;\">";
            html += "                   <b>R</b>elated article(s)&nbsp;";
            html += "                   <a href=\"http://wikipedia.org\" style=\"font-size:small;color:green;text-decoration:none;font-family:Calibri\">";
            html += "                       source: wikipedia.org";
            html += "                   </a>";
            html += "               </td>";
            html += "           </tr>";

            for (int index = 0; index < this.suggestion.Section.Length && index < 5; index++)
            {
                SearchSuggestionItem sugItem = this.suggestion.Section[index];
                if (uniqueLinks.ContainsKey(HttpUtility.UrlDecode(sugItem.Url.ToLower())) || uniqueLinks.ContainsKey(HttpUtility.UrlEncode(sugItem.Url.ToLower())))
                    continue;
                else
                    uniqueLinks.Add(HttpUtility.UrlDecode(sugItem.Url.ToLower()), String.Empty);
                html += "       <tr>";
                html += "           <td style=\"padding-bottom: 3px;\">";
                html += "               <a target=\"_blank\" href=\"" + sugItem.Url + "\" style=\"color:Blue;font-family: Calibri; font-size: medium\">";
                html += sugItem.Text;
                html += "               </a><br />";
                html += "               <span style=\"font-family: Calibri; font-size: small\">";
                html += sugItem.Description;
                html += "               </span>";
                html += "           </td>";
                html += "       </tr>";
                hasData = true;
            }
            html += "       </table>";
            html += "   </td>";
            html += "</tr>";
            html += "<tr><td style=\"height: 5px\">&nbsp;</td></tr>";

            return hasData ? html : String.Empty;
        }
コード例 #4
0
ファイル: WikiQueryEngine.cs プロジェクト: srpanwar/graph
        /// <summary>
        ///
        /// </summary>
        /// <param name="endpoint"></param>
        /// <returns></returns>
        private static SearchSuggestion ProcessSearchQuery(String endpoint)
        {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(endpoint);

            request.UserAgent = "IE";
            HttpWebResponse  response      = (HttpWebResponse)request.GetResponse();
            XmlSerializer    serializer    = new XmlSerializer(typeof(SearchSuggestion));
            SearchSuggestion searchSuggest = (SearchSuggestion)serializer.Deserialize(response.GetResponseStream());

            return(searchSuggest);
        }
コード例 #5
0
ファイル: Wikipedia.cs プロジェクト: srpanwar/graph
        /// <summary>
        ///
        /// </summary>
        /// <param name="topic"></param>
        /// <returns></returns>
        public Boolean IsArticleAvailable(String topic)
        {
            SearchSuggestion searchResult = queryEngine.QueryServerSearch("opensearch", topic, 1);

            if (searchResult != null && searchResult.Section != null && searchResult.Section.Length > 0)
            {
                return(searchResult.Section[0].Text.Equals(topic));
            }

            return(false);
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: srpanwar/graph
        static void Main(string[] args)
        {
            Wikipedia wClass = new Wikipedia(new WikiQueryEngine());

            Console.WriteLine(wClass.IsArticleAvailable("DDLJ"));
            SearchSuggestion searchSuggest = wClass.SearchArticles("DDLJ", 10);

            foreach (SearchSuggestionItem sItem in searchSuggest.Section)
            {
                Console.WriteLine(sItem.Text + "\n\t" + sItem.Description + "\n" + sItem.Url);
            }
            Console.WriteLine(wClass.GetArticle("Seattle", false).Introduction);
            return;
        }
コード例 #7
0
ファイル: Wikipedia.cs プロジェクト: srpanwar/graph
        /// <summary>
        ///
        /// </summary>
        /// <param name="topic"></param>
        /// <returns></returns>
        public SearchSuggestion SearchArticles(String topic, int count)
        {
            SearchSuggestion searchResult = queryEngine.QueryServerSearch("opensearch", topic, count);

            return(searchResult);
        }